mirror of
https://github.com/git/git
synced 2024-10-30 04:01:21 +00:00
Merge branch 'jk/clone-unborn-head-in-bare'
"git clone" from a repository whose HEAD is unborn into a bare repository didn't follow the branch name the other side used, which is corrected. * jk/clone-unborn-head-in-bare: clone: handle unborn branch in bare repos
This commit is contained in:
commit
ac162a606b
2 changed files with 30 additions and 16 deletions
|
@ -1229,6 +1229,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
|||
our_head_points_at = remote_head_points_at;
|
||||
}
|
||||
else {
|
||||
const char *branch;
|
||||
char *ref;
|
||||
|
||||
if (option_branch)
|
||||
die(_("Remote branch %s not found in upstream %s"),
|
||||
option_branch, remote_name);
|
||||
|
@ -1239,9 +1242,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
|||
remote_head_points_at = NULL;
|
||||
remote_head = NULL;
|
||||
option_no_checkout = 1;
|
||||
if (!option_bare) {
|
||||
const char *branch;
|
||||
char *ref;
|
||||
|
||||
if (transport_ls_refs_options.unborn_head_target &&
|
||||
skip_prefix(transport_ls_refs_options.unborn_head_target,
|
||||
|
@ -1254,10 +1254,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
|||
ref = xstrfmt("refs/heads/%s", branch);
|
||||
}
|
||||
|
||||
if (!option_bare)
|
||||
install_branch_config(0, branch, remote_name, ref);
|
||||
|
||||
free(ref);
|
||||
}
|
||||
}
|
||||
|
||||
write_refspec_config(src_ref_prefix, our_head_points_at,
|
||||
remote_head_points_at, &branch_top);
|
||||
|
|
|
@ -237,6 +237,19 @@ test_expect_success '...but not if explicitly forbidden by config' '
|
|||
! grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'bare clone propagates empty default branch' '
|
||||
test_when_finished "rm -rf file_empty_parent file_empty_child.git" &&
|
||||
|
||||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
|
||||
git -c init.defaultBranch=mydefaultbranch init file_empty_parent &&
|
||||
|
||||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
|
||||
git -c init.defaultBranch=main -c protocol.version=2 \
|
||||
clone --bare \
|
||||
"file://$(pwd)/file_empty_parent" file_empty_child.git &&
|
||||
grep "refs/heads/mydefaultbranch" file_empty_child.git/HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'fetch with file:// using protocol v2' '
|
||||
test_when_finished "rm -f log" &&
|
||||
|
||||
|
|
Loading…
Reference in a new issue