From: Max Kirillov Date: Sun, 30 Nov 2014 08:24:58 +0000 (+0700) Subject: checkout: do not fail if target is an empty directory X-Git-Tag: v2.5.0-rc0~143^2~8 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ee4fb8435e2186323c6a91d26d1572da12b5d033 checkout: do not fail if target is an empty directory 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 Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff --git a/builtin/checkout.c b/builtin/checkout.c index 8c5276cf44..953b76370b 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -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); diff --git a/t/t2025-checkout-to.sh b/t/t2025-checkout-to.sh index eddd3251f1..915b506b6c 100755 --- a/t/t2025-checkout-to.sh +++ b/t/t2025-checkout-to.sh @@ -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 &&