Skip to content

Commit 367844e

Browse files
ffyuandagitster
authored andcommitted
t7002: add tests for moving out-of-cone file/directory
Add corresponding tests to test following situations: We do not have sufficient coverage of moving files outside of a sparse-checkout cone. Create new tests covering this behavior, keeping in mind that the user can include --sparse (or not), move a file or directory, and the destination can already exist in the index (in this case user can use --force to overwrite existing entry). Helped-by: Victoria Dye <[email protected]> Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Shaoxuan Yuan <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4a4b31 commit 367844e

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

t/t7002-mv-sparse-checkout.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ test_description='git mv in sparse working trees'
44

55
. ./test-lib.sh
66

7+
setup_sparse_checkout () {
8+
mkdir folder1 &&
9+
touch folder1/file1 &&
10+
git add folder1 &&
11+
git sparse-checkout set --cone sub
12+
}
13+
14+
cleanup_sparse_checkout () {
15+
git sparse-checkout disable &&
16+
git reset --hard
17+
}
18+
719
test_expect_success 'setup' "
820
mkdir -p sub/dir sub/dir2 &&
921
touch a b c sub/d sub/dir/e sub/dir2/e &&
@@ -196,6 +208,7 @@ test_expect_success 'can move files to non-sparse dir' '
196208
'
197209

198210
test_expect_success 'refuse to move file to non-skip-worktree sparse path' '
211+
test_when_finished "cleanup_sparse_checkout" &&
199212
git reset --hard &&
200213
git sparse-checkout init --no-cone &&
201214
git sparse-checkout set a !/x y/ !x/y/z &&
@@ -206,4 +219,75 @@ test_expect_success 'refuse to move file to non-skip-worktree sparse path' '
206219
test_cmp expect stderr
207220
'
208221

222+
test_expect_failure 'refuse to move out-of-cone directory without --sparse' '
223+
test_when_finished "cleanup_sparse_checkout" &&
224+
setup_sparse_checkout &&
225+
226+
test_must_fail git mv folder1 sub 2>stderr &&
227+
cat sparse_error_header >expect &&
228+
echo folder1/file1 >>expect &&
229+
cat sparse_hint >>expect &&
230+
test_cmp expect stderr
231+
'
232+
233+
test_expect_failure 'can move out-of-cone directory with --sparse' '
234+
test_when_finished "cleanup_sparse_checkout" &&
235+
setup_sparse_checkout &&
236+
237+
git mv --sparse folder1 sub 2>stderr &&
238+
test_must_be_empty stderr &&
239+
240+
test_path_is_dir sub/folder1 &&
241+
test_path_is_file sub/folder1/file1
242+
'
243+
244+
test_expect_failure 'refuse to move out-of-cone file without --sparse' '
245+
test_when_finished "cleanup_sparse_checkout" &&
246+
setup_sparse_checkout &&
247+
248+
test_must_fail git mv folder1/file1 sub 2>stderr &&
249+
cat sparse_error_header >expect &&
250+
echo folder1/file1 >>expect &&
251+
cat sparse_hint >>expect &&
252+
test_cmp expect stderr
253+
'
254+
255+
test_expect_failure 'can move out-of-cone file with --sparse' '
256+
test_when_finished "cleanup_sparse_checkout" &&
257+
setup_sparse_checkout &&
258+
259+
git mv --sparse folder1/file1 sub 2>stderr &&
260+
test_must_be_empty stderr &&
261+
262+
test_path_is_file sub/file1
263+
'
264+
265+
test_expect_failure 'refuse to move sparse file to existing destination' '
266+
test_when_finished "cleanup_sparse_checkout" &&
267+
mkdir folder1 &&
268+
touch folder1/file1 &&
269+
touch sub/file1 &&
270+
git add folder1 sub/file1 &&
271+
git sparse-checkout set --cone sub &&
272+
273+
test_must_fail git mv --sparse folder1/file1 sub 2>stderr &&
274+
echo "fatal: destination exists, source=folder1/file1, destination=sub/file1" >expect &&
275+
test_cmp expect stderr
276+
'
277+
278+
test_expect_failure 'move sparse file to existing destination with --force and --sparse' '
279+
test_when_finished "cleanup_sparse_checkout" &&
280+
mkdir folder1 &&
281+
touch folder1/file1 &&
282+
touch sub/file1 &&
283+
echo "overwrite" >folder1/file1 &&
284+
git add folder1 sub/file1 &&
285+
git sparse-checkout set --cone sub &&
286+
287+
git mv --sparse --force folder1/file1 sub 2>stderr &&
288+
test_must_be_empty stderr &&
289+
echo "overwrite" >expect &&
290+
test_cmp expect sub/file1
291+
'
292+
209293
test_done

0 commit comments

Comments
 (0)