Skip to content

Commit 79da1aa

Browse files
committed
Merge pull request #577 from libgit2/cmn/extract-sig-errors
commit: raise when given bad data to extract the signature
2 parents 059bff4 + 8b6a364 commit 79da1aa

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

ext/rugged/rugged_commit.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ static VALUE rb_git_commit_header(VALUE self)
625625
static VALUE rb_git_commit_extract_signature(int argc, VALUE *argv, VALUE self)
626626
{
627627
int error;
628-
VALUE ret_arr;
628+
VALUE ret;
629629
git_oid commit_id;
630630
const char *field;
631631
git_repository *repo;
@@ -647,19 +647,19 @@ 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) {
651-
ret_arr = rb_ary_new3(2, Qnil, Qnil);
650+
if (error == GIT_ENOTFOUND && giterr_last()->klass == GITERR_OBJECT ) {
651+
ret = Qnil;
652652
} else {
653653
rugged_exception_check(error);
654654

655-
ret_arr = rb_ary_new3(2, rb_str_new(signature.ptr, signature.size),
656-
rb_str_new(signed_data.ptr, signed_data.size));
655+
ret = rb_ary_new3(2, rb_str_new(signature.ptr, signature.size),
656+
rb_str_new(signed_data.ptr, signed_data.size));
657657
}
658658

659659
git_buf_free(&signature);
660660
git_buf_free(&signed_data);
661661

662-
return ret_arr;
662+
return ret;
663663
}
664664

665665
void Init_rugged_commit(void)

lib/rugged/tag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def self.extract_signature(repo, oid, prefix=GPG_SIGNATURE_PREFIX)
1515
object.data.byteslice(0...index)
1616
]
1717
else
18-
[nil, object.data]
18+
nil
1919
end
2020
end
2121

test/commit_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,13 @@ def test_extract_signature
272272
assert_equal exp_signature, signature
273273
assert_equal exp_signed_data, signed_data
274274

275-
assert_equal [nil, nil], Rugged::Commit.extract_signature(@repo, "8496071c1b46c854b31185ea97743be6a8774479")
275+
assert_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)