2013/1/30 nulltoken <notifications@github.com>

> In tests-clar/clone/nonetwork.c:
>
> > @@ -175,3 +175,23 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
> >  	cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test");
> >  }
> >
> > +void test_clone_nonetwork__can_detached_head(void)
> > +{
> > +	git_oid out;
> > +	git_commit *commit = NULL;
> > +	cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
> > +	cl_git_pass(git_reference_name_to_id(&out, g_repo, "refs/heads/master"));
> > +	cl_git_pass(git_commit_lookup(&commit, g_repo, &out));
> > +	cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_parent_id(commit, 0)));
>
> As you do not assert below which commit the detached Head points to, you
> may be willing to replace the three lines above with
>
> cl_git_pass(git_repository_detach_head(repo));
>
> If detach head is the same hash value with master, clone will auto choose
"master", not detached HEAD. I already try git. that's the same behaviors.

So I have to detach head as "master~1".

>  Of course, a more thorough option would be to verify that Head indeed
> points to the same commit oid ;-)
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/libgit2/libgit2/pull/1286/files#r2822644>.
>
>