* [BUG] (minor) Cloning an empty repository
@ 2007-08-31 10:03 Matthieu Moy
2007-08-31 10:10 ` Petr Baudis
0 siblings, 1 reply; 2+ messages in thread
From: Matthieu Moy @ 2007-08-31 10:03 UTC (permalink / raw)
To: git
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [BUG] (minor) Cloning an empty repository
2007-08-31 10:03 [BUG] (minor) Cloning an empty repository Matthieu Moy
@ 2007-08-31 10:10 ` Petr Baudis
0 siblings, 0 replies; 2+ messages in thread
From: Petr Baudis @ 2007-08-31 10:10 UTC (permalink / raw)
To: Matthieu Moy; +Cc: git
Hi,
On Fri, Aug 31, 2007 at 12:03:50PM CEST, Matthieu Moy wrote:
> 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... ;-)
--
Petr "Pasky" Baudis
Early to rise and early to bed makes a male healthy and wealthy and dead.
-- James Thurber
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-08-31 10:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-31 10:03 [BUG] (minor) Cloning an empty repository Matthieu Moy
2007-08-31 10:10 ` Petr Baudis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox