Add corresponding tests to test following situations: * 'refuse to move out-of-cone directory without --sparse' * 'can move out-of-cone directory with --sparse' * 'refuse to move out-of-cone file without --sparse' * 'can move out-of-cone file with --sparse' * 'refuse to move sparse file to existing destination' * 'move sparse file to existing destination with --force and --sparse' Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@xxxxxxxxx> --- t/t7002-mv-sparse-checkout.sh | 98 +++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 1d3d2aca21..963cb512e2 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -206,4 +206,102 @@ test_expect_success 'refuse to move file to non-skip-worktree sparse path' ' test_cmp expect stderr ' +test_expect_failure 'refuse to move out-of-cone directory without --sparse' ' + git sparse-checkout disable && + git reset --hard && + mkdir folder1 && + touch folder1/file1 && + git add folder1 && + git sparse-checkout init --cone && + git sparse-checkout set sub && + + test_must_fail git mv folder1 sub 2>stderr && + cat sparse_error_header >expect && + echo folder1/file1 >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +test_expect_failure 'can move out-of-cone directory with --sparse' ' + git sparse-checkout disable && + git reset --hard && + mkdir folder1 && + touch folder1/file1 && + git add folder1 && + git sparse-checkout init --cone && + git sparse-checkout set sub && + + git mv --sparse folder1 sub 1>actual 2>stderr && + test_must_be_empty stderr && + + git sparse-checkout reapply && + test_path_is_dir sub/folder1 && + test_path_is_file sub/folder1/file1 +' + +test_expect_failure 'refuse to move out-of-cone file without --sparse' ' + git sparse-checkout disable && + git reset --hard && + mkdir folder1 && + touch folder1/file1 && + git add folder1 && + git sparse-checkout init --cone && + git sparse-checkout set sub && + + test_must_fail git mv folder1/file1 sub 2>stderr && + cat sparse_error_header >expect && + echo folder1/file1 >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +test_expect_failure 'can move out-of-cone file with --sparse' ' + git sparse-checkout disable && + git reset --hard && + mkdir folder1 && + touch folder1/file1 && + git add folder1 && + git sparse-checkout init --cone && + git sparse-checkout set sub && + + git mv --sparse folder1/file1 sub 1>actual 2>stderr && + test_must_be_empty stderr && + + git sparse-checkout reapply && + ! test_path_is_dir sub/folder1 && + test_path_is_file sub/file1 +' + +test_expect_failure 'refuse to move sparse file to existing destination' ' + git sparse-checkout disable && + git reset --hard && + mkdir folder1 && + touch folder1/file1 && + touch sub/file1 && + git add folder1 sub/file1 && + git sparse-checkout init --cone && + git sparse-checkout set sub && + + test_must_fail git mv --sparse folder1/file1 sub 2>stderr && + echo "fatal: destination exists, source=folder1/file1, destination=sub/file1" >expect && + test_cmp expect stderr +' + +test_expect_failure 'move sparse file to existing destination with --force and --sparse' ' + git sparse-checkout disable && + git reset --hard && + mkdir folder1 && + touch folder1/file1 && + touch sub/file1 && + echo "overwrite" >folder1/file1 && + git add folder1 sub/file1 && + git sparse-checkout init --cone && + git sparse-checkout set sub && + + git mv --sparse --force folder1/file1 sub 2>stderr && + test_must_be_empty stderr && + echo "overwrite" >expect && + test_cmp expect sub/file1 +' + test_done -- 2.35.1