Git development
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org
Subject: [BUG] (minor) Cloning an empty repository
Date: Fri, 31 Aug 2007 12:03:50 +0200	[thread overview]
Message-ID: <vpqk5rc10mx.fsf@bauges.imag.fr> (raw)

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@imag.fr>
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

             reply	other threads:[~2007-08-31 10:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-31 10:03 Matthieu Moy [this message]
2007-08-31 10:10 ` [BUG] (minor) Cloning an empty repository Petr Baudis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=vpqk5rc10mx.fsf@bauges.imag.fr \
    --to=matthieu.moy@imag.fr \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox