Permalink
Browse files

Merge branch 'patch-id' into github

  • Loading branch information...
2 parents f6dd621 + bc628b0 commit 087676cd79e4fca4fb14c7baa8e072dabc6da383 @mojombo committed Jun 8, 2011
Showing with 22 additions and 0 deletions.
  1. +15 −0 lib/grit/commit.rb
  2. +7 −0 test/test_commit.rb
View
@@ -252,6 +252,21 @@ def notes
ret
end
+ # Calculates the commit's Patch ID. The Patch ID is essentially the SHA1
+ # of the diff that the commit is introducing.
+ #
+ # Returns the 40 character hex String if a patch-id could be calculated
+ # or nil otherwise.
+ def patch_id
+ show = @repo.git.show({}, @id)
+ patch_line = @repo.git.native(:patch_id, :input => show)
+ if patch_line =~ /^([0-9a-f]{40}) [0-9a-f]{40}\n$/
+ $1
+ else
+ nil
+ end
+ end
+
# Pretty object inspection
def inspect
%Q{#<Grit::Commit "#{@id}">}
View
@@ -193,6 +193,13 @@ def test_to_patch
assert patch.include?("1.7.")
end
+ # patch_id
+
+ def test_patch_id
+ @c = Commit.create(@r, :id => '80f136f500dfdb8c3e8abf4ae716f875f0a1b57f')
+ assert_equal '9450b04e4f83ad0067199c9e9e338197d1835cbb', @c.patch_id
+ end
+
# inspect
def test_inspect

0 comments on commit 087676c

Please sign in to comment.