clone: die when trying to clone missing local path
Since 86ac751 (Allow cloning an empty repository, 2009-01-23), doing: git clone does-not-exist has created does-not-exist as an empty repository. This was an unintentional side effect of 86ac751. Even weirder, doing: git clone does-not-exist new-dir _does_ fail, making this "feature" (if you want to consider it such) broken. Let's detect this situation and explicitly die. It's almost certainly not what the user intended. This patch also adds two tests. One for the missing path case, and one to confirm that a similar case, cloning a non-repository directory, fails. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 17, 2011 at 23:01 UTC
a9026187923643235d4f9b876ff5f4c0ebe5c9ae
2 files changed
+14
-1
builtin/clone.c
+1
-1
@@ -413,7 +413,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
413
if (path)
414
repo = xstrdup(make_nonrelative_path(repo_name));
415
else if (!strchr(repo_name, ':'))
416
- repo = xstrdup(make_absolute_path(repo_name));
416
+ die("repository '%s' does not exist", repo_name);
417
else
418
repo = repo_name;
419
is_local = path && !is_bundle;
t/t5701-clone-local.sh
+13
@@ -144,4 +144,17 @@ test_expect_success 'clone empty repository, and then push should not segfault.'
144
test_must_fail git push)
145
'
146
147
+test_expect_success 'cloning non-existent directory fails' '
148
+ cd "$D" &&
149
+ rm -rf does-not-exist &&
150
+ test_must_fail git clone does-not-exist
151
+'
152
+
153
+test_expect_success 'cloning non-git directory fails' '
154
+ cd "$D" &&
155
+ rm -rf not-a-git-repo not-a-git-repo-clone &&
156
+ mkdir not-a-git-repo &&
157
+ test_must_fail git clone not-a-git-repo not-a-git-repo-clone
158
+'
159
+
160
test_done