git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Allow cloning an empty repository
@ 2009-01-23  0:07 Sverre Rabbelier
  2009-01-23  1:24 ` Junio C Hamano
  0 siblings, 1 reply; 23+ messages in thread
From: Sverre Rabbelier @ 2009-01-23  0:07 UTC (permalink / raw)
  To: git; +Cc: Sverre Rabbelier

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>
---

Thanks to Dscho for giving some pointers on how to do this.

 builtin-clone.c        |   17 +++++++++++++----
 t/t5701-clone-local.sh |   16 ++++++++++++++++
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/builtin-clone.c b/builtin-clone.c
index f7e5a7b..d5bba0e 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -522,14 +522,23 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 					     option_upload_pack);
 
 		refs = transport_get_remote_refs(transport);
-		transport_fetch_refs(transport, refs);
+		if(refs)
+			transport_fetch_refs(transport, refs);
 	}
 
-	clear_extra_refs();
+	if(refs) {
+		clear_extra_refs();
 
-	mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
+		mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
 
-	head_points_at = locate_head(refs, mapped_refs, &remote_head);
+		head_points_at = locate_head(refs, mapped_refs, &remote_head);
+	}
+	else {
+		warning("You appear to have cloned an empty repository.");
+		head_points_at = NULL;
+		remote_head = NULL;
+		option_no_checkout = 1;
+	}
 
 	if (head_points_at) {
 		/* Local default branch link */
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 8dfaaa4..fbd9bfa 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -116,4 +116,20 @@ test_expect_success 'bundle clone with nonexistent HEAD' '
 	test ! -e .git/refs/heads/master
 '
 
+test_expect_success 'clone empty repository' '
+	cd "$D" &&
+	mkdir empty &&
+	(cd empty && git init) &&
+	git clone empty empty-clone &&
+	test_tick &&
+	(cd empty-clone
+	 echo "content" >> foo &&
+	 git add foo &&
+	 git commit -m "Initial commit" &&
+	 git push origin master &&
+	 expected=$(git rev-parse master) &&
+	 actual=$(git --git-dir=../empty/.git rev-parse master) &&
+	 test $actual = $expected)
+'
+
 test_done
-- 
1.6.1.399.g0d272.dirty

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2009-01-25 18:34 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-23  0:07 [PATCH] Allow cloning an empty repository Sverre Rabbelier
2009-01-23  1:24 ` Junio C Hamano
2009-01-23  1:46   ` Sverre Rabbelier
2009-01-23  2:42     ` Johannes Schindelin
2009-01-23  2:47       ` Sverre Rabbelier
2009-01-23  3:20         ` Johannes Schindelin
2009-01-23 16:55           ` Miklos Vajna
2009-01-23 20:05             ` Johannes Schindelin
2009-01-23 22:32           ` Jeff King
2009-01-23 22:34             ` Sverre Rabbelier
2009-01-23 22:37               ` Jeff King
2009-01-23 22:39                 ` Sverre Rabbelier
2009-01-24  0:28                 ` Johannes Schindelin
2009-01-23 21:55       ` Mike Hommey
2009-01-24  0:26         ` http fixes, was " Johannes Schindelin
2009-01-24  9:39           ` Sverre Rabbelier
2009-01-23 23:05       ` Miklos Vajna
2009-01-24  0:33         ` Johannes Schindelin
2009-01-24  0:42           ` Sverre Rabbelier
2009-01-25  0:49             ` Miklos Vajna
2009-01-25  0:55               ` Sverre Rabbelier
2009-01-25  5:05                 ` Junio C Hamano
2009-01-25 18:33                   ` Sverre Rabbelier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).