t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t7002-mv-sparse-checkout.sh
blob57969ce805a54839fe18bfb3bea63faacb1dd85a
1 #!/bin/sh
3 test_description='git mv in sparse working trees'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 setup_sparse_checkout () {
9 mkdir folder1 &&
10 touch folder1/file1 &&
11 git add folder1 &&
12 git sparse-checkout set --cone sub
15 cleanup_sparse_checkout () {
16 git sparse-checkout disable &&
17 git reset --hard
20 test_expect_success 'setup' "
21 mkdir -p sub/dir sub/dir2 &&
22 touch a b c sub/d sub/dir/e sub/dir2/e &&
23 git add -A &&
24 git commit -m files &&
26 cat >sparse_error_header <<-EOF &&
27 The following paths and/or pathspecs matched paths that exist
28 outside of your sparse-checkout definition, so will not be
29 updated in the index:
30 EOF
32 cat >sparse_hint <<-EOF &&
33 hint: If you intend to update such entries, try one of the following:
34 hint: * Use the --sparse option.
35 hint: * Disable or modify the sparsity rules.
36 hint: Disable this message with \"git config advice.updateSparsePath false\"
37 EOF
39 cat >dirty_error_header <<-EOF &&
40 The following paths have been moved outside the
41 sparse-checkout definition but are not sparse due to local
42 modifications.
43 EOF
45 cat >dirty_hint <<-EOF
46 hint: To correct the sparsity of these paths, do the following:
47 hint: * Use \"git add --sparse <paths>\" to update the index
48 hint: * Use \"git sparse-checkout reapply\" to apply the sparsity rules
49 hint: Disable this message with \"git config advice.updateSparsePath false\"
50 EOF
53 test_expect_success 'mv refuses to move sparse-to-sparse' '
54 test_when_finished rm -f e &&
55 git reset --hard &&
56 git sparse-checkout set --no-cone a &&
57 touch b &&
58 test_must_fail git mv b e 2>stderr &&
59 cat sparse_error_header >expect &&
60 echo b >>expect &&
61 echo e >>expect &&
62 cat sparse_hint >>expect &&
63 test_cmp expect stderr &&
64 git mv --sparse b e 2>stderr &&
65 test_must_be_empty stderr
68 test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
69 test_when_finished rm -f b c e &&
70 git reset --hard &&
71 git sparse-checkout set a &&
73 # tracked-to-untracked
74 touch b &&
75 git mv -k b e 2>stderr &&
76 test_path_exists b &&
77 test_path_is_missing e &&
78 cat sparse_error_header >expect &&
79 echo b >>expect &&
80 echo e >>expect &&
81 cat sparse_hint >>expect &&
82 test_cmp expect stderr &&
84 git mv --sparse b e 2>stderr &&
85 test_must_be_empty stderr &&
86 test_path_is_missing b &&
87 test_path_exists e &&
89 # tracked-to-tracked
90 git reset --hard &&
91 touch b &&
92 git mv -k b c 2>stderr &&
93 test_path_exists b &&
94 test_path_is_missing c &&
95 cat sparse_error_header >expect &&
96 echo b >>expect &&
97 echo c >>expect &&
98 cat sparse_hint >>expect &&
99 test_cmp expect stderr &&
101 git mv --sparse b c 2>stderr &&
102 test_must_be_empty stderr &&
103 test_path_is_missing b &&
104 test_path_exists c
107 test_expect_success 'mv refuses to move non-sparse-to-sparse' '
108 test_when_finished rm -f b c e &&
109 git reset --hard &&
110 git sparse-checkout set a &&
112 # tracked-to-untracked
113 test_must_fail git mv a e 2>stderr &&
114 test_path_exists a &&
115 test_path_is_missing e &&
116 cat sparse_error_header >expect &&
117 echo e >>expect &&
118 cat sparse_hint >>expect &&
119 test_cmp expect stderr &&
120 git mv --sparse a e 2>stderr &&
121 test_must_be_empty stderr &&
122 test_path_is_missing a &&
123 test_path_exists e &&
125 # tracked-to-tracked
126 rm e &&
127 git reset --hard &&
128 test_must_fail git mv a c 2>stderr &&
129 test_path_exists a &&
130 test_path_is_missing c &&
131 cat sparse_error_header >expect &&
132 echo c >>expect &&
133 cat sparse_hint >>expect &&
134 test_cmp expect stderr &&
135 git mv --sparse a c 2>stderr &&
136 test_must_be_empty stderr &&
137 test_path_is_missing a &&
138 test_path_exists c
141 test_expect_success 'mv refuses to move sparse-to-non-sparse' '
142 test_when_finished rm -f b c e &&
143 git reset --hard &&
144 git sparse-checkout set a e &&
146 # tracked-to-untracked
147 touch b &&
148 test_must_fail git mv b e 2>stderr &&
149 cat sparse_error_header >expect &&
150 echo b >>expect &&
151 cat sparse_hint >>expect &&
152 test_cmp expect stderr &&
153 git mv --sparse b e 2>stderr &&
154 test_must_be_empty stderr
157 test_expect_success 'recursive mv refuses to move (possible) sparse' '
158 test_when_finished rm -rf b c e sub2 &&
159 git reset --hard &&
160 # Without cone mode, "sub" and "sub2" do not match
161 git sparse-checkout set sub/dir sub2/dir &&
163 # Add contained contents to ensure we avoid non-existence errors
164 mkdir sub/dir2 &&
165 touch sub/d sub/dir2/e &&
167 test_must_fail git mv sub sub2 2>stderr &&
168 cat sparse_error_header >expect &&
169 cat >>expect <<-\EOF &&
170 sub/d
171 sub2/d
172 sub/dir2/e
173 sub2/dir2/e
175 cat sparse_hint >>expect &&
176 test_cmp expect stderr &&
177 git mv --sparse sub sub2 2>stderr &&
178 test_must_be_empty stderr &&
179 git commit -m "moved sub to sub2" &&
180 git rev-parse HEAD~1:sub >expect &&
181 git rev-parse HEAD:sub2 >actual &&
182 test_cmp expect actual &&
183 git reset --hard HEAD~1
186 test_expect_success 'recursive mv refuses to move sparse' '
187 git reset --hard &&
188 # Use cone mode so "sub/" matches the sparse-checkout patterns
189 git sparse-checkout init --cone &&
190 git sparse-checkout set sub/dir sub2/dir &&
192 # Add contained contents to ensure we avoid non-existence errors
193 mkdir sub/dir2 &&
194 touch sub/dir2/e &&
196 test_must_fail git mv sub sub2 2>stderr &&
197 cat sparse_error_header >expect &&
198 cat >>expect <<-\EOF &&
199 sub/dir2/e
200 sub2/dir2/e
202 cat sparse_hint >>expect &&
203 test_cmp expect stderr &&
204 git mv --sparse sub sub2 2>stderr &&
205 test_must_be_empty stderr &&
206 git commit -m "moved sub to sub2" &&
207 git rev-parse HEAD~1:sub >expect &&
208 git rev-parse HEAD:sub2 >actual &&
209 test_cmp expect actual &&
210 git reset --hard HEAD~1
213 test_expect_success 'can move files to non-sparse dir' '
214 git reset --hard &&
215 git sparse-checkout init --no-cone &&
216 git sparse-checkout set a b c w !/x y/ &&
217 mkdir -p w x/y &&
219 git mv a w/new-a 2>stderr &&
220 git mv b x/y/new-b 2>stderr &&
221 test_must_be_empty stderr
224 test_expect_success 'refuse to move file to non-skip-worktree sparse path' '
225 test_when_finished "cleanup_sparse_checkout" &&
226 git reset --hard &&
227 git sparse-checkout init --no-cone &&
228 git sparse-checkout set a !/x y/ !x/y/z &&
229 mkdir -p x/y/z &&
231 test_must_fail git mv a x/y/z/new-a 2>stderr &&
232 echo x/y/z/new-a | cat sparse_error_header - sparse_hint >expect &&
233 test_cmp expect stderr
236 test_expect_success 'refuse to move out-of-cone directory without --sparse' '
237 test_when_finished "cleanup_sparse_checkout" &&
238 setup_sparse_checkout &&
240 test_must_fail git mv folder1 sub 2>stderr &&
241 cat sparse_error_header >expect &&
242 echo folder1/file1 >>expect &&
243 cat sparse_hint >>expect &&
244 test_cmp expect stderr
247 test_expect_success 'can move out-of-cone directory with --sparse' '
248 test_when_finished "cleanup_sparse_checkout" &&
249 setup_sparse_checkout &&
251 git mv --sparse folder1 sub 2>stderr &&
252 test_must_be_empty stderr &&
254 test_path_is_dir sub/folder1 &&
255 test_path_is_file sub/folder1/file1
258 test_expect_success 'refuse to move out-of-cone file without --sparse' '
259 test_when_finished "cleanup_sparse_checkout" &&
260 setup_sparse_checkout &&
262 test_must_fail git mv folder1/file1 sub 2>stderr &&
263 cat sparse_error_header >expect &&
264 echo folder1/file1 >>expect &&
265 cat sparse_hint >>expect &&
266 test_cmp expect stderr
269 test_expect_success 'can move out-of-cone file with --sparse' '
270 test_when_finished "cleanup_sparse_checkout" &&
271 setup_sparse_checkout &&
273 git mv --sparse folder1/file1 sub 2>stderr &&
274 test_must_be_empty stderr &&
276 test_path_is_file sub/file1
279 test_expect_success 'refuse to move sparse file to existing destination' '
280 test_when_finished "cleanup_sparse_checkout" &&
281 mkdir folder1 &&
282 touch folder1/file1 &&
283 touch sub/file1 &&
284 git add folder1 sub/file1 &&
285 git sparse-checkout set --cone sub &&
287 test_must_fail git mv --sparse folder1/file1 sub 2>stderr &&
288 echo "fatal: destination exists, source=folder1/file1, destination=sub/file1" >expect &&
289 test_cmp expect stderr
292 test_expect_success 'move sparse file to existing destination with --force and --sparse' '
293 test_when_finished "cleanup_sparse_checkout" &&
294 mkdir folder1 &&
295 touch folder1/file1 &&
296 touch sub/file1 &&
297 echo "overwrite" >folder1/file1 &&
298 git add folder1 sub/file1 &&
299 git sparse-checkout set --cone sub &&
301 git mv --sparse --force folder1/file1 sub 2>stderr &&
302 test_must_be_empty stderr &&
303 echo "overwrite" >expect &&
304 test_cmp expect sub/file1
307 test_expect_success 'move clean path from in-cone to out-of-cone' '
308 test_when_finished "cleanup_sparse_checkout" &&
309 setup_sparse_checkout &&
311 test_must_fail git mv sub/d folder1 2>stderr &&
312 cat sparse_error_header >expect &&
313 echo "folder1/d" >>expect &&
314 cat sparse_hint >>expect &&
315 test_cmp expect stderr &&
317 git mv --sparse sub/d folder1 2>stderr &&
318 test_must_be_empty stderr &&
320 test_path_is_missing sub/d &&
321 test_path_is_missing folder1/d &&
322 git ls-files -t >actual &&
323 ! grep "^H sub/d\$" actual &&
324 grep "S folder1/d" actual
327 test_expect_success 'move clean path from in-cone to out-of-cone overwrite' '
328 test_when_finished "cleanup_sparse_checkout" &&
329 setup_sparse_checkout &&
330 echo "sub/file1 overwrite" >sub/file1 &&
331 git add sub/file1 &&
333 test_must_fail git mv sub/file1 folder1 2>stderr &&
334 cat sparse_error_header >expect &&
335 echo "folder1/file1" >>expect &&
336 cat sparse_hint >>expect &&
337 test_cmp expect stderr &&
339 test_must_fail git mv --sparse sub/file1 folder1 2>stderr &&
340 echo "fatal: destination exists in the index, source=sub/file1, destination=folder1/file1" \
341 >expect &&
342 test_cmp expect stderr &&
344 git mv --sparse -f sub/file1 folder1 2>stderr &&
345 test_must_be_empty stderr &&
347 test_path_is_missing sub/file1 &&
348 test_path_is_missing folder1/file1 &&
349 git ls-files -t >actual &&
350 ! grep "H sub/file1" actual &&
351 grep "S folder1/file1" actual &&
353 # compare file content before move and after move
354 echo "sub/file1 overwrite" >expect &&
355 git ls-files -s -- folder1/file1 | awk "{print \$2}" >oid &&
356 git cat-file blob $(cat oid) >actual &&
357 test_cmp expect actual
360 # This test is testing the same behavior as the
361 # "move clean path from in-cone to out-of-cone overwrite" above.
362 # The only difference is the <destination> changes from "folder1" to "folder1/file1"
363 test_expect_success 'move clean path from in-cone to out-of-cone file overwrite' '
364 test_when_finished "cleanup_sparse_checkout" &&
365 setup_sparse_checkout &&
366 echo "sub/file1 overwrite" >sub/file1 &&
367 git add sub/file1 &&
369 test_must_fail git mv sub/file1 folder1/file1 2>stderr &&
370 cat sparse_error_header >expect &&
371 echo "folder1/file1" >>expect &&
372 cat sparse_hint >>expect &&
373 test_cmp expect stderr &&
375 test_must_fail git mv --sparse sub/file1 folder1/file1 2>stderr &&
376 echo "fatal: destination exists in the index, source=sub/file1, destination=folder1/file1" \
377 >expect &&
378 test_cmp expect stderr &&
380 git mv --sparse -f sub/file1 folder1/file1 2>stderr &&
381 test_must_be_empty stderr &&
383 test_path_is_missing sub/file1 &&
384 test_path_is_missing folder1/file1 &&
385 git ls-files -t >actual &&
386 ! grep "H sub/file1" actual &&
387 grep "S folder1/file1" actual &&
389 # compare file content before move and after move
390 echo "sub/file1 overwrite" >expect &&
391 git ls-files -s -- folder1/file1 | awk "{print \$2}" >oid &&
392 git cat-file blob $(cat oid) >actual &&
393 test_cmp expect actual
396 test_expect_success 'move directory with one of the files overwrite' '
397 test_when_finished "cleanup_sparse_checkout" &&
398 mkdir -p folder1/dir &&
399 touch folder1/dir/file1 &&
400 git add folder1 &&
401 git sparse-checkout set --cone sub &&
403 echo test >sub/dir/file1 &&
404 git add sub/dir/file1 &&
406 test_must_fail git mv sub/dir folder1 2>stderr &&
407 cat sparse_error_header >expect &&
408 echo "folder1/dir/e" >>expect &&
409 echo "folder1/dir/file1" >>expect &&
410 cat sparse_hint >>expect &&
411 test_cmp expect stderr &&
413 test_must_fail git mv --sparse sub/dir folder1 2>stderr &&
414 echo "fatal: destination exists in the index, source=sub/dir/file1, destination=folder1/dir/file1" \
415 >expect &&
416 test_cmp expect stderr &&
418 git mv --sparse -f sub/dir folder1 2>stderr &&
419 test_must_be_empty stderr &&
421 test_path_is_missing sub/dir/file1 &&
422 test_path_is_missing sub/dir/e &&
423 test_path_is_missing folder1/file1 &&
424 git ls-files -t >actual &&
425 ! grep "H sub/dir/file1" actual &&
426 ! grep "H sub/dir/e" actual &&
427 grep "S folder1/dir/file1" actual &&
429 # compare file content before move and after move
430 echo test >expect &&
431 git ls-files -s -- folder1/dir/file1 | awk "{print \$2}" >oid &&
432 git cat-file blob $(cat oid) >actual &&
433 test_cmp expect actual
436 test_expect_success 'move dirty path from in-cone to out-of-cone' '
437 test_when_finished "cleanup_sparse_checkout" &&
438 setup_sparse_checkout &&
439 echo "modified" >>sub/d &&
441 test_must_fail git mv sub/d folder1 2>stderr &&
442 cat sparse_error_header >expect &&
443 echo "folder1/d" >>expect &&
444 cat sparse_hint >>expect &&
445 test_cmp expect stderr &&
447 git mv --sparse sub/d folder1 2>stderr &&
448 cat dirty_error_header >expect &&
449 echo "folder1/d" >>expect &&
450 cat dirty_hint >>expect &&
451 test_cmp expect stderr &&
453 test_path_is_missing sub/d &&
454 test_path_is_file folder1/d &&
455 git ls-files -t >actual &&
456 ! grep "^H sub/d\$" actual &&
457 grep "H folder1/d" actual
460 test_expect_success 'move dir from in-cone to out-of-cone' '
461 test_when_finished "cleanup_sparse_checkout" &&
462 setup_sparse_checkout &&
463 mkdir sub/dir/deep &&
465 test_must_fail git mv sub/dir folder1 2>stderr &&
466 cat sparse_error_header >expect &&
467 echo "folder1/dir/e" >>expect &&
468 cat sparse_hint >>expect &&
469 test_cmp expect stderr &&
471 git mv --sparse sub/dir folder1 2>stderr &&
472 test_must_be_empty stderr &&
474 test_path_is_missing sub/dir &&
475 test_path_is_missing folder1 &&
476 git ls-files -t >actual &&
477 ! grep "H sub/dir/e" actual &&
478 grep "S folder1/dir/e" actual
481 test_expect_success 'move partially-dirty dir from in-cone to out-of-cone' '
482 test_when_finished "cleanup_sparse_checkout" &&
483 setup_sparse_checkout &&
484 mkdir sub/dir/deep &&
485 touch sub/dir/e2 sub/dir/e3 &&
486 git add sub/dir/e2 sub/dir/e3 &&
487 echo "modified" >>sub/dir/e2 &&
488 echo "modified" >>sub/dir/e3 &&
490 test_must_fail git mv sub/dir folder1 2>stderr &&
491 cat sparse_error_header >expect &&
492 echo "folder1/dir/e" >>expect &&
493 echo "folder1/dir/e2" >>expect &&
494 echo "folder1/dir/e3" >>expect &&
495 cat sparse_hint >>expect &&
496 test_cmp expect stderr &&
498 git mv --sparse sub/dir folder1 2>stderr &&
499 cat dirty_error_header >expect &&
500 echo "folder1/dir/e2" >>expect &&
501 echo "folder1/dir/e3" >>expect &&
502 cat dirty_hint >>expect &&
503 test_cmp expect stderr &&
505 test_path_is_missing sub/dir &&
506 test_path_is_missing folder1/dir/e &&
507 test_path_is_file folder1/dir/e2 &&
508 test_path_is_file folder1/dir/e3 &&
509 git ls-files -t >actual &&
510 ! grep "H sub/dir/e" actual &&
511 ! grep "H sub/dir/e2" actual &&
512 ! grep "H sub/dir/e3" actual &&
513 grep "S folder1/dir/e" actual &&
514 grep "H folder1/dir/e2" actual &&
515 grep "H folder1/dir/e3" actual
518 test_done