Skip to content

Commit

Permalink
clone: die when trying to clone missing local path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 18, 2011
1 parent 7ed863a commit a902618
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (path)
repo = xstrdup(make_nonrelative_path(repo_name));
else if (!strchr(repo_name, ':'))
repo = xstrdup(make_absolute_path(repo_name));
die("repository '%s' does not exist", repo_name);
else
repo = repo_name;
is_local = path && !is_bundle;
Expand Down
13 changes: 13 additions & 0 deletions t/t5701-clone-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,17 @@ test_expect_success 'clone empty repository, and then push should not segfault.'
test_must_fail git push)
'

test_expect_success 'cloning non-existent directory fails' '
cd "$D" &&
rm -rf does-not-exist &&
test_must_fail git clone does-not-exist
'

test_expect_success 'cloning non-git directory fails' '
cd "$D" &&
rm -rf not-a-git-repo not-a-git-repo-clone &&
mkdir not-a-git-repo &&
test_must_fail git clone not-a-git-repo not-a-git-repo-clone
'

test_done

0 comments on commit a902618

Please sign in to comment.