Skip to content

Commit 5cd12b8

Browse files
committed
Install the default "master" branch configuration after cloning a void
After "cloning from an empty repository", we have a configuration to describe the remote's URL and the default ref mappings, but we lack the branch configuration for the default branch we create on our end, "master". It is likely that the empty repository we cloned from will point the default "master" branch with its HEAD, so prepare the local configuration to match. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a526d4 commit 5cd12b8

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

builtin-clone.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,19 @@ static struct ref *write_remote_refs(const struct ref *refs,
350350
return local_refs;
351351
}
352352

353+
static void install_branch_config(const char *local,
354+
const char *origin,
355+
const char *remote)
356+
{
357+
struct strbuf key = STRBUF_INIT;
358+
strbuf_addf(&key, "branch.%s.remote", local);
359+
git_config_set(key.buf, origin);
360+
strbuf_reset(&key);
361+
strbuf_addf(&key, "branch.%s.merge", local);
362+
git_config_set(key.buf, remote);
363+
strbuf_release(&key);
364+
}
365+
353366
int cmd_clone(int argc, const char **argv, const char *prefix)
354367
{
355368
int use_local_hardlinks = 1;
@@ -539,6 +552,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
539552
head_points_at = NULL;
540553
remote_head = NULL;
541554
option_no_checkout = 1;
555+
if (!option_bare)
556+
install_branch_config("master", option_origin,
557+
"refs/heads/master");
542558
}
543559

544560
if (head_points_at) {
@@ -567,11 +583,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
567583
head_points_at->peer_ref->name,
568584
reflog_msg.buf);
569585

570-
strbuf_addf(&key, "branch.%s.remote", head);
571-
git_config_set(key.buf, option_origin);
572-
strbuf_reset(&key);
573-
strbuf_addf(&key, "branch.%s.merge", head);
574-
git_config_set(key.buf, head_points_at->name);
586+
install_branch_config(head, option_origin,
587+
head_points_at->name);
575588
}
576589
} else if (remote_head) {
577590
/* Source had detached HEAD pointing somewhere. */

t/t5601-clone.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,19 @@ test_expect_success 'clone to an existing path' '
144144
test_must_fail git clone src target-5
145145
'
146146

147+
test_expect_success 'clone a void' '
148+
mkdir src-0 &&
149+
(
150+
cd src-0 && git init
151+
) &&
152+
git clone src-0 target-6 &&
153+
(
154+
cd src-0 && test_commit A
155+
) &&
156+
git clone src-0 target-7 &&
157+
# There is no reason to insist they are bit-for-bit
158+
# identical, but this test should suffice for now.
159+
test_cmp target-6/.git/config target-7/.git/config
160+
'
161+
147162
test_done

0 commit comments

Comments
 (0)