Commit 7ac1b899 by Ben Straub

Add failing test case

parent 40e10630
......@@ -195,10 +195,41 @@ void test_repo_head__can_tell_if_an_unborn_head_is_detached(void)
cl_assert_equal_i(false, git_repository_head_detached(repo));
}
void test_repo_head__setting_head_updates_reflog(void)
static void test_reflog(git_repository *repo, size_t idx,
const char *old_spec, const char *new_spec,
const char *email, const char *message)
{
git_reflog *log;
const git_reflog_entry *entry1, *entry2, *entry3;
git_reflog_entry *entry;
cl_git_pass(git_reflog_read(&log, repo, "HEAD"));
entry = git_reflog_entry_byindex(log, idx);
if (old_spec) {
git_object *obj;
cl_git_pass(git_revparse_single(&obj, repo, old_spec));
cl_assert_equal_i(0, git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)));
git_object_free(obj);
}
if (new_spec) {
git_object *obj;
cl_git_pass(git_revparse_single(&obj, repo, new_spec));
cl_assert_equal_i(0, git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)));
git_object_free(obj);
}
if (email) {
cl_assert_equal_s(email, git_reflog_entry_committer(entry)->email);
}
if (message) {
cl_assert_equal_s(message, git_reflog_entry_message(entry));
}
git_reflog_free(log);
}
void test_repo_head__setting_head_updates_reflog(void)
{
git_object *tag;
git_signature *sig;
......@@ -208,19 +239,13 @@ void test_repo_head__setting_head_updates_reflog(void)
cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn", sig, "message2"));
cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag), sig, "message3"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, "message4"));
cl_git_pass(git_reflog_read(&log, repo, "HEAD"));
entry1 = git_reflog_entry_byindex(log, 2);
entry2 = git_reflog_entry_byindex(log, 1);
entry3 = git_reflog_entry_byindex(log, 0);
cl_assert_equal_s("message1", git_reflog_entry_message(entry1));
cl_assert_equal_s("message2", git_reflog_entry_message(entry2));
cl_assert_equal_s("message3", git_reflog_entry_message(entry3));
cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry1)->email);
cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry2)->email);
cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry3)->email);
test_reflog(repo, 3, NULL, "refs/heads/haacked", "foo@example.com", "message1");
test_reflog(repo, 2, "refs/heads/haacked", NULL, "foo@example.com", "message2");
test_reflog(repo, 1, NULL, "tags/test^{commit}", "foo@example.com", "message3");
test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "message4");
git_reflog_free(log);
git_object_free(tag);
git_signature_free(sig);
}
......
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