(minor) Cloning an empty repository
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.
Quoted 1 line
From
fdbb61bb9ac26627c4786b58f38426bde621cdcbMon Sep 17 00:00:00 2001
From: Matthieu Moy <[email protected]>
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(-)
git-clone.sh +5 -1
@@ -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"
Signature · 21 lines
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
Hi,
Quoted 3 lines · Matthieu Moy
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".
FWIW, I would like git to clone empty repositories too. With the current smart remotes handling, it will pick up the first branches as they appear in the other repository automagically. And with e.g. repo.or.cz, if you are starting a project from scratch this would be useful. Sure, you can instead git init && git remote add origin git+ssh://.../, but this fact seems to be confusing not-so-git-well-versed people.
Now, I guess you'd like a patch... ;-)
Signature · 3 lines
Petr "Pasky" Baudis
Early to rise and early to bed makes a male healthy and wealthy and dead.
-- James Thurber