Commit 5f4d2f9f by Ben Straub

Checkout: fix problem with detached HEAD.

parent 5280f4e6
...@@ -216,15 +216,12 @@ int git_checkout_reference(git_reference *ref, ...@@ -216,15 +216,12 @@ int git_checkout_reference(git_reference *ref,
git_reference *head = NULL; git_reference *head = NULL;
int retcode = GIT_ERROR; int retcode = GIT_ERROR;
if ((retcode = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0) if ((retcode = git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE,
git_reference_name(ref), true)) < 0)
return retcode; return retcode;
if ((retcode = git_reference_set_target(head, git_reference_name(ref))) < 0)
goto gcr_cleanup;
retcode = git_checkout_head(git_reference_owner(ref), opts, stats); retcode = git_checkout_head(git_reference_owner(ref), opts, stats);
gcr_cleanup:
git_reference_free(head); git_reference_free(head);
return retcode; return retcode;
} }
......
...@@ -177,3 +177,8 @@ void test_checkout_checkout__open_flags(void) ...@@ -177,3 +177,8 @@ void test_checkout_checkout__open_flags(void)
cl_git_pass(git_checkout_head(g_repo, &opts, NULL)); cl_git_pass(git_checkout_head(g_repo, &opts, NULL));
test_file_contents("./testrepo/new.txt", "hi\nmy new file\n"); test_file_contents("./testrepo/new.txt", "hi\nmy new file\n");
} }
void test_checkout_checkout__detached_head(void)
{
/* TODO: write this when git_checkout_commit is implemented. */
}
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