Skip to content

Commit 4d8ae7f

Browse files
author
Vicent Martí
authored
Merge pull request #697 from alyssais/commit_sig_key_error
Use Hash#fetch instead of Hash#[] for more understandable error messages
2 parents 57b46eb + bf087b0 commit 4d8ae7f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ext/rugged/rugged_signature.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ git_signature *rugged_signature_get(VALUE rb_sig, git_repository *repo)
5050

5151
Check_Type(rb_sig, T_HASH);
5252

53-
rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name"));
54-
rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email"));
53+
rb_name = rb_hash_fetch(rb_sig, CSTR2SYM("name"));
54+
rb_email = rb_hash_fetch(rb_sig, CSTR2SYM("email"));
5555
rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time"));
5656
rb_time_offset = rb_hash_aref(rb_sig, CSTR2SYM("time_offset"));
5757

test/commit_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ def test_write_empty_email_fails
452452
end
453453
end
454454

455+
def test_write_signature_raises_key_error_for_missing_keys
456+
person = {:name => 'Jake', :time => Time.now} # no :email
457+
assert_raises KeyError do
458+
Rugged::Commit.create(@repo,
459+
:message => "This is the commit message\n\nThis commit is created from Rugged",
460+
:committer => person,
461+
:author => person,
462+
:parents => [@repo.head.target],
463+
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
464+
end
465+
end
466+
455467
def test_create_commit_to_s
456468
person = {:name => 'Scott', :email => '[email protected]', :time => Time.now }
457469

0 commit comments

Comments
 (0)