yield the created SHA1 in the after_commit callback

This commit is contained in:
rick
2011-01-19 05:51:16 -08:00
parent 2b1510af11
commit 8ddb781588
3 changed files with 30 additions and 6 deletions
+3 -2
View File
@@ -144,14 +144,15 @@ module Gollum
def commit
sha1 = index.commit(@options[:message], parents, actor)
@callbacks.each do |cb|
cb.call(self)
cb.call(self, sha1)
end
sha1
end
# 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.
def after_commit(&block)
+4 -4
View File
@@ -205,7 +205,7 @@ module Gollum
committer.add_to_index('', name, format, data)
committer.after_commit do |index|
committer.after_commit do |index, sha|
@access.refresh
index.update_working_dir('', name, format)
end
@@ -256,7 +256,7 @@ module Gollum
committer.add_to_index(dir, name, format, data, :allow_same_ext)
end
committer.after_commit do |index|
committer.after_commit do |index, sha|
@access.refresh
index.update_working_dir(dir, page.name, page.format)
index.update_working_dir(dir, name, format)
@@ -293,7 +293,7 @@ module Gollum
committer.delete(page.path)
committer.after_commit do |index|
committer.after_commit do |index, sha|
dir = ::File.dirname(page.path)
dir = '' if dir == '.'
@@ -331,7 +331,7 @@ module Gollum
parent = committer.parents[0]
committer.options[:tree] = @repo.git.apply_patch(parent.sha, patch)
return false unless committer.options[:tree]
committer.after_commit do |index|
committer.after_commit do |index, sha|
@access.refresh
files = []
+23
View File
@@ -24,4 +24,27 @@ context "Wiki" do
assert_equal 'bob', committer.actor.name
assert_equal 'foo@bar.com', committer.actor.email
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