mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-21 13:02:38 +00:00
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.
This commit is contained in:
parent
538f908175
commit
e128a1af6e
21
src/clone.c
21
src/clone.c
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user