提交 ee4fb843 编写于 作者: M Max Kirillov 提交者: Junio C Hamano

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: NMax Kirillov <max@max630.net>
Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 ad35f615
......@@ -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);
......
......@@ -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 &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册