mv: check overwrite for in-to-out move
Add checking logic for overwriting when moving from in-cone to out-of-cone. It is the index version of the original overwrite logic. Helped-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5efd533ed8
commit
da6fe05b3d
12
builtin/mv.c
12
builtin/mv.c
@ -376,6 +376,18 @@ dir_check:
|
|||||||
goto act_on_entry;
|
goto act_on_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ignore_sparse &&
|
||||||
|
(dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&
|
||||||
|
index_entry_exists(&the_index, dst, strlen(dst))) {
|
||||||
|
bad = _("destination exists in the index");
|
||||||
|
if (force) {
|
||||||
|
if (verbose)
|
||||||
|
warning(_("overwriting '%s'"), dst);
|
||||||
|
bad = NULL;
|
||||||
|
} else {
|
||||||
|
goto act_on_entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* We check if the paths are in the sparse-checkout
|
* We check if the paths are in the sparse-checkout
|
||||||
* definition as a very final check, since that
|
* definition as a very final check, since that
|
||||||
|
@ -323,7 +323,7 @@ test_expect_success 'move clean path from in-cone to out-of-cone' '
|
|||||||
grep "S folder1/d" actual
|
grep "S folder1/d" actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'move clean path from in-cone to out-of-cone overwrite' '
|
test_expect_success 'move clean path from in-cone to out-of-cone overwrite' '
|
||||||
test_when_finished "cleanup_sparse_checkout" &&
|
test_when_finished "cleanup_sparse_checkout" &&
|
||||||
setup_sparse_checkout &&
|
setup_sparse_checkout &&
|
||||||
echo "sub/file1 overwrite" >sub/file1 &&
|
echo "sub/file1 overwrite" >sub/file1 &&
|
||||||
@ -359,7 +359,7 @@ test_expect_failure 'move clean path from in-cone to out-of-cone overwrite' '
|
|||||||
# This test is testing the same behavior as the
|
# This test is testing the same behavior as the
|
||||||
# "move clean path from in-cone to out-of-cone overwrite" above.
|
# "move clean path from in-cone to out-of-cone overwrite" above.
|
||||||
# The only difference is the <destination> changes from "folder1" to "folder1/file1"
|
# The only difference is the <destination> changes from "folder1" to "folder1/file1"
|
||||||
test_expect_failure 'move clean path from in-cone to out-of-cone file overwrite' '
|
test_expect_success 'move clean path from in-cone to out-of-cone file overwrite' '
|
||||||
test_when_finished "cleanup_sparse_checkout" &&
|
test_when_finished "cleanup_sparse_checkout" &&
|
||||||
setup_sparse_checkout &&
|
setup_sparse_checkout &&
|
||||||
echo "sub/file1 overwrite" >sub/file1 &&
|
echo "sub/file1 overwrite" >sub/file1 &&
|
||||||
@ -392,7 +392,7 @@ test_expect_failure 'move clean path from in-cone to out-of-cone file overwrite'
|
|||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'move directory with one of the files overwrite' '
|
test_expect_success 'move directory with one of the files overwrite' '
|
||||||
test_when_finished "cleanup_sparse_checkout" &&
|
test_when_finished "cleanup_sparse_checkout" &&
|
||||||
mkdir -p folder1/dir &&
|
mkdir -p folder1/dir &&
|
||||||
touch folder1/dir/file1 &&
|
touch folder1/dir/file1 &&
|
||||||
|
Loading…
Reference in New Issue
Block a user