Skip to content

Commit 70bca72

Browse files
committed
commit: raise when given bad data to extract the signature
This lets the caller distinguish between a missing object, the wrong kind of object and unsigned commits.
1 parent 059bff4 commit 70bca72

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

ext/rugged/rugged_commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static VALUE rb_git_commit_extract_signature(int argc, VALUE *argv, VALUE self)
647647
git_buf_free(&signed_data);
648648
}
649649

650-
if (error == GIT_ENOTFOUND) {
650+
if (error == GIT_ENOTFOUND && giterr_last()->klass == GITERR_OBJECT ) {
651651
ret_arr = rb_ary_new3(2, Qnil, Qnil);
652652
} else {
653653
rugged_exception_check(error);

test/commit_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ def test_extract_signature
273273
assert_equal exp_signed_data, signed_data
274274

275275
assert_equal [nil, nil], Rugged::Commit.extract_signature(@repo, "8496071c1b46c854b31185ea97743be6a8774479")
276+
277+
# Ask for a tree
278+
assert_raises(Rugged::InvalidError) { Rugged::Commit.extract_signature(@repo, "181037049a54a1eb5fab404658a3a250b44335d7") }
279+
280+
# Ask for a non-existent object
281+
assert_raises(Rugged::OdbError) { Rugged::Commit.extract_signature(@repo, "181037049a54a1eb5fab404658a3a250b44335d8") }
276282
end
277283
end
278284

0 commit comments

Comments
 (0)