Commit e128a1af by Carlos Martín Nieto

clone: correct handling of an unborn HEAD

If the remote does not advertise HEAD, then it is unborn and we cannot
checkout that branch. Handle it the same way as an empty repo.
parent 538f9081
......@@ -138,23 +138,6 @@ static int update_head_to_new_branch(
return error;
}
/**
* Check whether there are any branches among the listed
* references. It's possible for a repository to have a long list of
* references without us downloading any of them.
*/
static bool remote_has_branches(const git_remote_head **refs, size_t len)
{
size_t i;
for (i = 0; i < len; i++) {
if (!git__prefixcmp(refs[i]->name, GIT_REFS_HEADS_DIR))
return true;
}
return false;
}
static int update_head_to_remote(
git_repository *repo,
git_remote *remote,
......@@ -172,8 +155,8 @@ static int update_head_to_remote(
if ((error = git_remote_ls(&refs, &refs_len, remote)) < 0)
return error;
/* Did we just clone an empty repository? */
if (!remote_has_branches(refs, refs_len))
/* We cloned an empty repository or one with an unborn HEAD */
if (refs_len == 0 || strcmp(refs[0]->name, GIT_HEAD_FILE))
return setup_tracking_config(
repo, "master", GIT_REMOTE_ORIGIN, GIT_REFS_HEADS_MASTER_FILE);
......
......@@ -91,3 +91,18 @@ void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void)
git_repository_free(cloned_repo);
}
void test_network_remote_defaultbranch__unborn_HEAD_with_branches(void)
{
git_reference *ref;
git_repository *cloned_repo;
cl_git_pass(git_reference_symbolic_create(&ref, g_repo_a, "HEAD", "refs/heads/i-dont-exist", 1, NULL, NULL));
git_reference_free(ref);
cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./semi-empty", NULL));
cl_assert(git_repository_head_unborn(cloned_repo));
git_repository_free(cloned_repo);
}
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