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 <gitster@pobox.com>
Junio C Hamano committed
Feb 11, 2009 at 22:42 UTC
5cd12b85fe8ff74f202a158511ead34e8aba584c
2 files changed
+33
-5
builtin-clone.c
+18
-5
@@ -350,6 +350,19 @@ static struct ref *write_remote_refs(const struct ref *refs,
350
return local_refs;
351
}
352
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
+
366
int cmd_clone(int argc, const char **argv, const char *prefix)
367
{
368
int use_local_hardlinks = 1;
@@ -539,6 +552,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
552
head_points_at = NULL;
553
remote_head = NULL;
554
option_no_checkout = 1;
555
+ if (!option_bare)
556
+ install_branch_config("master", option_origin,
557
+ "refs/heads/master");
558
}
559
560
if (head_points_at) {
@@ -567,11 +583,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
583
head_points_at->peer_ref->name,
584
reflog_msg.buf);
585
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);
588
}
589
} else if (remote_head) {
590
/* Source had detached HEAD pointing somewhere. */
t/t5601-clone.sh
+15
@@ -144,4 +144,19 @@ test_expect_success 'clone to an existing path' '
144
test_must_fail git clone src target-5
145
'
146
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
+
162
test_done