diff --git a/lib/gollum/committer.rb b/lib/gollum/committer.rb index 9038f2ff..a8b73673 100644 --- a/lib/gollum/committer.rb +++ b/lib/gollum/committer.rb @@ -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) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 211bbe66..dd362572 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -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 = [] diff --git a/test/test_committer.rb b/test/test_committer.rb index f87a05a4..68157844 100644 --- a/test/test_committer.rb +++ b/test/test_committer.rb @@ -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 \ No newline at end of file