Skip to content

Commit

Permalink
checkout: do not fail if target is an empty directory
Browse files Browse the repository at this point in the history
Non-recursive checkout creates empty directpries in place of submodules.
If then I try to "checkout --to" submodules there, it refuses to do so,
because directory already exists.

Fix by allowing checking out to empty directory. Add test and modify the
existing one so that it uses non-empty directory.

Signed-off-by: Max Kirillov <max@max630.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Max Kirillov authored and Junio C Hamano committed Dec 1, 2014
1 parent ad35f61 commit ee4fb84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ static int prepare_linked_checkout(const struct checkout_opts *opts,

if (!new->commit)
die(_("no branch specified"));
if (file_exists(path))
if (file_exists(path) && !is_empty_dir(path))
die(_("'%s' already exists"), path);

len = strlen(path);
Expand Down
7 changes: 6 additions & 1 deletion t/t2025-checkout-to.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ test_expect_success 'checkout --to not updating paths' '
'

test_expect_success 'checkout --to an existing worktree' '
mkdir existing &&
mkdir -p existing/subtree &&
test_must_fail git checkout --detach --to existing master
'

test_expect_success 'checkout --to an existing empty worktree' '
mkdir existing_empty &&
git checkout --detach --to existing_empty master
'

test_expect_success 'checkout --to refuses to checkout locked branch' '
test_must_fail git checkout --to zere master &&
! test -d zere &&
Expand Down

0 comments on commit ee4fb84

Please sign in to comment.