tests: leverage git_repository_detach_head()
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 74 75 76 77 78 79 80 81 82
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index 99af44e..656a618 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -64,13 +64,15 @@ void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void)
void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void)
{
- git_reference *master, *head, *branch;
+ git_reference *head, *branch;
- /* Detach HEAD and make it target the commit that "master" points to */
- cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
- cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", git_reference_oid(master), 1));
+ cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE));
+ cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
+ cl_assert_equal_s("refs/heads/master", git_reference_target(head));
git_reference_free(head);
- git_reference_free(master);
+
+ /* Detach HEAD and make it target the commit that "master" points to */
+ git_repository_detach_head(repo);
cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c
index 4113289..34f3f89 100644
--- a/tests-clar/repo/head.c
+++ b/tests-clar/repo/head.c
@@ -16,21 +16,18 @@ void test_repo_head__cleanup(void)
void test_repo_head__head_detached(void)
{
git_reference *ref;
- git_oid oid;
cl_assert(git_repository_head_detached(repo) == 0);
- /* detach the HEAD */
- git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
- cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1));
- cl_assert(git_repository_head_detached(repo) == 1);
- git_reference_free(ref);
+ git_repository_detach_head(repo);
+
+ cl_assert_equal_i(true, git_repository_head_detached(repo));
/* take the reop back to it's original state */
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
- cl_assert(git_repository_head_detached(repo) == 0);
-
git_reference_free(ref);
+
+ cl_assert_equal_i(false, git_repository_head_detached(repo));
}
static void make_head_orphaned(void)
diff --git a/tests-clar/reset/soft.c b/tests-clar/reset/soft.c
index 3200c15..3c678ad 100644
--- a/tests-clar/reset/soft.c
+++ b/tests-clar/reset/soft.c
@@ -39,20 +39,9 @@ void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(vo
assert_reset_soft(false);
}
-static void detach_head(void)
-{
- git_reference *head;
- git_oid oid;
-
- cl_git_pass(git_reference_name_to_oid(&oid, repo, "HEAD"));
-
- cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", &oid, true));
- git_reference_free(head);
-}
-
void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void)
{
- detach_head();
+ git_repository_detach_head(repo);
assert_reset_soft(true);
}