Commit 5f4d2f9f6574fd41d9340ef80de0813bde80b76d

Ben Straub 2012-07-31T19:49:19

Checkout: fix problem with detached HEAD.

diff --git a/src/checkout.c b/src/checkout.c
index e8fba79..252d9c4 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -216,15 +216,12 @@ int git_checkout_reference(git_reference *ref,
 	git_reference *head = NULL;
 	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;
 
-	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);
 
-gcr_cleanup:
 	git_reference_free(head);
 	return retcode;
 }
diff --git a/tests-clar/checkout/checkout.c b/tests-clar/checkout/checkout.c
index 3a27fe5..af3bae9 100644
--- a/tests-clar/checkout/checkout.c
+++ b/tests-clar/checkout/checkout.c
@@ -177,3 +177,8 @@ void test_checkout_checkout__open_flags(void)
 	cl_git_pass(git_checkout_head(g_repo, &opts, NULL));
 	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. */
+}