Skip to content

Commit 6985f78

Browse files
committed
commit: return nils if the commit isn't signed
Unsigned commits aren't exceptional, so just return normally and indicate there's nothing there.
1 parent 8244ab5 commit 6985f78

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ext/rugged/rugged_commit.c

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

650-
rugged_exception_check(error);
650+
if (error == GIT_ENOTFOUND) {
651+
ret_arr = rb_ary_new3(2, Qnil, Qnil);
652+
} else {
653+
rugged_exception_check(error);
651654

652-
ret_arr = rb_ary_new3(2, rb_str_new(signature.ptr, signature.size),
653-
rb_str_new(signed_data.ptr, signed_data.size));
655+
ret_arr = rb_ary_new3(2, rb_str_new(signature.ptr, signature.size),
656+
rb_str_new(signed_data.ptr, signed_data.size));
657+
}
654658

655659
git_buf_free(&signature);
656660
git_buf_free(&signed_data);

test/commit_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ def test_extract_signature
271271
signature, signed_data = Rugged::Commit.extract_signature(@repo, commit_sha)
272272
assert_equal exp_signature, signature
273273
assert_equal exp_signed_data, signed_data
274+
275+
assert_equal [nil, nil], Rugged::Commit.extract_signature(@repo, "8496071c1b46c854b31185ea97743be6a8774479")
274276
end
275277
end
276278

0 commit comments

Comments
 (0)