Allow cloning an empty repository
Cloning an empty repository manually (that is, doing 'git init' and then doing all configuration by hand) can be a lot of work. Save the user this work by allowing the cloning of empty repositories. Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sverre Rabbelier committed
Jan 23, 2009 at 01:07 UTC
86ac751859033741a120e9e4a91133d075d9d898
2 files changed
+29
-4
builtin-clone.c
+13
-4
@@ -522,14 +522,23 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
522
option_upload_pack);
523
524
refs = transport_get_remote_refs(transport);
525
- transport_fetch_refs(transport, refs);
525
+ if(refs)
526
+ transport_fetch_refs(transport, refs);
527
}
528
528
- clear_extra_refs();
529
+ if (refs) {
530
+ clear_extra_refs();
531
530
- mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
532
+ mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
533
532
- head_points_at = locate_head(refs, mapped_refs, &remote_head);
534
+ head_points_at = locate_head(refs, mapped_refs, &remote_head);
535
+ }
536
+ else {
537
+ warning("You appear to have cloned an empty repository.");
538
+ head_points_at = NULL;
539
+ remote_head = NULL;
540
+ option_no_checkout = 1;
541
+ }
542
543
if (head_points_at) {
544
/* Local default branch link */
t/t5701-clone-local.sh
+16
@@ -116,4 +116,20 @@ test_expect_success 'bundle clone with nonexistent HEAD' '
116
test ! -e .git/refs/heads/master
117
'
118
119
+test_expect_success 'clone empty repository' '
120
+ cd "$D" &&
121
+ mkdir empty &&
122
+ (cd empty && git init) &&
123
+ git clone empty empty-clone &&
124
+ test_tick &&
125
+ (cd empty-clone
126
+ echo "content" >> foo &&
127
+ git add foo &&
128
+ git commit -m "Initial commit" &&
129
+ git push origin master &&
130
+ expected=$(git rev-parse master) &&
131
+ actual=$(git --git-dir=../empty/.git rev-parse master) &&
132
+ test $actual = $expected)
133
+'
134
+
135
test_done