Commit 209e34fa by nulltoken

tests: leverage git_repository_detach_head()

parent c497a63b
...@@ -64,13 +64,15 @@ void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void) ...@@ -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) 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(&head, repo, GIT_HEAD_FILE));
cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master")); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
cl_git_pass(git_reference_create_oid(&head, repo, "HEAD", git_reference_oid(master), 1)); cl_assert_equal_s("refs/heads/master", git_reference_target(head));
git_reference_free(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_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch)); cl_git_pass(git_branch_delete(branch));
......
...@@ -16,21 +16,18 @@ void test_repo_head__cleanup(void) ...@@ -16,21 +16,18 @@ void test_repo_head__cleanup(void)
void test_repo_head__head_detached(void) void test_repo_head__head_detached(void)
{ {
git_reference *ref; git_reference *ref;
git_oid oid;
cl_assert(git_repository_head_detached(repo) == 0); cl_assert(git_repository_head_detached(repo) == 0);
/* detach the HEAD */ git_repository_detach_head(repo);
git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1)); cl_assert_equal_i(true, git_repository_head_detached(repo));
cl_assert(git_repository_head_detached(repo) == 1);
git_reference_free(ref);
/* take the reop back to it's original state */ /* take the reop back to it's original state */
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); 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); git_reference_free(ref);
cl_assert_equal_i(false, git_repository_head_detached(repo));
} }
static void make_head_orphaned(void) static void make_head_orphaned(void)
......
...@@ -39,20 +39,9 @@ void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(vo ...@@ -39,20 +39,9 @@ void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(vo
assert_reset_soft(false); 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) 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); assert_reset_soft(true);
} }
......
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