yield the created SHA1 in the after_commit callback
This commit is contained in:
@@ -144,14 +144,15 @@ module Gollum
|
|||||||
def commit
|
def commit
|
||||||
sha1 = index.commit(@options[:message], parents, actor)
|
sha1 = index.commit(@options[:message], parents, actor)
|
||||||
@callbacks.each do |cb|
|
@callbacks.each do |cb|
|
||||||
cb.call(self)
|
cb.call(self, sha1)
|
||||||
end
|
end
|
||||||
sha1
|
sha1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds a callback to be fired after a commit.
|
# Adds a callback to be fired after a commit.
|
||||||
#
|
#
|
||||||
# block - A block that expects this Committer instance as the argument.
|
# block - A block that expects this Committer instance and the created
|
||||||
|
# commit's SHA1 as the arguments.
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def after_commit(&block)
|
def after_commit(&block)
|
||||||
|
|||||||
+4
-4
@@ -205,7 +205,7 @@ module Gollum
|
|||||||
|
|
||||||
committer.add_to_index('', name, format, data)
|
committer.add_to_index('', name, format, data)
|
||||||
|
|
||||||
committer.after_commit do |index|
|
committer.after_commit do |index, sha|
|
||||||
@access.refresh
|
@access.refresh
|
||||||
index.update_working_dir('', name, format)
|
index.update_working_dir('', name, format)
|
||||||
end
|
end
|
||||||
@@ -256,7 +256,7 @@ module Gollum
|
|||||||
committer.add_to_index(dir, name, format, data, :allow_same_ext)
|
committer.add_to_index(dir, name, format, data, :allow_same_ext)
|
||||||
end
|
end
|
||||||
|
|
||||||
committer.after_commit do |index|
|
committer.after_commit do |index, sha|
|
||||||
@access.refresh
|
@access.refresh
|
||||||
index.update_working_dir(dir, page.name, page.format)
|
index.update_working_dir(dir, page.name, page.format)
|
||||||
index.update_working_dir(dir, name, format)
|
index.update_working_dir(dir, name, format)
|
||||||
@@ -293,7 +293,7 @@ module Gollum
|
|||||||
|
|
||||||
committer.delete(page.path)
|
committer.delete(page.path)
|
||||||
|
|
||||||
committer.after_commit do |index|
|
committer.after_commit do |index, sha|
|
||||||
dir = ::File.dirname(page.path)
|
dir = ::File.dirname(page.path)
|
||||||
dir = '' if dir == '.'
|
dir = '' if dir == '.'
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ module Gollum
|
|||||||
parent = committer.parents[0]
|
parent = committer.parents[0]
|
||||||
committer.options[:tree] = @repo.git.apply_patch(parent.sha, patch)
|
committer.options[:tree] = @repo.git.apply_patch(parent.sha, patch)
|
||||||
return false unless committer.options[:tree]
|
return false unless committer.options[:tree]
|
||||||
committer.after_commit do |index|
|
committer.after_commit do |index, sha|
|
||||||
@access.refresh
|
@access.refresh
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
|
|||||||
@@ -24,4 +24,27 @@ context "Wiki" do
|
|||||||
assert_equal 'bob', committer.actor.name
|
assert_equal 'bob', committer.actor.name
|
||||||
assert_equal 'foo@bar.com', committer.actor.email
|
assert_equal 'foo@bar.com', committer.actor.email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "yield after_commit callback" do
|
||||||
|
@path = cloned_testpath('examples/lotr.git')
|
||||||
|
yielded = nil
|
||||||
|
begin
|
||||||
|
wiki = Gollum::Wiki.new(@path)
|
||||||
|
committer = Gollum::Committer.new(wiki)
|
||||||
|
committer.after_commit do |index, sha1|
|
||||||
|
yielded = sha1
|
||||||
|
assert_equal committer, index
|
||||||
|
end
|
||||||
|
|
||||||
|
res = wiki.write_page("Gollum", :markdown, "# Gollum",
|
||||||
|
:committer => committer)
|
||||||
|
|
||||||
|
assert_equal committer, res
|
||||||
|
|
||||||
|
sha1 = committer.commit
|
||||||
|
assert_equal sha1, yielded
|
||||||
|
ensure
|
||||||
|
FileUtils.rm_rf(@path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user