{"thread":{"id":"9720","subject":"[BUG] (minor) Cloning an empty repository","startedAt":"2007-08-31T10:03:50Z","lastAt":"2007-08-31T10:10:52Z","messageCount":2,"participants":["Matthieu Moy","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"52016","messageId":"vpqk5rc10mx.fsf@bauges.imag.fr","threadId":"9720","inReplyTo":null,"subject":"[BUG] (minor) Cloning an empty repository","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2007-08-31T10:03:50Z","receivedAt":"2007-08-31T10:03:50Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Hi,\n\nGit fails to clone an empty repository (no commit yet), but claims it\ndoes:\n\n/tmp$ mkdir empty\n/tmp$ cd empty\n/tmp/empty$ git init\nInitialized empty Git repository in .git/\n/tmp/empty$ cd ../\n/tmp$ git clone empty my-clone\nInitialized empty Git repository in /tmp/my-clone/.git/\n\n# All seems correct.\n\n/tmp$ cd my-clone\ncd: no such file or directory: my-clone\n\n# Gosh, git lied when telling me it initialized\n# /tmp/my-clone/.git/ ? ;-)\n\nA quick look at the code tells me that the directory was actually\ninitialized, but later, at git-clone.sh:282,\n\n\t\t\t# objects directory should not be empty because\n\t\t\t# we are cloning!\n\t\t\ttest -f \"$repo/$sample_file\" || exit\n\nand the exit is trapped to \"cleanup()\" which rm -fr the directory.\nUnfortunately, just commenting-out this line isn't sufficient, it\nleaves me with a half-initialized repository (.git/config/ doesn't\ncontain the \"origin\" remote).\n\nThat's a detail, but it would be better if either git could actually\ndo the clone, or give me a clean error message like \"Can not clone\nempty repository\".\n\nIf no one does anything better, the following patch can be a very\nsmall step forward.\n\n\n>From fdbb61bb9ac26627c4786b58f38426bde621cdcb Mon Sep 17 00:00:00 2001\nFrom: Matthieu Moy <Matthieu.Moy@imag.fr>\nDate: Fri, 31 Aug 2007 12:00:09 +0200\nSubject: [PATCH] Slightly more informative error message when cloning an empty repository.\n\n---\n git-clone.sh |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 18003ab..1aad510 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -278,7 +278,11 @@ yes)\n \t\t\t\t      find objects -type f -print | sed -e 1q)\n \t\t\t# objects directory should not be empty because\n \t\t\t# we are cloning!\n-\t\t\ttest -f \"$repo/$sample_file\" || exit\n+\t\t\tif test \\! -f \"$repo/$sample_file\"\n+\t\t\tthen\n+\t\t\t\techo \"No objects in repository. Cleaning up ...\" >&2\n+\t\t\t\texit\n+\t\t\tfi\n \t\t\tif ln \"$repo/$sample_file\" \"$GIT_DIR/objects/sample\" 2>/dev/null\n \t\t\tthen\n \t\t\t\trm -f \"$GIT_DIR/objects/sample\"\n-- \n1.5.3.rc6.49.gd50b\n\n\nPS: In case someone's interested, my use-case is the following:\n\nI have ~/archives/git/ which contains git tree-less repositories\n(normally bare repository, but sometimes simply normal repositories in\nwhich I didn't checkout), and I have a working tree somewhere else in\nmy $HOME (or on my /local, faster but not backed-up). I set my commit\nhook to \"git push --all\", so it's a kind of centralized system inside\nmy machine. Just to separate the stuff that matters (repositories),\nand the others (working tree).\n\nTo start a new project, I can either create the repository with the\nworking tree, and clone it to ~/archives/git/some-project, but it's\nmore conveinient to create ~/archives/git/some-project and then clone\nit somewhere else, since it sets up the \"origin\" remote for me, and\npush/pull work out of the box.\n\n-- \nMatthieu\n"},{"id":"52018","messageId":"20070831101052.GO1219@pasky.or.cz","threadId":"9720","inReplyTo":"vpqk5rc10mx.fsf@bauges.imag.fr","subject":"Re: [BUG] (minor) Cloning an empty repository","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2007-08-31T10:10:52Z","receivedAt":"2007-08-31T10:10:52Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"  Hi,\n\nOn Fri, Aug 31, 2007 at 12:03:50PM CEST, Matthieu Moy wrote:\n> That's a detail, but it would be better if either git could actually\n> do the clone, or give me a clean error message like \"Can not clone\n> empty repository\".\n\nFWIW, I would like git to clone empty repositories too. With the current\nsmart remotes handling, it will pick up the first branches as they\nappear in the other repository automagically. And with e.g. repo.or.cz,\nif you are starting a project from scratch this would be useful. Sure,\nyou can instead git init && git remote add origin git+ssh://.../, but\nthis fact seems to be confusing not-so-git-well-versed people.\n\nNow, I guess you'd like a patch... ;-)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nEarly to rise and early to bed makes a male healthy and wealthy and dead.\n                -- James Thurber\n"}]}