Commit b93688d0 by Vicent Marti

Merge remote-tracking branch 'yorah/fix/notes-creation' into development

Conflicts:
	src/notes.c
parents 515a4c7c 027d77ee
......@@ -634,6 +634,9 @@ void git_treebuilder_clear(git_treebuilder *bld)
void git_treebuilder_free(git_treebuilder *bld)
{
if (bld == NULL)
return;
git_treebuilder_clear(bld);
git_vector_free(&bld->entries);
git__free(bld);
......
......@@ -107,7 +107,7 @@ void test_network_remotelocal__retrieve_advertised_references(void)
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
cl_assert_equal_i(how_many_refs, 20);
cl_assert_equal_i(how_many_refs, 21);
}
void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
......@@ -121,7 +121,7 @@ void test_network_remotelocal__retrieve_advertised_references_from_spaced_reposi
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
cl_assert_equal_i(how_many_refs, 20);
cl_assert_equal_i(how_many_refs, 21);
git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
remote = NULL;
......
......@@ -15,6 +15,16 @@ void test_notes_notes__cleanup(void)
cl_git_sandbox_cleanup();
}
static void assert_note_equal(git_note *note, char *message, git_oid *note_oid) {
git_blob *blob;
cl_assert_equal_s(git_note_message(note), message);
cl_assert(!git_oid_cmp(git_note_oid(note), note_oid));
cl_git_pass(git_blob_lookup(&blob, _repo, note_oid));
cl_assert_equal_s(git_note_message(note), (const char *)git_blob_rawcontent(blob));
}
static void create_note(git_oid *note_oid, const char *canonical_namespace, const char *target_sha, const char *message)
{
git_oid oid;
......@@ -23,38 +33,6 @@ static void create_note(git_oid *note_oid, const char *canonical_namespace, cons
cl_git_pass(git_note_create(note_oid, _repo, _sig, _sig, canonical_namespace, &oid, message));
}
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(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n"));
cl_git_pass(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
cl_git_pass(git_note_read(&note, _repo, NULL, &oid));
cl_assert_equal_s(git_note_message(note), "hello world\n");
cl_assert(!git_oid_cmp(git_note_oid(note), &note_oid));
cl_git_pass(git_blob_lookup(&blob, _repo, &note_oid));
cl_assert_equal_s(git_note_message(note), git_blob_rawcontent(blob));
cl_git_fail(git_note_create(&note_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n"));
cl_git_fail(git_note_create(&note_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, &note_oid));
cl_git_fail(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid));
git_note_free(note);
git_blob_free(blob);
}
static struct {
const char *note_sha;
const char *annotated_object_sha;
......@@ -131,3 +109,152 @@ void test_notes_notes__retrieving_a_list_of_notes_for_an_unknown_namespace_retur
cl_assert_equal_i(0, retrieved_notes);
}
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(&note_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
cl_git_pass(git_note_read(&note, _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", &note_oid);
assert_note_equal(default_namespace_note, "hello world\n", &note_oid);
git_note_free(note);
git_note_free(default_namespace_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(&note_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world on a custom namespace\n");
cl_git_pass(git_note_read(&note, _repo, "refs/notes/some/namespace", &target_oid));
assert_note_equal(note, "hello world on a custom namespace\n", &note_oid);
git_note_free(note);
}
/*
* $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479
* 08b041783f40edfe12bb406c9c9a8a040177c125
*/
void test_notes_notes__creating_a_note_on_a_target_which_already_has_one_returns_EEXISTS(void)
{
int error;
git_oid note_oid, target_oid;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
create_note(&note_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
error = git_note_create(&note_oid, _repo, _sig, _sig, NULL, &target_oid, "hello world\n");
cl_git_fail(error);
cl_assert_equal_i(GIT_EEXISTS, error);
create_note(&note_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
error = git_note_create(&note_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &target_oid, "hello world\n");
cl_git_fail(error);
cl_assert_equal_i(GIT_EEXISTS, error);
}
static char *messages[] = {
"08c041783f40edfe12bb406c9c9a8a040177c125",
"96c45fbe09ab7445fc7c60fd8d17f32494399343",
"48cc7e38dcfc1ec87e70ec03e08c3e83d7a16aa1",
"24c3eaafb681c3df668f9df96f58e7b8c756eb04",
"96ca1b6ccc7858ae94684777f85ac0e7447f7040",
"7ac2db4378a08bb244a427c357e0082ee0d57ac6",
"e6cba23dbf4ef84fe35e884f017f4e24dc228572",
"c8cf3462c7d8feba716deeb2ebe6583bd54589e2",
"39c16b9834c2d665ac5f68ad91dc5b933bad8549",
"f3c582b1397df6a664224ebbaf9d4cc952706597",
"29cec67037fe8e89977474988219016ae7f342a6",
"36c4cd238bf8e82e27b740e0741b025f2e8c79ab",
"f1c45a47c02e01d5a9a326f1d9f7f756373387f8",
"4aca84406f5daee34ab513a60717c8d7b1763ead",
"84ce167da452552f63ed8407b55d5ece4901845f",
NULL
};
#define MESSAGES_COUNT (sizeof(messages)/sizeof(messages[0])) - 1
/*
* $ 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(&note_oid, _repo, _sig, _sig, "refs/notes/fanout", &target_oid, messages[i]));
cl_git_pass(git_note_read(&_note, _repo, "refs/notes/fanout", &target_oid));
git_note_free(_note);
git_oid_cpy(&target_oid, &note_oid);
}
}
/*
* $ 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(&note, _repo, "refs/notes/fanout", &target_oid));
cl_git_pass(git_oid_fromstr(&note_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
cl_assert(!git_oid_cmp(git_note_oid(note), &note_oid));
git_note_free(note);
}
void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void)
{
git_oid target_oid;
git_note *note;
cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
cl_git_fail(git_note_read(&note, _repo, "refs/notes/fanout", &target_oid));
}
void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(void)
{
int error;
git_oid target_oid;
cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid);
cl_git_fail(error);
cl_assert_equal_i(GIT_ENOTFOUND, error);
}
d07b0f9a8c89f1d9e74dc4fce6421dec5ef8a659
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment