Add failing test case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/tests/repo/head.c b/tests/repo/head.c
index 71cfc3c..8ea9a0f 100644
--- a/tests/repo/head.c
+++ b/tests/repo/head.c
@@ -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);
}