Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add `force` option to obj.create_note

  • Loading branch information...
commit 35a26de7e562342e56d3eb6e9f63cfef48dc28b9 1 parent 2f6b301
@nvloff nvloff authored
Showing with 54 additions and 2 deletions.
  1. +8 −2 ext/rugged/rugged_note.c
  2. +46 −0 test/note_test.rb
View
10 ext/rugged/rugged_note.c
@@ -119,6 +119,7 @@ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
* - +:committer+: a hash with the signature for the committer
* - +:author+: a hash with the signature for the author
* - +:ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
+ * - +:force+: (optional): overwrite existing note (disabled by default)
*
* When the note is successfully written to disk, its +oid+ will be
* returned as a hex +String+.
@@ -134,7 +135,7 @@ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
*/
static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
{
- VALUE rb_ref, rb_message;
+ VALUE rb_ref, rb_message, rb_force;
git_repository *repo = NULL;
const char *notes_ref = NULL;
@@ -145,6 +146,7 @@ static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
git_object *target = NULL;
int error = 0;
+ int force = 0;
Check_Type(rb_data, T_HASH);
@@ -155,6 +157,10 @@ static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref"));
+ rb_force = rb_hash_aref(rb_data, CSTR2SYM("force"));
+ if (!NIL_P(rb_force))
+ force = rugged_parse_bool(rb_force);
+
if (!NIL_P(rb_ref)) {
Check_Type(rb_ref, T_STRING);
notes_ref = StringValueCStr(rb_ref);
@@ -179,7 +185,7 @@ static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
notes_ref,
git_object_id(target),
StringValueCStr(rb_message),
- 0);
+ force);
git_signature_free(author);
View
46 test/note_test.rb
@@ -77,6 +77,52 @@ def test_create_note
assert_equal note[:message], message
end
+ def test_create_note_on_object_with_notes_raises
+ person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
+ oid = "8496071c1b46c854b31185ea97743be6a8774479"
+ message ="This is the note message\n\nThis note is created from Rugged"
+ obj = @repo.lookup(oid)
+ obj.create_note(
+ :message => message,
+ :committer => person,
+ :author => person,
+ :ref => 'refs/notes/test'
+ )
+
+ assert_raises Rugged::RepositoryError do
+ obj.create_note(
+ :message => message,
+ :committer => person,
+ :author => person,
+ :ref => 'refs/notes/test'
+ )
+ end
+ end
+
+ def test_overwrite_object_note
+ person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
+ oid = "8496071c1b46c854b31185ea97743be6a8774479"
+ message ="This is the note message\n\nThis note is created from Rugged"
+ obj = @repo.lookup(oid)
+ obj.create_note(
+ :message => message,
+ :committer => person,
+ :author => person,
+ :ref => 'refs/notes/test'
+ )
+
+ obj.create_note(
+ :message => 'new message',
+ :committer => person,
+ :author => person,
+ :ref => 'refs/notes/test',
+ :force => true
+ )
+
+ note = obj.notes('refs/notes/test')
+ assert_equal note[:message], 'new message'
+ end
+
def test_remove_note
oid = "36060c58702ed4c2a40832c51758d5344201d89a"
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
Please sign in to comment.
Something went wrong with that request. Please try again.