/* Can remove a note from a commit */ void test_notes_notes__can_remove_a_note_from_commit(void) { git_oid oid, notes_commit_oid; git_note *note = NULL; git_commit *existing_notes_commit; git_reference *ref; cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0)); git_commit_lookup(&existing_notes_commit, _repo, ¬es_commit_oid); cl_assert(existing_notes_commit); cl_git_pass(git_note_commit_remove(¬es_commit_oid, _repo, existing_notes_commit, _sig, _sig, &oid)); /* remove_from_commit will not update any ref, * so we must manually create the ref, that points to the commit */ cl_git_pass(git_reference_create(&ref, _repo, "refs/notes/i-can-see-dead-notes", ¬es_commit_oid, 0, NULL)); cl_git_fail(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &oid)); git_commit_free(existing_notes_commit); git_reference_free(ref); git_note_free(note); }
void test_notes_notes__1(void) { git_oid oid, note_oid; static git_note *note; static git_blob *blob; cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n")); cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n")); cl_git_pass(git_note_read(¬e, _repo, NULL, &oid)); cl_assert_equal_s(git_note_message(note), "hello world\n"); cl_assert(!git_oid_cmp(git_note_oid(note), ¬e_oid)); cl_git_pass(git_blob_lookup(&blob, _repo, ¬e_oid)); cl_assert_equal_s(git_note_message(note), git_blob_rawcontent(blob)); cl_git_fail(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n")); cl_git_fail(git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n")); cl_git_pass(git_note_remove(_repo, NULL, _sig, _sig, &oid)); cl_git_pass(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid)); cl_git_fail(git_note_remove(_repo, NULL, _sig, _sig, ¬e_oid)); cl_git_fail(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid)); git_note_free(note); git_blob_free(blob); }
void test_notes_notes__can_iterate_custom_namespace(void) { git_note_iterator *iter; git_note *note; git_oid note_id, annotated_id; git_oid note_created[2]; const char* note_message[] = { "I decorate a65f\n", "I decorate c478\n" }; int i, err; create_note(¬e_created[0], "refs/notes/beer", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", note_message[0]); create_note(¬e_created[1], "refs/notes/beer", "c47800c7266a2be04c571c04d5a6614691ea99bd", note_message[1]); cl_git_pass(git_note_iterator_new(&iter, _repo, "refs/notes/beer")); for (i = 0; (err = git_note_next(¬e_id, &annotated_id, iter)) >= 0; ++i) { cl_git_pass(git_note_read(¬e, _repo, "refs/notes/beer", &annotated_id)); cl_assert_equal_s(git_note_message(note), note_message[i]); git_note_free(note); } cl_assert_equal_i(GIT_ITEROVER, err); cl_assert_equal_i(2, i); git_note_iterator_free(iter); }
void test_notes_notesref__config_corenotesref(void) { git_oid oid, note_oid; const char *default_ref; cl_git_pass(git_signature_now(&_sig, "alice", "*****@*****.**")); cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_pass(git_repository_config(&_cfg, _repo)); cl_git_pass(git_config_set_string(_cfg, "core.notesRef", "refs/notes/mydefaultnotesref")); cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "test123test\n")); cl_git_pass(git_note_read(&_note, _repo, NULL, &oid)); cl_assert(!strcmp(git_note_message(_note), "test123test\n")); cl_assert(!git_oid_cmp(git_note_oid(_note), ¬e_oid)); git_note_free(_note); cl_git_pass(git_note_read(&_note, _repo, "refs/notes/mydefaultnotesref", &oid)); cl_assert(!strcmp(git_note_message(_note), "test123test\n")); cl_assert(!git_oid_cmp(git_note_oid(_note), ¬e_oid)); cl_git_pass(git_note_default_ref(&default_ref, _repo)); cl_assert(!strcmp(default_ref, "refs/notes/mydefaultnotesref")); cl_git_pass(git_config_delete(_cfg, "core.notesRef")); cl_git_pass(git_note_default_ref(&default_ref, _repo)); cl_assert(!strcmp(default_ref, GIT_NOTES_DEFAULT_REF)); }
/** * Init slots in S4 class git_note * * @param blob_id Oid of the blob containing the message * @param annotated_object_id Oid of the git object being annotated * @param repository * @param repo S4 class git_repository that contains the stash * @param dest S4 class git_note to initialize * @return int 0 on success, or an error code. */ static int git2r_note_init( const git_oid *blob_id, const git_oid *annotated_object_id, git_repository *repository, const char *notes_ref, SEXP repo, SEXP dest) { int err; git_note *note = NULL; char sha[GIT_OID_HEXSZ + 1]; err = git_note_read(¬e, repository, notes_ref, annotated_object_id); if (GIT_OK != err) return err; git_oid_fmt(sha, blob_id); sha[GIT_OID_HEXSZ] = '\0'; SET_SLOT(dest, Rf_install("sha"), mkString(sha)); git_oid_fmt(sha, annotated_object_id); sha[GIT_OID_HEXSZ] = '\0'; SET_SLOT(dest, Rf_install("annotated"), mkString(sha)); SET_SLOT(dest, Rf_install("message"), mkString(git_note_message(note))); SET_SLOT(dest, Rf_install("refname"), mkString(notes_ref)); SET_SLOT(dest, Rf_install("repo"), repo); if (note) git_note_free(note); return 0; }
static void Note_dealloc(Note *self) { Py_CLEAR(self->repo); free(self->annotated_id); git_note_free(self->note); PyObject_Del(self); }
static void test_copy_note( const git_rebase_options *opts, bool should_exist) { git_rebase *rebase; git_reference *branch_ref, *upstream_ref; git_annotated_commit *branch_head, *upstream_head; git_commit *branch_commit; git_rebase_operation *rebase_operation; git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid note_id, commit_id; git_note *note = NULL; int error; checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal")); cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); cl_git_pass(git_reference_peel((git_object **)&branch_commit, branch_ref, GIT_OBJ_COMMIT)); /* Add a note to a commit */ cl_git_pass(git_note_create(¬e_id, repo, "refs/notes/test", git_commit_author(branch_commit), git_commit_committer(branch_commit), git_commit_id(branch_commit), "This is a commit note.", 0)); cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, opts)); cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); cl_git_pass(git_rebase_finish(rebase, signature, opts)); cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo)); if (should_exist) { cl_git_pass(git_note_read(¬e, repo, "refs/notes/test", &commit_id)); cl_assert_equal_s("This is a commit note.", git_note_message(note)); } else { cl_git_fail(error = git_note_read(¬e, repo, "refs/notes/test", &commit_id)); cl_assert_equal_i(GIT_ENOTFOUND, error); } git_note_free(note); git_commit_free(branch_commit); git_annotated_commit_free(branch_head); git_annotated_commit_free(upstream_head); git_reference_free(branch_ref); git_reference_free(upstream_ref); git_rebase_free(rebase); }
void test_notes_notesref__cleanup(void) { git_note_free(_note); git_signature_free(_sig); git_config_free(_cfg); git_repository_free(_repo); cl_fixture_cleanup("testrepo.git"); }
void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_default_namespace(void) { git_oid note_oid, target_oid; git_note *note, *default_namespace_note; const char *default_ref; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); cl_git_pass(git_note_default_ref(&default_ref, _repo)); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid)); cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref, &target_oid)); assert_note_equal(note, "hello world\n", ¬e_oid); assert_note_equal(default_namespace_note, "hello world\n", ¬e_oid); git_note_free(note); git_note_free(default_namespace_note); }
/* * $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479 * 08b041783f40edfe12bb406c9c9a8a040177c125 */ void test_notes_notes__can_read_a_note_in_an_existing_fanout(void) { git_oid note_oid, target_oid; git_note *note; cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_pass(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid)); cl_git_pass(git_oid_fromstr(¬e_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); cl_assert_equal_oid(git_note_id(note), ¬e_oid); git_note_free(note); }
void test_notes_notes__creating_a_note_on_a_target_can_overwrite_existing_note(void) { git_oid note_oid, target_oid; git_note *note, *namespace_note; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n"); cl_git_pass(git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &target_oid, "hello new world\n", 1)); cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid)); assert_note_equal(note, "hello new world\n", ¬e_oid); create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n"); cl_git_pass(git_note_create(¬e_oid, _repo, "refs/notes/some/namespace", _sig, _sig, &target_oid, "hello new ref world\n", 1)); cl_git_pass(git_note_read(&namespace_note, _repo, "refs/notes/some/namespace", &target_oid)); assert_note_equal(namespace_note, "hello new ref world\n", ¬e_oid); git_note_free(note); git_note_free(namespace_note); }
/* Test that we can read a note */ void test_notes_notes__can_read_a_note(void) { git_oid note_oid, target_oid; git_note *note; create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 4a20\n"); cl_git_pass(git_oid_fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &target_oid)); cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n"); git_note_free(note); }
void test_notes_notes__can_insert_a_note_with_a_custom_namespace(void) { git_oid note_oid, target_oid; git_note *note; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world on a custom namespace\n"); cl_git_pass(git_note_read(¬e, _repo, "refs/notes/some/namespace", &target_oid)); assert_note_equal(note, "hello world on a custom namespace\n", ¬e_oid); git_note_free(note); }
/* * $ git ls-tree refs/notes/fanout * 040000 tree 4b22b35d44b5a4f589edf3dc89196399771796ea 84 * * $ git ls-tree 4b22b35 * 040000 tree d71aab4f9b04b45ce09bcaa636a9be6231474759 96 * * $ git ls-tree d71aab4 * 100644 blob 08b041783f40edfe12bb406c9c9a8a040177c125 071c1b46c854b31185ea97743be6a8774479 */ void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void) { size_t i; git_oid note_oid, target_oid; git_note *_note; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); for (i = 0; i < MESSAGES_COUNT; i++) { cl_git_pass(git_note_create(¬e_oid, _repo, "refs/notes/fanout", _sig, _sig, &target_oid, messages[i], 0)); cl_git_pass(git_note_read(&_note, _repo, "refs/notes/fanout", &target_oid)); git_note_free(_note); git_oid_cpy(&target_oid, ¬e_oid); } }
static int rebase_copy_note( git_rebase *rebase, const char *notes_ref, git_oid *from, git_oid *to, const git_signature *committer) { git_note *note = NULL; git_oid note_id; git_signature *who = NULL; int error; if ((error = git_note_read(¬e, rebase->repo, notes_ref, from)) < 0) { if (error == GIT_ENOTFOUND) { giterr_clear(); error = 0; } goto done; } if (!committer) { if((error = git_signature_default(&who, rebase->repo)) < 0) { if (error != GIT_ENOTFOUND || (error = git_signature_now(&who, "unknown", "unknown")) < 0) goto done; giterr_clear(); } committer = who; } error = git_note_create(¬e_id, rebase->repo, notes_ref, git_note_author(note), committer, to, git_note_message(note), 0); done: git_note_free(note); git_signature_free(who); return error; }
void test_notes_notes__iterate_from_commit(void) { git_note_iterator *iter; git_note *note; git_oid note_id, annotated_id; git_oid oids[2]; git_oid notes_commit_oids[2]; git_commit *notes_commits[2]; const char* note_message[] = { "I decorate a65f\n", "I decorate c478\n" }; int i, err; cl_git_pass(git_oid_fromstr(&(oids[0]), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); cl_git_pass(git_oid_fromstr(&(oids[1]), "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_note_commit_create(¬es_commit_oids[0], NULL, _repo, NULL, _sig, _sig, &(oids[0]), note_message[0], 0)); git_commit_lookup(¬es_commits[0], _repo, ¬es_commit_oids[0]); cl_assert(notes_commits[0]); cl_git_pass(git_note_commit_create(¬es_commit_oids[1], NULL, _repo, notes_commits[0], _sig, _sig, &(oids[1]), note_message[1], 0)); git_commit_lookup(¬es_commits[1], _repo, ¬es_commit_oids[1]); cl_assert(notes_commits[1]); cl_git_pass(git_note_commit_iterator_new(&iter, notes_commits[1])); for (i = 0; (err = git_note_next(¬e_id, &annotated_id, iter)) >= 0; ++i) { cl_git_pass(git_note_commit_read(¬e, _repo, notes_commits[1], &annotated_id)); cl_assert_equal_s(git_note_message(note), note_message[i]); git_note_free(note); } cl_assert_equal_i(GIT_ITEROVER, err); cl_assert_equal_i(2, i); git_note_iterator_free(iter); git_commit_free(notes_commits[0]); git_commit_free(notes_commits[1]); }
/* Test that we can read a note with from commit api */ void test_notes_notes__can_read_a_note_from_a_commit(void) { git_oid oid, notes_commit_oid; git_commit *notes_commit; git_note *note; cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1)); git_commit_lookup(¬es_commit, _repo, ¬es_commit_oid); cl_assert(notes_commit); cl_git_pass(git_note_commit_read(¬e, _repo, notes_commit, &oid)); cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n"); git_commit_free(notes_commit); git_note_free(note); }
/* * call-seq: * obj.notes(notes_ref = 'refs/notes/commits') -> hash * * Lookup a note for +obj+ from +notes_ref+: * - +notes_ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits" * * Returns a new Hash object. * * obj.notes #=> {:message=>"note text\n", :oid=>"94eca2de348d5f672faf56b0decafa5937e3235e"} */ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self) { git_repository *repo; const char *notes_ref = NULL; VALUE rb_notes_ref; VALUE rb_note_hash; VALUE owner; git_note *note; git_object *object; int error; rb_scan_args(argc, argv, "01", &rb_notes_ref); if (!NIL_P(rb_notes_ref)) { Check_Type(rb_notes_ref, T_STRING); notes_ref = StringValueCStr(rb_notes_ref); } Data_Get_Struct(self, git_object, object); owner = rugged_owner(self); Data_Get_Struct(owner, git_repository, repo); error = git_note_read(¬e, repo, notes_ref, git_object_id(object)); if (error == GIT_ENOTFOUND) return Qnil; rugged_exception_check(error); rb_note_hash = rb_hash_new(); rb_hash_aset(rb_note_hash, CSTR2SYM("message"), rugged_git_note_message(note)); rb_hash_aset(rb_note_hash, CSTR2SYM("oid"), rugged_git_note_oid(note)); git_note_free(note); return rb_note_hash; }