]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1091-sparse-checkout-builtin.sh
repo-settings: rename the traditional default fetch.negotiationAlgorithm
[thirdparty/git.git] / t / t1091-sparse-checkout-builtin.sh
1 #!/bin/sh
2
3 test_description='sparse checkout builtin tests'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 list_files() {
11 # Do not replace this with 'ls "$1"', as "ls" with BSD-lineage
12 # enables "-A" by default for root and ends up including ".git" and
13 # such in its output. (Note, though, that running the test suite as
14 # root is generally not recommended.)
15 (cd "$1" && printf '%s\n' *)
16 }
17
18 check_files() {
19 list_files "$1" >actual &&
20 shift &&
21 printf "%s\n" $@ >expect &&
22 test_cmp expect actual
23 }
24
25 test_expect_success 'setup' '
26 git init repo &&
27 (
28 cd repo &&
29 echo "initial" >a &&
30 mkdir folder1 folder2 deep &&
31 mkdir deep/deeper1 deep/deeper2 &&
32 mkdir deep/deeper1/deepest &&
33 cp a folder1 &&
34 cp a folder2 &&
35 cp a deep &&
36 cp a deep/deeper1 &&
37 cp a deep/deeper2 &&
38 cp a deep/deeper1/deepest &&
39 git add . &&
40 git commit -m "initial commit"
41 )
42 '
43
44 test_expect_success 'git sparse-checkout list (empty)' '
45 git -C repo sparse-checkout list >list 2>err &&
46 test_must_be_empty list &&
47 test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err
48 '
49
50 test_expect_success 'git sparse-checkout list (populated)' '
51 test_when_finished rm -f repo/.git/info/sparse-checkout &&
52 cat >repo/.git/info/sparse-checkout <<-\EOF &&
53 /folder1/*
54 /deep/
55 **/a
56 !*bin*
57 EOF
58 cp repo/.git/info/sparse-checkout expect &&
59 git -C repo sparse-checkout list >list &&
60 test_cmp expect list
61 '
62
63 test_expect_success 'git sparse-checkout init' '
64 git -C repo sparse-checkout init &&
65 cat >expect <<-\EOF &&
66 /*
67 !/*/
68 EOF
69 test_cmp expect repo/.git/info/sparse-checkout &&
70 test_cmp_config -C repo true core.sparsecheckout &&
71 check_files repo a
72 '
73
74 test_expect_success 'git sparse-checkout list after init' '
75 git -C repo sparse-checkout list >actual &&
76 cat >expect <<-\EOF &&
77 /*
78 !/*/
79 EOF
80 test_cmp expect actual
81 '
82
83 test_expect_success 'init with existing sparse-checkout' '
84 echo "*folder*" >> repo/.git/info/sparse-checkout &&
85 git -C repo sparse-checkout init &&
86 cat >expect <<-\EOF &&
87 /*
88 !/*/
89 *folder*
90 EOF
91 test_cmp expect repo/.git/info/sparse-checkout &&
92 check_files repo a folder1 folder2
93 '
94
95 test_expect_success 'clone --sparse' '
96 git clone --sparse "file://$(pwd)/repo" clone &&
97 git -C clone sparse-checkout list >actual &&
98 cat >expect <<-\EOF &&
99 /*
100 !/*/
101 EOF
102 test_cmp expect actual &&
103 check_files clone a
104 '
105
106 test_expect_success 'interaction with clone --no-checkout (unborn index)' '
107 git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout &&
108 git -C clone_no_checkout sparse-checkout init --cone &&
109 git -C clone_no_checkout sparse-checkout set folder1 &&
110
111 git -C clone_no_checkout sparse-checkout list >actual &&
112 cat >expect <<-\EOF &&
113 folder1
114 EOF
115 test_cmp expect actual &&
116
117 # nothing checked out, expect "No such file or directory"
118 ! ls clone_no_checkout/* >actual &&
119 test_must_be_empty actual &&
120 test_path_is_missing clone_no_checkout/.git/index &&
121
122 # No branch is checked out until we manually switch to one
123 git -C clone_no_checkout switch main &&
124 test_path_is_file clone_no_checkout/.git/index &&
125 check_files clone_no_checkout a folder1
126 '
127
128 test_expect_success 'set enables config' '
129 git init empty-config &&
130 (
131 cd empty-config &&
132 test_commit test file &&
133 test_path_is_missing .git/config.worktree &&
134 git sparse-checkout set nothing &&
135 test_path_is_file .git/config.worktree &&
136 test_cmp_config true core.sparseCheckout
137 )
138 '
139
140 test_expect_success 'set sparse-checkout using builtin' '
141 git -C repo sparse-checkout set "/*" "!/*/" "*folder*" &&
142 cat >expect <<-\EOF &&
143 /*
144 !/*/
145 *folder*
146 EOF
147 git -C repo sparse-checkout list >actual &&
148 test_cmp expect actual &&
149 test_cmp expect repo/.git/info/sparse-checkout &&
150 check_files repo a folder1 folder2
151 '
152
153 test_expect_success 'set sparse-checkout using --stdin' '
154 cat >expect <<-\EOF &&
155 /*
156 !/*/
157 /folder1/
158 /folder2/
159 EOF
160 git -C repo sparse-checkout set --stdin <expect &&
161 git -C repo sparse-checkout list >actual &&
162 test_cmp expect actual &&
163 test_cmp expect repo/.git/info/sparse-checkout &&
164 check_files repo "a folder1 folder2"
165 '
166
167 test_expect_success 'add to sparse-checkout' '
168 cat repo/.git/info/sparse-checkout >expect &&
169 cat >add <<-\EOF &&
170 pattern1
171 /folder1/
172 pattern2
173 EOF
174 cat add >>expect &&
175 git -C repo sparse-checkout add --stdin <add &&
176 git -C repo sparse-checkout list >actual &&
177 test_cmp expect actual &&
178 test_cmp expect repo/.git/info/sparse-checkout &&
179 check_files repo "a folder1 folder2"
180 '
181
182 test_expect_success 'cone mode: match patterns' '
183 git -C repo config --worktree core.sparseCheckoutCone true &&
184 rm -rf repo/a repo/folder1 repo/folder2 &&
185 git -C repo read-tree -mu HEAD 2>err &&
186 test_i18ngrep ! "disabling cone patterns" err &&
187 git -C repo reset --hard &&
188 check_files repo a folder1 folder2
189 '
190
191 test_expect_success 'cone mode: warn on bad pattern' '
192 test_when_finished mv sparse-checkout repo/.git/info/ &&
193 cp repo/.git/info/sparse-checkout . &&
194 echo "!/deep/deeper/*" >>repo/.git/info/sparse-checkout &&
195 git -C repo read-tree -mu HEAD 2>err &&
196 test_i18ngrep "unrecognized negative pattern" err
197 '
198
199 test_expect_success 'sparse-checkout disable' '
200 test_when_finished rm -rf repo/.git/info/sparse-checkout &&
201 git -C repo sparse-checkout disable &&
202 test_path_is_file repo/.git/info/sparse-checkout &&
203 git -C repo config --list >config &&
204 test_must_fail git config core.sparseCheckout &&
205 check_files repo a deep folder1 folder2
206 '
207
208 test_expect_success 'sparse-index enabled and disabled' '
209 (
210 sane_unset GIT_TEST_SPLIT_INDEX &&
211 git -C repo update-index --no-split-index &&
212
213 git -C repo sparse-checkout init --cone --sparse-index &&
214 test_cmp_config -C repo true index.sparse &&
215 test-tool -C repo read-cache --table >cache &&
216 grep " tree " cache &&
217
218 git -C repo sparse-checkout disable &&
219 test-tool -C repo read-cache --table >cache &&
220 ! grep " tree " cache &&
221 git -C repo config --list >config &&
222 ! grep index.sparse config
223 )
224 '
225
226 test_expect_success 'cone mode: init and set' '
227 git -C repo sparse-checkout init --cone &&
228 git -C repo config --list >config &&
229 test_i18ngrep "core.sparsecheckoutcone=true" config &&
230 list_files repo >dir &&
231 echo a >expect &&
232 test_cmp expect dir &&
233 git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
234 test_must_be_empty err &&
235 check_files repo a deep &&
236 check_files repo/deep a deeper1 &&
237 check_files repo/deep/deeper1 a deepest &&
238 cat >expect <<-\EOF &&
239 /*
240 !/*/
241 /deep/
242 !/deep/*/
243 /deep/deeper1/
244 !/deep/deeper1/*/
245 /deep/deeper1/deepest/
246 EOF
247 test_cmp expect repo/.git/info/sparse-checkout &&
248 git -C repo sparse-checkout set --stdin 2>err <<-\EOF &&
249 folder1
250 folder2
251 EOF
252 test_must_be_empty err &&
253 check_files repo a folder1 folder2
254 '
255
256 test_expect_success 'cone mode: list' '
257 cat >expect <<-\EOF &&
258 folder1
259 folder2
260 EOF
261 git -C repo sparse-checkout set --stdin <expect &&
262 git -C repo sparse-checkout list >actual 2>err &&
263 test_must_be_empty err &&
264 test_cmp expect actual
265 '
266
267 test_expect_success 'cone mode: set with nested folders' '
268 git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&
269 test_line_count = 0 err &&
270 cat >expect <<-\EOF &&
271 /*
272 !/*/
273 /deep/
274 EOF
275 test_cmp repo/.git/info/sparse-checkout expect
276 '
277
278 test_expect_success 'cone mode: add independent path' '
279 git -C repo sparse-checkout set deep/deeper1 &&
280 git -C repo sparse-checkout add folder1 &&
281 cat >expect <<-\EOF &&
282 /*
283 !/*/
284 /deep/
285 !/deep/*/
286 /deep/deeper1/
287 /folder1/
288 EOF
289 test_cmp expect repo/.git/info/sparse-checkout &&
290 check_files repo a deep folder1
291 '
292
293 test_expect_success 'cone mode: add sibling path' '
294 git -C repo sparse-checkout set deep/deeper1 &&
295 git -C repo sparse-checkout add deep/deeper2 &&
296 cat >expect <<-\EOF &&
297 /*
298 !/*/
299 /deep/
300 !/deep/*/
301 /deep/deeper1/
302 /deep/deeper2/
303 EOF
304 test_cmp expect repo/.git/info/sparse-checkout &&
305 check_files repo a deep
306 '
307
308 test_expect_success 'cone mode: add parent path' '
309 git -C repo sparse-checkout set deep/deeper1 folder1 &&
310 git -C repo sparse-checkout add deep &&
311 cat >expect <<-\EOF &&
312 /*
313 !/*/
314 /deep/
315 /folder1/
316 EOF
317 test_cmp expect repo/.git/info/sparse-checkout &&
318 check_files repo a deep folder1
319 '
320
321 test_expect_success 'not-up-to-date does not block rest of sparsification' '
322 test_when_finished git -C repo sparse-checkout disable &&
323 test_when_finished git -C repo reset --hard &&
324 git -C repo sparse-checkout set deep &&
325
326 echo update >repo/deep/deeper2/a &&
327 cp repo/.git/info/sparse-checkout expect &&
328 test_write_lines "!/deep/*/" "/deep/deeper1/" >>expect &&
329
330 git -C repo sparse-checkout set deep/deeper1 2>err &&
331
332 test_i18ngrep "The following paths are not up to date" err &&
333 test_cmp expect repo/.git/info/sparse-checkout &&
334 check_files repo/deep a deeper1 deeper2 &&
335 check_files repo/deep/deeper1 a deepest &&
336 check_files repo/deep/deeper1/deepest a &&
337 check_files repo/deep/deeper2 a
338 '
339
340 test_expect_success 'revert to old sparse-checkout on empty update' '
341 git init empty-test &&
342 (
343 echo >file &&
344 git add file &&
345 git commit -m "test" &&
346 git sparse-checkout set nothing 2>err &&
347 test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err &&
348 test_i18ngrep ! ".git/index.lock" err &&
349 git sparse-checkout set file
350 )
351 '
352
353 test_expect_success 'fail when lock is taken' '
354 test_when_finished rm -rf repo/.git/info/sparse-checkout.lock &&
355 touch repo/.git/info/sparse-checkout.lock &&
356 test_must_fail git -C repo sparse-checkout set deep 2>err &&
357 test_i18ngrep "Unable to create .*\.lock" err
358 '
359
360 test_expect_success '.gitignore should not warn about cone mode' '
361 git -C repo config --worktree core.sparseCheckoutCone true &&
362 echo "**/bin/*" >repo/.gitignore &&
363 git -C repo reset --hard 2>err &&
364 test_i18ngrep ! "disabling cone patterns" err
365 '
366
367 test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' '
368 git clone repo dirty &&
369 echo dirty >dirty/folder1/a &&
370
371 git -C dirty sparse-checkout init 2>err &&
372 test_i18ngrep "warning.*The following paths are not up to date" err &&
373
374 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err &&
375 test_i18ngrep "warning.*The following paths are not up to date" err &&
376 test_path_is_file dirty/folder1/a &&
377
378 git -C dirty sparse-checkout disable 2>err &&
379 test_must_be_empty err &&
380
381 git -C dirty reset --hard &&
382 git -C dirty sparse-checkout init &&
383 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* &&
384 test_path_is_missing dirty/folder1/a &&
385 git -C dirty sparse-checkout disable &&
386 test_path_is_file dirty/folder1/a
387 '
388
389 test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged status' '
390 git clone repo unmerged &&
391
392 cat >input <<-EOF &&
393 0 $ZERO_OID folder1/a
394 100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1 folder1/a
395 EOF
396 git -C unmerged update-index --index-info <input &&
397
398 git -C unmerged sparse-checkout init 2>err &&
399 test_i18ngrep "warning.*The following paths are unmerged" err &&
400
401 git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err &&
402 test_i18ngrep "warning.*The following paths are unmerged" err &&
403 test_path_is_file dirty/folder1/a &&
404
405 git -C unmerged sparse-checkout disable 2>err &&
406 test_i18ngrep "warning.*The following paths are unmerged" err &&
407
408 git -C unmerged reset --hard &&
409 git -C unmerged sparse-checkout init &&
410 git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* &&
411 git -C unmerged sparse-checkout disable
412 '
413
414 test_expect_failure 'sparse-checkout reapply' '
415 git clone repo tweak &&
416
417 echo dirty >tweak/deep/deeper2/a &&
418
419 cat >input <<-EOF &&
420 0 $ZERO_OID folder1/a
421 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a
422 EOF
423 git -C tweak update-index --index-info <input &&
424
425 git -C tweak sparse-checkout init --cone 2>err &&
426 test_i18ngrep "warning.*The following paths are not up to date" err &&
427 test_i18ngrep "warning.*The following paths are unmerged" err &&
428
429 git -C tweak sparse-checkout set folder2 deep/deeper1 2>err &&
430 test_i18ngrep "warning.*The following paths are not up to date" err &&
431 test_i18ngrep "warning.*The following paths are unmerged" err &&
432
433 git -C tweak sparse-checkout reapply 2>err &&
434 test_i18ngrep "warning.*The following paths are not up to date" err &&
435 test_path_is_file tweak/deep/deeper2/a &&
436 test_i18ngrep "warning.*The following paths are unmerged" err &&
437 test_path_is_file tweak/folder1/a &&
438
439 git -C tweak checkout HEAD deep/deeper2/a &&
440 git -C tweak sparse-checkout reapply 2>err &&
441 test_i18ngrep ! "warning.*The following paths are not up to date" err &&
442 test_path_is_missing tweak/deep/deeper2/a &&
443 test_i18ngrep "warning.*The following paths are unmerged" err &&
444 test_path_is_file tweak/folder1/a &&
445
446 # NEEDSWORK: We are asking to update a file outside of the
447 # sparse-checkout cone, but this is no longer allowed.
448 git -C tweak add folder1/a &&
449 git -C tweak sparse-checkout reapply 2>err &&
450 test_must_be_empty err &&
451 test_path_is_missing tweak/deep/deeper2/a &&
452 test_path_is_missing tweak/folder1/a &&
453
454 git -C tweak sparse-checkout disable
455 '
456
457 test_expect_success 'cone mode: set with core.ignoreCase=true' '
458 rm repo/.git/info/sparse-checkout &&
459 git -C repo sparse-checkout init --cone &&
460 git -C repo -c core.ignoreCase=true sparse-checkout set folder1 &&
461 cat >expect <<-\EOF &&
462 /*
463 !/*/
464 /folder1/
465 EOF
466 test_cmp expect repo/.git/info/sparse-checkout &&
467 check_files repo a folder1
468 '
469
470 test_expect_success 'interaction with submodules' '
471 git clone repo super &&
472 (
473 cd super &&
474 mkdir modules &&
475 git submodule add ../repo modules/child &&
476 git add . &&
477 git commit -m "add submodule" &&
478 git sparse-checkout init --cone &&
479 git sparse-checkout set folder1
480 ) &&
481 check_files super a folder1 modules &&
482 check_files super/modules/child a deep folder1 folder2
483 '
484
485 test_expect_success 'different sparse-checkouts with worktrees' '
486 git -C repo worktree add --detach ../worktree &&
487 check_files worktree "a deep folder1 folder2" &&
488 git -C worktree sparse-checkout init --cone &&
489 git -C repo sparse-checkout set folder1 &&
490 git -C worktree sparse-checkout set deep/deeper1 &&
491 check_files repo a folder1 &&
492 check_files worktree a deep
493 '
494
495 test_expect_success 'set using filename keeps file on-disk' '
496 git -C repo sparse-checkout set a deep &&
497 cat >expect <<-\EOF &&
498 /*
499 !/*/
500 /a/
501 /deep/
502 EOF
503 test_cmp expect repo/.git/info/sparse-checkout &&
504 check_files repo a deep
505 '
506
507 check_read_tree_errors () {
508 REPO=$1
509 FILES=$2
510 ERRORS=$3
511 git -C $REPO -c core.sparseCheckoutCone=false read-tree -mu HEAD 2>err &&
512 test_must_be_empty err &&
513 check_files $REPO "$FILES" &&
514 git -C $REPO read-tree -mu HEAD 2>err &&
515 if test -z "$ERRORS"
516 then
517 test_must_be_empty err
518 else
519 test_i18ngrep "$ERRORS" err
520 fi &&
521 check_files $REPO $FILES
522 }
523
524 test_expect_success 'pattern-checks: /A/**' '
525 cat >repo/.git/info/sparse-checkout <<-\EOF &&
526 /*
527 !/*/
528 /folder1/**
529 EOF
530 check_read_tree_errors repo "a folder1" "disabling cone pattern matching"
531 '
532
533 test_expect_success 'pattern-checks: /A/**/B/' '
534 cat >repo/.git/info/sparse-checkout <<-\EOF &&
535 /*
536 !/*/
537 /deep/**/deepest
538 EOF
539 check_read_tree_errors repo "a deep" "disabling cone pattern matching" &&
540 check_files repo/deep "deeper1" &&
541 check_files repo/deep/deeper1 "deepest"
542 '
543
544 test_expect_success 'pattern-checks: too short' '
545 cat >repo/.git/info/sparse-checkout <<-\EOF &&
546 /*
547 !/*/
548 /
549 EOF
550 check_read_tree_errors repo "a" "disabling cone pattern matching"
551 '
552 test_expect_success 'pattern-checks: not too short' '
553 cat >repo/.git/info/sparse-checkout <<-\EOF &&
554 /*
555 !/*/
556 /b/
557 EOF
558 git -C repo read-tree -mu HEAD 2>err &&
559 test_must_be_empty err &&
560 check_files repo a
561 '
562
563 test_expect_success 'pattern-checks: trailing "*"' '
564 cat >repo/.git/info/sparse-checkout <<-\EOF &&
565 /*
566 !/*/
567 /a*
568 EOF
569 check_read_tree_errors repo "a" "disabling cone pattern matching"
570 '
571
572 test_expect_success 'pattern-checks: starting "*"' '
573 cat >repo/.git/info/sparse-checkout <<-\EOF &&
574 /*
575 !/*/
576 *eep/
577 EOF
578 check_read_tree_errors repo "a deep" "disabling cone pattern matching"
579 '
580
581 test_expect_success 'pattern-checks: contained glob characters' '
582 for c in "[a]" "\\" "?" "*"
583 do
584 cat >repo/.git/info/sparse-checkout <<-EOF &&
585 /*
586 !/*/
587 something$c-else/
588 EOF
589 check_read_tree_errors repo "a" "disabling cone pattern matching"
590 done
591 '
592
593 test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' '
594 git clone repo escaped &&
595 TREEOID=$(git -C escaped rev-parse HEAD:folder1) &&
596 NEWTREE=$(git -C escaped mktree <<-EOF
597 $(git -C escaped ls-tree HEAD)
598 040000 tree $TREEOID zbad\\dir
599 040000 tree $TREEOID zdoes*exist
600 040000 tree $TREEOID zglob[!a]?
601 EOF
602 ) &&
603 COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) &&
604 git -C escaped reset --hard $COMMIT &&
605 check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
606 git -C escaped sparse-checkout init --cone &&
607 git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" &&
608 cat >expect <<-\EOF &&
609 /*
610 !/*/
611 /zbad\\dir/
612 !/zbad\\dir/*/
613 /zbad\\dir/bogus/
614 /zdoes\*exist/
615 /zdoes\*not\*exist/
616 /zglob\[!a]\?/
617 EOF
618 test_cmp expect escaped/.git/info/sparse-checkout &&
619 check_read_tree_errors escaped "a zbad\\dir zdoes*exist zglob[!a]?" &&
620 git -C escaped ls-tree -d --name-only HEAD >list-expect &&
621 git -C escaped sparse-checkout set --stdin <list-expect &&
622 cat >expect <<-\EOF &&
623 /*
624 !/*/
625 /deep/
626 /folder1/
627 /folder2/
628 /zbad\\dir/
629 /zdoes\*exist/
630 /zglob\[!a]\?/
631 EOF
632 test_cmp expect escaped/.git/info/sparse-checkout &&
633 check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
634 git -C escaped sparse-checkout list >list-actual &&
635 test_cmp list-expect list-actual
636 '
637
638 test_expect_success MINGW 'cone mode replaces backslashes with slashes' '
639 git -C repo sparse-checkout set deep\\deeper1 &&
640 cat >expect <<-\EOF &&
641 /*
642 !/*/
643 /deep/
644 !/deep/*/
645 /deep/deeper1/
646 EOF
647 test_cmp expect repo/.git/info/sparse-checkout &&
648 check_files repo a deep &&
649 check_files repo/deep a deeper1
650 '
651
652 test_expect_success 'cone mode clears ignored subdirectories' '
653 rm repo/.git/info/sparse-checkout &&
654
655 git -C repo sparse-checkout init --cone &&
656 git -C repo sparse-checkout set deep/deeper1 &&
657
658 cat >repo/.gitignore <<-\EOF &&
659 obj/
660 *.o
661 EOF
662
663 git -C repo add .gitignore &&
664 git -C repo commit -m ".gitignore" &&
665
666 mkdir -p repo/obj repo/folder1/obj repo/deep/deeper2/obj &&
667 for file in folder1/obj/a obj/a folder1/file.o folder1.o \
668 deep/deeper2/obj/a deep/deeper2/file.o file.o
669 do
670 echo ignored >repo/$file || return 1
671 done &&
672
673 git -C repo status --porcelain=v2 >out &&
674 test_must_be_empty out &&
675
676 git -C repo sparse-checkout reapply &&
677 test_path_is_missing repo/folder1 &&
678 test_path_is_missing repo/deep/deeper2 &&
679 test_path_is_dir repo/obj &&
680 test_path_is_file repo/file.o &&
681
682 git -C repo status --porcelain=v2 >out &&
683 test_must_be_empty out &&
684
685 git -C repo sparse-checkout set deep/deeper2 &&
686 test_path_is_missing repo/deep/deeper1 &&
687 test_path_is_dir repo/deep/deeper2 &&
688 test_path_is_dir repo/obj &&
689 test_path_is_file repo/file.o &&
690
691 >repo/deep/deeper2/ignored.o &&
692 >repo/deep/deeper2/untracked &&
693
694 # When an untracked file is in the way, all untracked files
695 # (even ignored files) are preserved.
696 git -C repo sparse-checkout set folder1 2>err &&
697 grep "contains untracked files" err &&
698 test_path_is_file repo/deep/deeper2/ignored.o &&
699 test_path_is_file repo/deep/deeper2/untracked &&
700
701 # The rest of the cone matches expectation
702 test_path_is_missing repo/deep/deeper1 &&
703 test_path_is_dir repo/obj &&
704 test_path_is_file repo/file.o &&
705
706 git -C repo status --porcelain=v2 >out &&
707 echo "? deep/deeper2/untracked" >expect &&
708 test_cmp expect out
709 '
710
711 test_done