Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'patch-id' into github

  • Loading branch information...
commit 087676cd79e4fca4fb14c7baa8e072dabc6da383 2 parents f6dd621 + bc628b0
@mojombo authored
Showing with 22 additions and 0 deletions.
  1. +15 −0 lib/grit/commit.rb
  2. +7 −0 test/test_commit.rb
View
15 lib/grit/commit.rb
@@ -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
7 test/test_commit.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.