[BUG] (minor) Cloning an empty repository

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Git fails to clone an empty repository (no commit yet), but claims it
does:

/tmp$ mkdir empty
/tmp$ cd empty
/tmp/empty$ git init
Initialized empty Git repository in .git/
/tmp/empty$ cd ../
/tmp$ git clone empty my-clone
Initialized empty Git repository in /tmp/my-clone/.git/

# All seems correct.

/tmp$ cd my-clone
cd: no such file or directory: my-clone

# Gosh, git lied when telling me it initialized
# /tmp/my-clone/.git/ ? ;-)

A quick look at the code tells me that the directory was actually
initialized, but later, at git-clone.sh:282,

			# objects directory should not be empty because
			# we are cloning!
			test -f "$repo/$sample_file" || exit

and the exit is trapped to "cleanup()" which rm -fr the directory.
Unfortunately, just commenting-out this line isn't sufficient, it
leaves me with a half-initialized repository (.git/config/ doesn't
contain the "origin" remote).

That's a detail, but it would be better if either git could actually
do the clone, or give me a clean error message like "Can not clone
empty repository".

If no one does anything better, the following patch can be a very
small step forward.


>From fdbb61bb9ac26627c4786b58f38426bde621cdcb Mon Sep 17 00:00:00 2001
From: Matthieu Moy <Matthieu.Moy@xxxxxxx>
Date: Fri, 31 Aug 2007 12:00:09 +0200
Subject: [PATCH] Slightly more informative error message when cloning an empty repository.

---
 git-clone.sh |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index 18003ab..1aad510 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -278,7 +278,11 @@ yes)
 				      find objects -type f -print | sed -e 1q)
 			# objects directory should not be empty because
 			# we are cloning!
-			test -f "$repo/$sample_file" || exit
+			if test \! -f "$repo/$sample_file"
+			then
+				echo "No objects in repository. Cleaning up ..." >&2
+				exit
+			fi
 			if ln "$repo/$sample_file" "$GIT_DIR/objects/sample" 2>/dev/null
 			then
 				rm -f "$GIT_DIR/objects/sample"
-- 
1.5.3.rc6.49.gd50b


PS: In case someone's interested, my use-case is the following:

I have ~/archives/git/ which contains git tree-less repositories
(normally bare repository, but sometimes simply normal repositories in
which I didn't checkout), and I have a working tree somewhere else in
my $HOME (or on my /local, faster but not backed-up). I set my commit
hook to "git push --all", so it's a kind of centralized system inside
my machine. Just to separate the stuff that matters (repositories),
and the others (working tree).

To start a new project, I can either create the repository with the
working tree, and clone it to ~/archives/git/some-project, but it's
more conveinient to create ~/archives/git/some-project and then clone
it somewhere else, since it sets up the "origin" remote for me, and
push/pull work out of the box.

-- 
Matthieu
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux