Commit f01a8587 by Etienne Samson

tests: make reflog_check_entry more clar-y

parent b9b1f9f8
...@@ -37,23 +37,23 @@ void test_refs_reflog_messages__setting_head_updates_reflog(void) ...@@ -37,23 +37,23 @@ void test_refs_reflog_messages__setting_head_updates_reflog(void)
cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test")); /* 1 */ cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test")); /* 1 */
cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master")); /* 0 */ cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master")); /* 0 */
reflog_check_entry(g_repo, GIT_HEAD_FILE, 4, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 4,
NULL, "refs/heads/haacked", NULL, "refs/heads/haacked",
"foo@example.com", "foo@example.com",
"checkout: moving from master to haacked"); "checkout: moving from master to haacked");
reflog_check_entry(g_repo, GIT_HEAD_FILE, 3, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 3,
NULL, "tags/test^{commit}", NULL, "tags/test^{commit}",
"foo@example.com", "foo@example.com",
"checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d"); "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
reflog_check_entry(g_repo, GIT_HEAD_FILE, 2, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 2,
"tags/test^{commit}", "refs/heads/haacked", "tags/test^{commit}", "refs/heads/haacked",
"foo@example.com", "foo@example.com",
"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked"); "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
reflog_check_entry(g_repo, GIT_HEAD_FILE, 1, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 1,
"refs/heads/haacked", "tags/test^{commit}", "refs/heads/haacked", "tags/test^{commit}",
"foo@example.com", "foo@example.com",
"checkout: moving from haacked to test"); "checkout: moving from haacked to test");
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"tags/test^{commit}", "refs/remotes/test/master", "tags/test^{commit}", "refs/remotes/test/master",
"foo@example.com", "foo@example.com",
"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master"); "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master");
...@@ -61,7 +61,7 @@ void test_refs_reflog_messages__setting_head_updates_reflog(void) ...@@ -61,7 +61,7 @@ void test_refs_reflog_messages__setting_head_updates_reflog(void)
cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "haacked~0")); cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "haacked~0"));
cl_git_pass(git_repository_set_head_detached_from_annotated(g_repo, annotated)); cl_git_pass(git_repository_set_head_detached_from_annotated(g_repo, annotated));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
NULL, "refs/heads/haacked", NULL, "refs/heads/haacked",
"foo@example.com", "foo@example.com",
"checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0"); "checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0");
...@@ -96,14 +96,14 @@ void test_refs_reflog_messages__detaching_writes_reflog(void) ...@@ -96,14 +96,14 @@ void test_refs_reflog_messages__detaching_writes_reflog(void)
msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d"; msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d"); git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
cl_git_pass(git_repository_set_head_detached(g_repo, &id)); cl_git_pass(git_repository_set_head_detached(g_repo, &id));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", "e90810b8df3e80c413d903f631643c716887138d",
NULL, msg); NULL, msg);
msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked"; msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked";
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"e90810b8df3e80c413d903f631643c716887138d", "e90810b8df3e80c413d903f631643c716887138d",
"258f0e2a959a364e40ed6603d5d44fbb24765b10", "258f0e2a959a364e40ed6603d5d44fbb24765b10",
NULL, msg); NULL, msg);
...@@ -120,14 +120,14 @@ void test_refs_reflog_messages__orphan_branch_does_not_count(void) ...@@ -120,14 +120,14 @@ void test_refs_reflog_messages__orphan_branch_does_not_count(void)
msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d"; msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d"); git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
cl_git_pass(git_repository_set_head_detached(g_repo, &id)); cl_git_pass(git_repository_set_head_detached(g_repo, &id));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", "e90810b8df3e80c413d903f631643c716887138d",
NULL, msg); NULL, msg);
/* Switching to an orphan branch does not write to the reflog */ /* Switching to an orphan branch does not write to the reflog */
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan")); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan"));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", "e90810b8df3e80c413d903f631643c716887138d",
NULL, msg); NULL, msg);
...@@ -135,7 +135,7 @@ void test_refs_reflog_messages__orphan_branch_does_not_count(void) ...@@ -135,7 +135,7 @@ void test_refs_reflog_messages__orphan_branch_does_not_count(void)
/* And coming back, we set the source to zero */ /* And coming back, we set the source to zero */
msg = "checkout: moving from orphan to haacked"; msg = "checkout: moving from orphan to haacked";
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"0000000000000000000000000000000000000000", "0000000000000000000000000000000000000000",
"258f0e2a959a364e40ed6603d5d44fbb24765b10", "258f0e2a959a364e40ed6603d5d44fbb24765b10",
NULL, msg); NULL, msg);
...@@ -245,7 +245,7 @@ void test_refs_reflog_messages__show_merge_for_merge_commits(void) ...@@ -245,7 +245,7 @@ void test_refs_reflog_messages__show_merge_for_merge_commits(void)
"Merge commit", tree, "Merge commit", tree,
2, (const struct git_commit **) parent_commits)); 2, (const struct git_commit **) parent_commits));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
NULL, NULL,
git_oid_tostr_s(&merge_commit_oid), git_oid_tostr_s(&merge_commit_oid),
NULL, "commit (merge): Merge commit"); NULL, "commit (merge): Merge commit");
...@@ -291,7 +291,7 @@ void test_refs_reflog_messages__renaming_ref(void) ...@@ -291,7 +291,7 @@ void test_refs_reflog_messages__renaming_ref(void)
cl_git_pass(git_reference_rename(&new_ref, ref, "refs/heads/renamed", false, cl_git_pass(git_reference_rename(&new_ref, ref, "refs/heads/renamed", false,
"message")); "message"));
reflog_check_entry(g_repo, git_reference_name(new_ref), 0, cl_reflog_check_entry(g_repo, git_reference_name(new_ref), 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"foo@example.com", "message"); "foo@example.com", "message");
...@@ -313,7 +313,7 @@ void test_refs_reflog_messages__updating_a_direct_reference(void) ...@@ -313,7 +313,7 @@ void test_refs_reflog_messages__updating_a_direct_reference(void)
cl_git_pass(git_reference_set_target(&ref_out, ref, &target_id, message)); cl_git_pass(git_reference_set_target(&ref_out, ref, &target_id, message));
reflog_check_entry(g_repo, "refs/heads/master", 0, cl_reflog_check_entry(g_repo, "refs/heads/master", 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"258f0e2a959a364e40ed6603d5d44fbb24765b10", "258f0e2a959a364e40ed6603d5d44fbb24765b10",
NULL, message); NULL, message);
...@@ -340,7 +340,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void) ...@@ -340,7 +340,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
cl_git_pass(git_branch_create(&branch, g_repo, NEW_BRANCH_NAME, target, false)); cl_git_pass(git_branch_create(&branch, g_repo, NEW_BRANCH_NAME, target, false));
cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target)))); cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
GIT_OID_HEX_ZERO, GIT_OID_HEX_ZERO,
git_oid_tostr_s(git_commit_id(target)), git_oid_tostr_s(git_commit_id(target)),
g_email, git_buf_cstr(&buf)); g_email, git_buf_cstr(&buf));
...@@ -352,7 +352,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void) ...@@ -352,7 +352,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3")); cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3"));
cl_git_pass(git_branch_create_from_annotated(&branch, g_repo, NEW_BRANCH_NAME, annotated, true)); cl_git_pass(git_branch_create_from_annotated(&branch, g_repo, NEW_BRANCH_NAME, annotated, true));
reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
GIT_OID_HEX_ZERO, GIT_OID_HEX_ZERO,
git_oid_tostr_s(git_commit_id(target)), git_oid_tostr_s(git_commit_id(target)),
g_email, "branch: Created from e90810b8df3"); g_email, "branch: Created from e90810b8df3");
...@@ -371,7 +371,7 @@ void test_refs_reflog_messages__moving_branch_default_message(void) ...@@ -371,7 +371,7 @@ void test_refs_reflog_messages__moving_branch_default_message(void)
git_oid_cpy(&id, git_reference_target(branch)); git_oid_cpy(&id, git_reference_target(branch));
cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0)); cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0));
reflog_check_entry(g_repo, git_reference_name(new_branch), 0, cl_reflog_check_entry(g_repo, git_reference_name(new_branch), 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
g_email, g_email,
...@@ -388,7 +388,7 @@ void test_refs_reflog_messages__detaching_head_default_message(void) ...@@ -388,7 +388,7 @@ void test_refs_reflog_messages__detaching_head_default_message(void)
cl_assert_equal_i(false, git_repository_head_detached(g_repo)); cl_assert_equal_i(false, git_repository_head_detached(g_repo));
cl_git_pass(git_repository_detach_head(g_repo)); cl_git_pass(git_repository_detach_head(g_repo));
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
NULL, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); NULL, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
...@@ -399,7 +399,7 @@ void test_refs_reflog_messages__detaching_head_default_message(void) ...@@ -399,7 +399,7 @@ void test_refs_reflog_messages__detaching_head_default_message(void)
true, "REATTACH")); true, "REATTACH"));
git_reference_free(ref); git_reference_free(ref);
reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
NULL, "REATTACH"); NULL, "REATTACH");
......
...@@ -15,51 +15,89 @@ size_t reflog_entrycount(git_repository *repo, const char *name) ...@@ -15,51 +15,89 @@ size_t reflog_entrycount(git_repository *repo, const char *name)
return ret; return ret;
} }
void reflog_check_entry(git_repository *repo, const char *reflog, size_t idx, void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
const char *old_spec, const char *new_spec, const char *old_spec, const char *new_spec,
const char *email, const char *message) const char *email, const char *message, const char *file, int line)
{ {
git_reflog *log; git_reflog *log;
const git_reflog_entry *entry; const git_reflog_entry *entry;
git_buf result = GIT_BUF_INIT;
cl_git_pass(git_reflog_read(&log, repo, reflog)); cl_git_pass(git_reflog_read(&log, repo, reflog));
entry = git_reflog_entry_byindex(log, idx); entry = git_reflog_entry_byindex(log, idx);
if (entry == NULL)
clar__fail(file, line, "Reflog has no such entry", NULL, 1);
if (old_spec) { if (old_spec) {
git_object *obj = NULL; git_object *obj = NULL;
if (git_revparse_single(&obj, repo, old_spec) == GIT_OK) { if (git_revparse_single(&obj, repo, old_spec) == GIT_OK) {
cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_old(entry)); if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_buf_puts(&result, "\"\n");
}
git_object_free(obj); git_object_free(obj);
} else { } else {
git_oid *oid = git__calloc(1, sizeof(*oid)); git_oid *oid = git__calloc(1, sizeof(*oid));
git_oid_fromstr(oid, old_spec); git_oid_fromstr(oid, old_spec);
cl_assert_equal_oid(oid, git_reflog_entry_id_old(entry)); if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_buf_puts(&result, "\"\n");
}
git__free(oid); git__free(oid);
} }
} }
if (new_spec) { if (new_spec) {
git_object *obj = NULL; git_object *obj = NULL;
if (git_revparse_single(&obj, repo, new_spec) == GIT_OK) { if (git_revparse_single(&obj, repo, new_spec) == GIT_OK) {
cl_assert_equal_oid(git_object_id(obj), git_reflog_entry_id_new(entry)); if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_buf_puts(&result, "\"\n");
}
git_object_free(obj); git_object_free(obj);
} else { } else {
git_oid *oid = git__calloc(1, sizeof(*oid)); git_oid *oid = git__calloc(1, sizeof(*oid));
git_oid_fromstr(oid, new_spec); git_oid_fromstr(oid, new_spec);
cl_assert_equal_oid(oid, git_reflog_entry_id_new(entry)); if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_buf_puts(&result, "\"\n");
}
git__free(oid); git__free(oid);
} }
} }
if (email) { if (email && strcmp(email, git_reflog_entry_committer(entry)->email) != 0)
cl_assert_equal_s(email, git_reflog_entry_committer(entry)->email); git_buf_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email);
}
if (message) { if (message) {
cl_assert_equal_s(message, git_reflog_entry_message(entry)); const char *entry_msg = git_reflog_entry_message(entry);
if (entry_msg == NULL) entry_msg = "";
if (entry_msg && strcmp(message, entry_msg) != 0)
git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
} }
if (git_buf_len(&result) != 0)
clar__fail(file, line, "Reflog entry mismatch", git_buf_cstr(&result), 1);
git_buf_free(&result);
git_reflog_free(log); git_reflog_free(log);
} }
static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry)
{
char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];
assert(out && entry);
git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry));
git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry));
return git_buf_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
}
void reflog_print(git_repository *repo, const char *reflog_name) void reflog_print(git_repository *repo, const char *reflog_name)
{ {
git_reflog *reflog; git_reflog *reflog;
...@@ -70,12 +108,8 @@ void reflog_print(git_repository *repo, const char *reflog_name) ...@@ -70,12 +108,8 @@ void reflog_print(git_repository *repo, const char *reflog_name)
for (idx = 0; idx < git_reflog_entrycount(reflog); idx++) { for (idx = 0; idx < git_reflog_entrycount(reflog); idx++) {
const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, idx); const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, idx);
char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];; reflog_entry_tostr(&out, entry);
git_buf_putc(&out, '\n');
git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry));
git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry));
git_buf_printf(&out, "%ld: %s %s %s %s\n", idx, old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
} }
fprintf(stderr, "%s", git_buf_cstr(&out)); fprintf(stderr, "%s", git_buf_cstr(&out));
......
size_t reflog_entrycount(git_repository *repo, const char *name); size_t reflog_entrycount(git_repository *repo, const char *name);
void reflog_check_entry(git_repository *repo, const char *reflog, size_t idx,
#define cl_reflog_check_entry(repo, reflog, idx, old_spec, new_spec, email, message) \
cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __LINE__)
void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
const char *old_spec, const char *new_spec, const char *old_spec, const char *new_spec,
const char *email, const char *message); const char *email, const char *message, const char *file, int line);
void reflog_print(git_repository *repo, const char *reflog_name); void reflog_print(git_repository *repo, const char *reflog_name);
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