]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1092-sparse-checkout-compatibility.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t1092-sparse-checkout-compatibility.sh
1 #!/bin/sh
2
3 test_description='compare full workdir to sparse workdir'
4
5 GIT_TEST_SPLIT_INDEX=0
6 GIT_TEST_SPARSE_INDEX=
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11 git init initial-repo &&
12 (
13 GIT_TEST_SPARSE_INDEX=0 &&
14 cd initial-repo &&
15 echo a >a &&
16 echo "after deep" >e &&
17 echo "after folder1" >g &&
18 echo "after x" >z &&
19 mkdir folder1 folder2 deep before x &&
20 echo "before deep" >before/a &&
21 echo "before deep again" >before/b &&
22 mkdir deep/deeper1 deep/deeper2 deep/before deep/later &&
23 mkdir deep/deeper1/deepest &&
24 mkdir deep/deeper1/deepest2 &&
25 mkdir deep/deeper1/deepest3 &&
26 echo "after deeper1" >deep/e &&
27 echo "after deepest" >deep/deeper1/e &&
28 cp a folder1 &&
29 cp a folder2 &&
30 cp a x &&
31 cp a deep &&
32 cp a deep/before &&
33 cp a deep/deeper1 &&
34 cp a deep/deeper2 &&
35 cp a deep/later &&
36 cp a deep/deeper1/deepest &&
37 cp a deep/deeper1/deepest2 &&
38 cp a deep/deeper1/deepest3 &&
39 cp -r deep/deeper1/ deep/deeper2 &&
40 mkdir deep/deeper1/0 &&
41 mkdir deep/deeper1/0/0 &&
42 touch deep/deeper1/0/1 &&
43 touch deep/deeper1/0/0/0 &&
44 >folder1- &&
45 >folder1.x &&
46 >folder10 &&
47 cp -r deep/deeper1/0 folder1 &&
48 cp -r deep/deeper1/0 folder2 &&
49 echo >>folder1/0/0/0 &&
50 echo >>folder2/0/1 &&
51 git add . &&
52 git commit -m "initial commit" &&
53 git checkout -b base &&
54 for dir in folder1 folder2 deep
55 do
56 git checkout -b update-$dir base &&
57 echo "updated $dir" >$dir/a &&
58 git commit -a -m "update $dir" || return 1
59 done &&
60
61 git checkout -b rename-base base &&
62 cat >folder1/larger-content <<-\EOF &&
63 matching
64 lines
65 help
66 inexact
67 renames
68 EOF
69 cp folder1/larger-content folder2/ &&
70 cp folder1/larger-content deep/deeper1/ &&
71 git add . &&
72 git commit -m "add interesting rename content" &&
73
74 git checkout -b rename-out-to-out rename-base &&
75 mv folder1/a folder2/b &&
76 mv folder1/larger-content folder2/edited-content &&
77 echo >>folder2/edited-content &&
78 echo >>folder2/0/1 &&
79 echo stuff >>deep/deeper1/a &&
80 git add . &&
81 git commit -m "rename folder1/... to folder2/..." &&
82
83 git checkout -b rename-out-to-in rename-base &&
84 mv folder1/a deep/deeper1/b &&
85 echo more stuff >>deep/deeper1/a &&
86 rm folder2/0/1 &&
87 mkdir folder2/0/1 &&
88 echo >>folder2/0/1/1 &&
89 mv folder1/larger-content deep/deeper1/edited-content &&
90 echo >>deep/deeper1/edited-content &&
91 git add . &&
92 git commit -m "rename folder1/... to deep/deeper1/..." &&
93
94 git checkout -b rename-in-to-out rename-base &&
95 mv deep/deeper1/a folder1/b &&
96 echo >>folder2/0/1 &&
97 rm -rf folder1/0/0 &&
98 echo >>folder1/0/0 &&
99 mv deep/deeper1/larger-content folder1/edited-content &&
100 echo >>folder1/edited-content &&
101 git add . &&
102 git commit -m "rename deep/deeper1/... to folder1/..." &&
103
104 git checkout -b df-conflict-1 base &&
105 rm -rf folder1 &&
106 echo content >folder1 &&
107 git add . &&
108 git commit -m "dir to file" &&
109
110 git checkout -b df-conflict-2 base &&
111 rm -rf folder2 &&
112 echo content >folder2 &&
113 git add . &&
114 git commit -m "dir to file" &&
115
116 git checkout -b fd-conflict base &&
117 rm a &&
118 mkdir a &&
119 echo content >a/a &&
120 git add . &&
121 git commit -m "file to dir" &&
122
123 for side in left right
124 do
125 git checkout -b merge-$side base &&
126 echo $side >>deep/deeper2/a &&
127 echo $side >>folder1/a &&
128 echo $side >>folder2/a &&
129 git add . &&
130 git commit -m "$side" || return 1
131 done &&
132
133 git checkout -b deepest base &&
134 echo "updated deepest" >deep/deeper1/deepest/a &&
135 echo "updated deepest2" >deep/deeper1/deepest2/a &&
136 echo "updated deepest3" >deep/deeper1/deepest3/a &&
137 git commit -a -m "update deepest" &&
138
139 git checkout -f base &&
140 git reset --hard
141 )
142 '
143
144 init_repos () {
145 rm -rf full-checkout sparse-checkout sparse-index &&
146
147 # create repos in initial state
148 cp -r initial-repo full-checkout &&
149 git -C full-checkout reset --hard &&
150
151 cp -r initial-repo sparse-checkout &&
152 git -C sparse-checkout reset --hard &&
153
154 cp -r initial-repo sparse-index &&
155 git -C sparse-index reset --hard &&
156
157 # initialize sparse-checkout definitions
158 git -C sparse-checkout sparse-checkout init --cone &&
159 git -C sparse-checkout sparse-checkout set deep &&
160 git -C sparse-index sparse-checkout init --cone --sparse-index &&
161 test_cmp_config -C sparse-index true index.sparse &&
162 git -C sparse-index sparse-checkout set deep
163 }
164
165 run_on_sparse () {
166 (
167 cd sparse-checkout &&
168 GIT_PROGRESS_DELAY=100000 "$@" >../sparse-checkout-out 2>../sparse-checkout-err
169 ) &&
170 (
171 cd sparse-index &&
172 GIT_PROGRESS_DELAY=100000 "$@" >../sparse-index-out 2>../sparse-index-err
173 )
174 }
175
176 run_on_all () {
177 (
178 cd full-checkout &&
179 GIT_PROGRESS_DELAY=100000 "$@" >../full-checkout-out 2>../full-checkout-err
180 ) &&
181 run_on_sparse "$@"
182 }
183
184 test_all_match () {
185 run_on_all "$@" &&
186 test_cmp full-checkout-out sparse-checkout-out &&
187 test_cmp full-checkout-out sparse-index-out &&
188 test_cmp full-checkout-err sparse-checkout-err &&
189 test_cmp full-checkout-err sparse-index-err
190 }
191
192 test_sparse_match () {
193 run_on_sparse "$@" &&
194 test_cmp sparse-checkout-out sparse-index-out &&
195 test_cmp sparse-checkout-err sparse-index-err
196 }
197
198 test_sparse_unstaged () {
199 file=$1 &&
200 for repo in sparse-checkout sparse-index
201 do
202 # Skip "unmerged" paths
203 git -C $repo diff --staged --diff-filter=u -- "$file" >diff &&
204 test_must_be_empty diff || return 1
205 done
206 }
207
208 # Usage: test_sprase_checkout_set "<c1> ... <cN>" "<s1> ... <sM>"
209 # Verifies that "git sparse-checkout set <c1> ... <cN>" succeeds and
210 # leaves the sparse index in a state where <s1> ... <sM> are sparse
211 # directories (and <c1> ... <cN> are not).
212 test_sparse_checkout_set () {
213 CONE_DIRS=$1 &&
214 SPARSE_DIRS=$2 &&
215 git -C sparse-index sparse-checkout set --skip-checks $CONE_DIRS &&
216 git -C sparse-index ls-files --sparse --stage >cache &&
217
218 # Check that the directories outside of the sparse-checkout cone
219 # have sparse directory entries.
220 for dir in $SPARSE_DIRS
221 do
222 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
223 grep "040000 $TREE 0 $dir/" cache \
224 || return 1
225 done &&
226
227 # Check that the directories in the sparse-checkout cone
228 # are not sparse directory entries.
229 for dir in $CONE_DIRS
230 do
231 # Allow TREE to not exist because
232 # $dir does not exist at HEAD.
233 TREE=$(git -C sparse-index rev-parse HEAD:$dir) ||
234 ! grep "040000 $TREE 0 $dir/" cache \
235 || return 1
236 done
237 }
238
239 test_expect_success 'sparse-index contents' '
240 init_repos &&
241
242 # Remove deep, add three other directories.
243 test_sparse_checkout_set \
244 "folder1 folder2 x" \
245 "before deep" &&
246
247 # Remove folder1, add deep
248 test_sparse_checkout_set \
249 "deep folder2 x" \
250 "before folder1" &&
251
252 # Replace deep with deep/deeper2 (dropping deep/deeper1)
253 # Add folder1
254 test_sparse_checkout_set \
255 "deep/deeper2 folder1 folder2 x" \
256 "before deep/deeper1" &&
257
258 # Replace deep/deeper2 with deep/deeper1
259 # Replace folder1 with folder1/0/0
260 # Replace folder2 with non-existent folder2/2/3
261 # Add non-existent "bogus"
262 test_sparse_checkout_set \
263 "bogus deep/deeper1 folder1/0/0 folder2/2/3 x" \
264 "before deep/deeper2 folder2/0" &&
265
266 # Drop down to only files at root
267 test_sparse_checkout_set \
268 "" \
269 "before deep folder1 folder2 x" &&
270
271 # Disabling the sparse-index replaces tree entries with full ones
272 git -C sparse-index sparse-checkout init --no-sparse-index &&
273 test_sparse_match git ls-files --stage --sparse
274 '
275
276 test_expect_success 'expanded in-memory index matches full index' '
277 init_repos &&
278 test_sparse_match git ls-files --stage
279 '
280
281 test_expect_success 'root directory cannot be sparse' '
282 init_repos &&
283
284 # Remove all in-cone files and directories from the index, collapse index
285 # with `git sparse-checkout reapply`
286 git -C sparse-index rm -r . &&
287 git -C sparse-index sparse-checkout reapply &&
288
289 # Verify sparse directories still present, root directory is not sparse
290 cat >expect <<-EOF &&
291 before/
292 folder1/
293 folder2/
294 x/
295 EOF
296 git -C sparse-index ls-files --sparse >actual &&
297 test_cmp expect actual
298 '
299
300 test_expect_success 'status with options' '
301 init_repos &&
302 test_sparse_match ls &&
303 test_all_match git status --porcelain=v2 &&
304 test_all_match git status --porcelain=v2 -z -u &&
305 test_all_match git status --porcelain=v2 -uno &&
306 run_on_all touch README.md &&
307 test_all_match git status --porcelain=v2 &&
308 test_all_match git status --porcelain=v2 -z -u &&
309 test_all_match git status --porcelain=v2 -uno &&
310 test_all_match git add README.md &&
311 test_all_match git status --porcelain=v2 &&
312 test_all_match git status --porcelain=v2 -z -u &&
313 test_all_match git status --porcelain=v2 -uno
314 '
315
316 test_expect_success 'status with diff in unexpanded sparse directory' '
317 init_repos &&
318 test_all_match git checkout rename-base &&
319 test_all_match git reset --soft rename-out-to-out &&
320 test_all_match git status --porcelain=v2
321 '
322
323 test_expect_success 'status reports sparse-checkout' '
324 init_repos &&
325 git -C sparse-checkout status >full &&
326 git -C sparse-index status >sparse &&
327 test_i18ngrep "You are in a sparse checkout with " full &&
328 test_i18ngrep "You are in a sparse checkout." sparse
329 '
330
331 test_expect_success 'add, commit, checkout' '
332 init_repos &&
333
334 write_script edit-contents <<-\EOF &&
335 echo text >>$1
336 EOF
337 run_on_all ../edit-contents README.md &&
338
339 test_all_match git add README.md &&
340 test_all_match git status --porcelain=v2 &&
341 test_all_match git commit -m "Add README.md" &&
342
343 test_all_match git checkout HEAD~1 &&
344 test_all_match git checkout - &&
345
346 run_on_all ../edit-contents README.md &&
347
348 test_all_match git add -A &&
349 test_all_match git status --porcelain=v2 &&
350 test_all_match git commit -m "Extend README.md" &&
351
352 test_all_match git checkout HEAD~1 &&
353 test_all_match git checkout - &&
354
355 run_on_all ../edit-contents deep/newfile &&
356
357 test_all_match git status --porcelain=v2 -uno &&
358 test_all_match git status --porcelain=v2 &&
359 test_all_match git add . &&
360 test_all_match git status --porcelain=v2 &&
361 test_all_match git commit -m "add deep/newfile" &&
362
363 test_all_match git checkout HEAD~1 &&
364 test_all_match git checkout -
365 '
366
367 test_expect_success 'deep changes during checkout' '
368 init_repos &&
369
370 test_sparse_match git sparse-checkout set deep/deeper1/deepest &&
371 test_all_match git checkout deepest &&
372 test_all_match git checkout base
373 '
374
375 test_expect_success 'checkout with modified sparse directory' '
376 init_repos &&
377
378 test_all_match git checkout rename-in-to-out -- . &&
379 test_sparse_match git sparse-checkout reapply &&
380 test_all_match git checkout base
381 '
382
383 test_expect_success 'checkout orphan then non-orphan' '
384 init_repos &&
385
386 test_all_match git checkout --orphan test-orphan &&
387 test_all_match git status --porcelain=v2 &&
388 test_all_match git checkout base &&
389 test_all_match git status --porcelain=v2
390 '
391
392 test_expect_success 'add outside sparse cone' '
393 init_repos &&
394
395 run_on_sparse mkdir folder1 &&
396 run_on_sparse ../edit-contents folder1/a &&
397 run_on_sparse ../edit-contents folder1/newfile &&
398 test_sparse_match test_must_fail git add folder1/a &&
399 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
400 test_sparse_unstaged folder1/a &&
401 test_sparse_match test_must_fail git add folder1/newfile &&
402 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
403 test_sparse_unstaged folder1/newfile
404 '
405
406 test_expect_success 'commit including unstaged changes' '
407 init_repos &&
408
409 write_script edit-file <<-\EOF &&
410 echo $1 >$2
411 EOF
412
413 run_on_all ../edit-file 1 a &&
414 run_on_all ../edit-file 1 deep/a &&
415
416 test_all_match git commit -m "-a" -a &&
417 test_all_match git status --porcelain=v2 &&
418
419 run_on_all ../edit-file 2 a &&
420 run_on_all ../edit-file 2 deep/a &&
421
422 test_all_match git commit -m "--include" --include deep/a &&
423 test_all_match git status --porcelain=v2 &&
424 test_all_match git commit -m "--include" --include a &&
425 test_all_match git status --porcelain=v2 &&
426
427 run_on_all ../edit-file 3 a &&
428 run_on_all ../edit-file 3 deep/a &&
429
430 test_all_match git commit -m "--amend" -a --amend &&
431 test_all_match git status --porcelain=v2
432 '
433
434 test_expect_success 'status/add: outside sparse cone' '
435 init_repos &&
436
437 # folder1 is at HEAD, but outside the sparse cone
438 run_on_sparse mkdir folder1 &&
439 cp initial-repo/folder1/a sparse-checkout/folder1/a &&
440 cp initial-repo/folder1/a sparse-index/folder1/a &&
441
442 test_sparse_match git status &&
443
444 write_script edit-contents <<-\EOF &&
445 echo text >>$1
446 EOF
447 run_on_all ../edit-contents folder1/a &&
448 run_on_all ../edit-contents folder1/new &&
449
450 test_sparse_match git status --porcelain=v2 &&
451
452 # Adding the path outside of the sparse-checkout cone should fail.
453 test_sparse_match test_must_fail git add folder1/a &&
454 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
455 test_sparse_unstaged folder1/a &&
456 test_all_match git add --refresh folder1/a &&
457 test_must_be_empty sparse-checkout-err &&
458 test_sparse_unstaged folder1/a &&
459 test_sparse_match test_must_fail git add folder1/new &&
460 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
461 test_sparse_unstaged folder1/new &&
462 test_sparse_match git add --sparse folder1/a &&
463 test_sparse_match git add --sparse folder1/new &&
464
465 test_all_match git add --sparse . &&
466 test_all_match git status --porcelain=v2 &&
467 test_all_match git commit -m folder1/new &&
468 test_all_match git rev-parse HEAD^{tree} &&
469
470 run_on_all ../edit-contents folder1/newer &&
471 test_all_match git add --sparse folder1/ &&
472 test_all_match git status --porcelain=v2 &&
473 test_all_match git commit -m folder1/newer &&
474 test_all_match git rev-parse HEAD^{tree}
475 '
476
477 test_expect_success 'checkout and reset --hard' '
478 init_repos &&
479
480 test_all_match git checkout update-folder1 &&
481 test_all_match git status --porcelain=v2 &&
482
483 test_all_match git checkout update-deep &&
484 test_all_match git status --porcelain=v2 &&
485
486 test_all_match git checkout -b reset-test &&
487 test_all_match git reset --hard deepest &&
488 test_all_match git reset --hard update-folder1 &&
489 test_all_match git reset --hard update-folder2
490 '
491
492 test_expect_success 'diff --cached' '
493 init_repos &&
494
495 write_script edit-contents <<-\EOF &&
496 echo text >>README.md
497 EOF
498 run_on_all ../edit-contents &&
499
500 test_all_match git diff &&
501 test_all_match git diff --cached &&
502 test_all_match git add README.md &&
503 test_all_match git diff &&
504 test_all_match git diff --cached
505 '
506
507 # NEEDSWORK: sparse-checkout behaves differently from full-checkout when
508 # running this test with 'df-conflict-2' after 'df-conflict-1'.
509 test_expect_success 'diff with renames and conflicts' '
510 init_repos &&
511
512 for branch in rename-out-to-out \
513 rename-out-to-in \
514 rename-in-to-out \
515 df-conflict-1 \
516 fd-conflict
517 do
518 test_all_match git checkout rename-base &&
519 test_all_match git checkout $branch -- . &&
520 test_all_match git status --porcelain=v2 &&
521 test_all_match git diff --cached --no-renames &&
522 test_all_match git diff --cached --find-renames || return 1
523 done
524 '
525
526 test_expect_success 'diff with directory/file conflicts' '
527 init_repos &&
528
529 for branch in rename-out-to-out \
530 rename-out-to-in \
531 rename-in-to-out \
532 df-conflict-1 \
533 df-conflict-2 \
534 fd-conflict
535 do
536 git -C full-checkout reset --hard &&
537 test_sparse_match git reset --hard &&
538 test_all_match git checkout $branch &&
539 test_all_match git checkout rename-base -- . &&
540 test_all_match git status --porcelain=v2 &&
541 test_all_match git diff --cached --no-renames &&
542 test_all_match git diff --cached --find-renames || return 1
543 done
544 '
545
546 test_expect_success 'log with pathspec outside sparse definition' '
547 init_repos &&
548
549 test_all_match git log -- a &&
550 test_all_match git log -- folder1/a &&
551 test_all_match git log -- folder2/a &&
552 test_all_match git log -- deep/a &&
553 test_all_match git log -- deep/deeper1/a &&
554 test_all_match git log -- deep/deeper1/deepest/a &&
555
556 test_all_match git checkout update-folder1 &&
557 test_all_match git log -- folder1/a
558 '
559
560 test_expect_success 'blame with pathspec inside sparse definition' '
561 init_repos &&
562
563 for file in a \
564 deep/a \
565 deep/deeper1/a \
566 deep/deeper1/deepest/a
567 do
568 test_all_match git blame $file || return 1
569 done
570 '
571
572 # Without a revision specified, blame will error if passed any file that
573 # is not present in the working directory (even if the file is tracked).
574 # Here we just verify that this is also true with sparse checkouts.
575 test_expect_success 'blame with pathspec outside sparse definition' '
576 init_repos &&
577 test_sparse_match git sparse-checkout set &&
578
579 for file in \
580 deep/a \
581 deep/deeper1/a \
582 deep/deeper1/deepest/a
583 do
584 test_sparse_match test_must_fail git blame $file &&
585 cat >expect <<-EOF &&
586 fatal: Cannot lstat '"'"'$file'"'"': No such file or directory
587 EOF
588 # We compare sparse-checkout-err and sparse-index-err in
589 # `test_sparse_match`. Given we know they are the same, we
590 # only check the content of sparse-index-err here.
591 test_cmp expect sparse-index-err || return 1
592 done
593 '
594
595 test_expect_success 'checkout and reset (mixed)' '
596 init_repos &&
597
598 test_all_match git checkout -b reset-test update-deep &&
599 test_all_match git reset deepest &&
600
601 # Because skip-worktree is preserved, resetting to update-folder1
602 # will show worktree changes for folder1/a in full-checkout, but not
603 # in sparse-checkout or sparse-index.
604 git -C full-checkout reset update-folder1 >full-checkout-out &&
605 test_sparse_match git reset update-folder1 &&
606 grep "M folder1/a" full-checkout-out &&
607 ! grep "M folder1/a" sparse-checkout-out &&
608 run_on_sparse test_path_is_missing folder1
609 '
610
611 test_expect_success 'checkout and reset (merge)' '
612 init_repos &&
613
614 write_script edit-contents <<-\EOF &&
615 echo text >>$1
616 EOF
617
618 test_all_match git checkout -b reset-test update-deep &&
619 run_on_all ../edit-contents a &&
620 test_all_match git reset --merge deepest &&
621 test_all_match git status --porcelain=v2 &&
622
623 test_all_match git reset --hard update-deep &&
624 run_on_all ../edit-contents deep/a &&
625 test_all_match test_must_fail git reset --merge deepest
626 '
627
628 test_expect_success 'checkout and reset (keep)' '
629 init_repos &&
630
631 write_script edit-contents <<-\EOF &&
632 echo text >>$1
633 EOF
634
635 test_all_match git checkout -b reset-test update-deep &&
636 run_on_all ../edit-contents a &&
637 test_all_match git reset --keep deepest &&
638 test_all_match git status --porcelain=v2 &&
639
640 test_all_match git reset --hard update-deep &&
641 run_on_all ../edit-contents deep/a &&
642 test_all_match test_must_fail git reset --keep deepest
643 '
644
645 test_expect_success 'reset with pathspecs inside sparse definition' '
646 init_repos &&
647
648 write_script edit-contents <<-\EOF &&
649 echo text >>$1
650 EOF
651
652 test_all_match git checkout -b reset-test update-deep &&
653 run_on_all ../edit-contents deep/a &&
654
655 test_all_match git reset base -- deep/a &&
656 test_all_match git status --porcelain=v2 &&
657
658 test_all_match git reset base -- nonexistent-file &&
659 test_all_match git status --porcelain=v2 &&
660
661 test_all_match git reset deepest -- deep &&
662 test_all_match git status --porcelain=v2
663 '
664
665 # Although the working tree differs between full and sparse checkouts after
666 # reset, the state of the index is the same.
667 test_expect_success 'reset with pathspecs outside sparse definition' '
668 init_repos &&
669 test_all_match git checkout -b reset-test base &&
670
671 test_sparse_match git reset update-folder1 -- folder1 &&
672 git -C full-checkout reset update-folder1 -- folder1 &&
673 test_all_match git ls-files -s -- folder1 &&
674
675 test_sparse_match git reset update-folder2 -- folder2/a &&
676 git -C full-checkout reset update-folder2 -- folder2/a &&
677 test_all_match git ls-files -s -- folder2/a
678 '
679
680 test_expect_success 'reset with wildcard pathspec' '
681 init_repos &&
682
683 test_all_match git reset update-deep -- deep\* &&
684 test_all_match git ls-files -s -- deep &&
685
686 test_all_match git reset deepest -- deep\*\*\* &&
687 test_all_match git ls-files -s -- deep &&
688
689 # The following `git reset`s result in updating the index on files with
690 # `skip-worktree` enabled. To avoid failing due to discrepencies in reported
691 # "modified" files, `test_sparse_match` reset is performed separately from
692 # "full-checkout" reset, then the index contents of all repos are verified.
693
694 test_sparse_match git reset update-folder1 -- \*/a &&
695 git -C full-checkout reset update-folder1 -- \*/a &&
696 test_all_match git ls-files -s -- deep/a folder1/a &&
697
698 test_sparse_match git reset update-folder2 -- folder\* &&
699 git -C full-checkout reset update-folder2 -- folder\* &&
700 test_all_match git ls-files -s -- folder10 folder1 folder2 &&
701
702 test_sparse_match git reset base -- folder1/\* &&
703 git -C full-checkout reset base -- folder1/\* &&
704 test_all_match git ls-files -s -- folder1
705 '
706
707 test_expect_success 'reset hard with removed sparse dir' '
708 init_repos &&
709
710 run_on_all git rm -r --sparse folder1 &&
711 test_all_match git status --porcelain=v2 &&
712
713 test_all_match git reset --hard &&
714 test_all_match git status --porcelain=v2 &&
715
716 cat >expect <<-\EOF &&
717 folder1/
718 EOF
719
720 git -C sparse-index ls-files --sparse folder1 >out &&
721 test_cmp expect out
722 '
723
724 test_expect_success 'update-index modify outside sparse definition' '
725 init_repos &&
726
727 write_script edit-contents <<-\EOF &&
728 echo text >>$1
729 EOF
730
731 # Create & modify folder1/a
732 # Note that this setup is a manual way of reaching the erroneous
733 # condition in which a `skip-worktree` enabled, outside-of-cone file
734 # exists on disk. It is used here to ensure `update-index` is stable
735 # and behaves predictably if such a condition occurs.
736 run_on_sparse mkdir -p folder1 &&
737 run_on_sparse cp ../initial-repo/folder1/a folder1/a &&
738 run_on_all ../edit-contents folder1/a &&
739
740 # If file has skip-worktree enabled, but the file is present, it is
741 # treated the same as if skip-worktree is disabled
742 test_all_match git status --porcelain=v2 &&
743 test_all_match git update-index folder1/a &&
744 test_all_match git status --porcelain=v2 &&
745
746 # When skip-worktree is disabled (even on files outside sparse cone), file
747 # is updated in the index
748 test_sparse_match git update-index --no-skip-worktree folder1/a &&
749 test_all_match git status --porcelain=v2 &&
750 test_all_match git update-index folder1/a &&
751 test_all_match git status --porcelain=v2
752 '
753
754 test_expect_success 'update-index --add outside sparse definition' '
755 init_repos &&
756
757 write_script edit-contents <<-\EOF &&
758 echo text >>$1
759 EOF
760
761 # Create folder1, add new file
762 run_on_sparse mkdir -p folder1 &&
763 run_on_all ../edit-contents folder1/b &&
764
765 # The *untracked* out-of-cone file is added to the index because it does
766 # not have a `skip-worktree` bit to signal that it should be ignored
767 # (unlike in `git add`, which will fail due to the file being outside
768 # the sparse checkout definition).
769 test_all_match git update-index --add folder1/b &&
770 test_all_match git status --porcelain=v2
771 '
772
773 # NEEDSWORK: `--remove`, unlike the rest of `update-index`, does not ignore
774 # `skip-worktree` entries by default and will remove them from the index.
775 # The `--ignore-skip-worktree-entries` flag must be used in conjunction with
776 # `--remove` to ignore the `skip-worktree` entries and prevent their removal
777 # from the index.
778 test_expect_success 'update-index --remove outside sparse definition' '
779 init_repos &&
780
781 # When --ignore-skip-worktree-entries is _not_ specified:
782 # out-of-cone, not-on-disk files are removed from the index
783 test_sparse_match git update-index --remove folder1/a &&
784 cat >expect <<-EOF &&
785 D folder1/a
786 EOF
787 test_sparse_match git diff --cached --name-status &&
788 test_cmp expect sparse-checkout-out &&
789
790 # Reset the state
791 test_all_match git reset --hard &&
792
793 # When --ignore-skip-worktree-entries is specified, out-of-cone
794 # (skip-worktree) files are ignored
795 test_sparse_match git update-index --remove --ignore-skip-worktree-entries folder1/a &&
796 test_sparse_match git diff --cached --name-status &&
797 test_must_be_empty sparse-checkout-out &&
798
799 # Reset the state
800 test_all_match git reset --hard &&
801
802 # --force-remove supercedes --ignore-skip-worktree-entries, removing
803 # a skip-worktree file from the index (and disk) when both are specified
804 # with --remove
805 test_sparse_match git update-index --force-remove --ignore-skip-worktree-entries folder1/a &&
806 cat >expect <<-EOF &&
807 D folder1/a
808 EOF
809 test_sparse_match git diff --cached --name-status &&
810 test_cmp expect sparse-checkout-out
811 '
812
813 test_expect_success 'update-index with directories' '
814 init_repos &&
815
816 # update-index will exit silently when provided with a directory name
817 # containing a trailing slash
818 test_all_match git update-index deep/ folder1/ &&
819 grep "Ignoring path deep/" sparse-checkout-err &&
820 grep "Ignoring path folder1/" sparse-checkout-err &&
821
822 # When update-index is given a directory name WITHOUT a trailing slash, it will
823 # behave in different ways depending on the status of the directory on disk:
824 # * if it exists, the command exits with an error ("add individual files instead")
825 # * if it does NOT exist (e.g., in a sparse-checkout), it is assumed to be a
826 # file and either triggers an error ("does not exist and --remove not passed")
827 # or is ignored completely (when using --remove)
828 test_all_match test_must_fail git update-index deep &&
829 run_on_all test_must_fail git update-index folder1 &&
830 test_must_fail git -C full-checkout update-index --remove folder1 &&
831 test_sparse_match git update-index --remove folder1 &&
832 test_all_match git status --porcelain=v2
833 '
834
835 test_expect_success 'update-index --again file outside sparse definition' '
836 init_repos &&
837
838 test_all_match git checkout -b test-reupdate &&
839
840 # Update HEAD without modifying the index to introduce a difference in
841 # folder1/a
842 test_sparse_match git reset --soft update-folder1 &&
843
844 # Because folder1/a differs in the index vs HEAD,
845 # `git update-index --no-skip-worktree --again` will effectively perform
846 # `git update-index --no-skip-worktree folder1/a` and remove the skip-worktree
847 # flag from folder1/a
848 test_sparse_match git update-index --no-skip-worktree --again &&
849 test_sparse_match git status --porcelain=v2 &&
850
851 cat >expect <<-EOF &&
852 D folder1/a
853 EOF
854 test_sparse_match git diff --name-status &&
855 test_cmp expect sparse-checkout-out
856 '
857
858 test_expect_success 'update-index --cacheinfo' '
859 init_repos &&
860
861 deep_a_oid=$(git -C full-checkout rev-parse update-deep:deep/a) &&
862 folder2_oid=$(git -C full-checkout rev-parse update-folder2:folder2) &&
863 folder1_a_oid=$(git -C full-checkout rev-parse update-folder1:folder1/a) &&
864
865 test_all_match git update-index --cacheinfo 100644 $deep_a_oid deep/a &&
866 test_all_match git status --porcelain=v2 &&
867
868 # Cannot add sparse directory, even in sparse index case
869 test_all_match test_must_fail git update-index --add --cacheinfo 040000 $folder2_oid folder2/ &&
870
871 # Sparse match only: the new outside-of-cone entry is added *without* skip-worktree,
872 # so `git status` reports it as "deleted" in the worktree
873 test_sparse_match git update-index --add --cacheinfo 100644 $folder1_a_oid folder1/a &&
874 test_sparse_match git status --porcelain=v2 &&
875 cat >expect <<-EOF &&
876 MD folder1/a
877 EOF
878 test_sparse_match git status --short -- folder1/a &&
879 test_cmp expect sparse-checkout-out &&
880
881 # To return folder1/a to "normal" for a sparse checkout (ignored &
882 # outside-of-cone), add the skip-worktree flag.
883 test_sparse_match git update-index --skip-worktree folder1/a &&
884 cat >expect <<-EOF &&
885 S folder1/a
886 EOF
887 test_sparse_match git ls-files -t -- folder1/a &&
888 test_cmp expect sparse-checkout-out
889 '
890
891 for MERGE_TREES in "base HEAD update-folder2" \
892 "update-folder1 update-folder2" \
893 "update-folder2"
894 do
895 test_expect_success "'read-tree -mu $MERGE_TREES' with files outside sparse definition" '
896 init_repos &&
897
898 # Although the index matches, without --no-sparse-checkout, outside-of-
899 # definition files will not exist on disk for sparse checkouts
900 test_all_match git read-tree -mu $MERGE_TREES &&
901 test_all_match git status --porcelain=v2 &&
902 test_path_is_missing sparse-checkout/folder2 &&
903 test_path_is_missing sparse-index/folder2 &&
904
905 test_all_match git read-tree --reset -u HEAD &&
906 test_all_match git status --porcelain=v2 &&
907
908 test_all_match git read-tree -mu --no-sparse-checkout $MERGE_TREES &&
909 test_all_match git status --porcelain=v2 &&
910 test_cmp sparse-checkout/folder2/a sparse-index/folder2/a &&
911 test_cmp sparse-checkout/folder2/a full-checkout/folder2/a
912
913 '
914 done
915
916 test_expect_success 'read-tree --merge with edit/edit conflicts in sparse directories' '
917 init_repos &&
918
919 # Merge of multiple changes to same directory (but not same files) should
920 # succeed
921 test_all_match git read-tree -mu base rename-base update-folder1 &&
922 test_all_match git status --porcelain=v2 &&
923
924 test_all_match git reset --hard &&
925
926 test_all_match git read-tree -mu rename-base update-folder2 &&
927 test_all_match git status --porcelain=v2 &&
928
929 test_all_match git reset --hard &&
930
931 test_all_match test_must_fail git read-tree -mu base update-folder1 rename-out-to-in &&
932 test_all_match test_must_fail git read-tree -mu rename-out-to-in update-folder1
933 '
934
935 test_expect_success 'read-tree --prefix' '
936 init_repos &&
937
938 # If files differing between the index and target <commit-ish> exist
939 # inside the prefix, `read-tree --prefix` should fail
940 test_all_match test_must_fail git read-tree --prefix=deep/ deepest &&
941 test_all_match test_must_fail git read-tree --prefix=folder1/ update-folder1 &&
942
943 # If no differing index entries exist matching the prefix,
944 # `read-tree --prefix` updates the index successfully
945 test_all_match git rm -rf deep/deeper1/deepest/ &&
946 test_all_match git read-tree --prefix=deep/deeper1/deepest -u deepest &&
947 test_all_match git status --porcelain=v2 &&
948
949 run_on_all git rm -rf --sparse folder1/ &&
950 test_all_match git read-tree --prefix=folder1/ -u update-folder1 &&
951 test_all_match git status --porcelain=v2 &&
952
953 test_all_match git rm -rf --sparse folder2/0 &&
954 test_all_match git read-tree --prefix=folder2/0/ -u rename-out-to-out &&
955 test_all_match git status --porcelain=v2
956 '
957
958 test_expect_success 'read-tree --merge with directory-file conflicts' '
959 init_repos &&
960
961 test_all_match git checkout -b test-branch rename-base &&
962
963 # Although the index matches, without --no-sparse-checkout, outside-of-
964 # definition files will not exist on disk for sparse checkouts
965 test_sparse_match git read-tree -mu rename-out-to-out &&
966 test_sparse_match git status --porcelain=v2 &&
967 test_path_is_missing sparse-checkout/folder2 &&
968 test_path_is_missing sparse-index/folder2 &&
969
970 test_sparse_match git read-tree --reset -u HEAD &&
971 test_sparse_match git status --porcelain=v2 &&
972
973 test_sparse_match git read-tree -mu --no-sparse-checkout rename-out-to-out &&
974 test_sparse_match git status --porcelain=v2 &&
975 test_cmp sparse-checkout/folder2/0/1 sparse-index/folder2/0/1
976 '
977
978 test_expect_success 'merge, cherry-pick, and rebase' '
979 init_repos &&
980
981 for OPERATION in "merge -m merge" cherry-pick "rebase --apply" "rebase --merge"
982 do
983 test_all_match git checkout -B temp update-deep &&
984 test_all_match git $OPERATION update-folder1 &&
985 test_all_match git rev-parse HEAD^{tree} &&
986 test_all_match git $OPERATION update-folder2 &&
987 test_all_match git rev-parse HEAD^{tree} || return 1
988 done
989 '
990
991 test_expect_success 'merge with conflict outside cone' '
992 init_repos &&
993
994 test_all_match git checkout -b merge-tip merge-left &&
995 test_all_match git status --porcelain=v2 &&
996 test_all_match test_must_fail git merge -m merge merge-right &&
997 test_all_match git status --porcelain=v2 &&
998
999 # Resolve the conflict in different ways:
1000 # 1. Revert to the base
1001 test_all_match git checkout base -- deep/deeper2/a &&
1002 test_all_match git status --porcelain=v2 &&
1003
1004 # 2. Add the file with conflict markers
1005 test_sparse_match test_must_fail git add folder1/a &&
1006 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
1007 test_sparse_unstaged folder1/a &&
1008 test_all_match git add --sparse folder1/a &&
1009 test_all_match git status --porcelain=v2 &&
1010
1011 # 3. Rename the file to another sparse filename and
1012 # accept conflict markers as resolved content.
1013 run_on_all mv folder2/a folder2/z &&
1014 test_sparse_match test_must_fail git add folder2 &&
1015 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
1016 test_sparse_unstaged folder2/z &&
1017 test_all_match git add --sparse folder2 &&
1018 test_all_match git status --porcelain=v2 &&
1019
1020 test_all_match git merge --continue &&
1021 test_all_match git status --porcelain=v2 &&
1022 test_all_match git rev-parse HEAD^{tree}
1023 '
1024
1025 test_expect_success 'cherry-pick/rebase with conflict outside cone' '
1026 init_repos &&
1027
1028 for OPERATION in cherry-pick rebase
1029 do
1030 test_all_match git checkout -B tip &&
1031 test_all_match git reset --hard merge-left &&
1032 test_all_match git status --porcelain=v2 &&
1033 test_all_match test_must_fail git $OPERATION merge-right &&
1034 test_all_match git status --porcelain=v2 &&
1035
1036 # Resolve the conflict in different ways:
1037 # 1. Revert to the base
1038 test_all_match git checkout base -- deep/deeper2/a &&
1039 test_all_match git status --porcelain=v2 &&
1040
1041 # 2. Add the file with conflict markers
1042 # NEEDSWORK: Even though the merge conflict removed the
1043 # SKIP_WORKTREE bit from the index entry for folder1/a, we should
1044 # warn that this is a problematic add.
1045 test_sparse_match test_must_fail git add folder1/a &&
1046 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
1047 test_sparse_unstaged folder1/a &&
1048 test_all_match git add --sparse folder1/a &&
1049 test_all_match git status --porcelain=v2 &&
1050
1051 # 3. Rename the file to another sparse filename and
1052 # accept conflict markers as resolved content.
1053 # NEEDSWORK: This mode now fails, because folder2/z is
1054 # outside of the sparse-checkout cone and does not match an
1055 # existing index entry with the SKIP_WORKTREE bit cleared.
1056 run_on_all mv folder2/a folder2/z &&
1057 test_sparse_match test_must_fail git add folder2 &&
1058 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
1059 test_sparse_unstaged folder2/z &&
1060 test_all_match git add --sparse folder2 &&
1061 test_all_match git status --porcelain=v2 &&
1062
1063 test_all_match git $OPERATION --continue &&
1064 test_all_match git status --porcelain=v2 &&
1065 test_all_match git rev-parse HEAD^{tree} || return 1
1066 done
1067 '
1068
1069 test_expect_success 'merge with outside renames' '
1070 init_repos &&
1071
1072 for type in out-to-out out-to-in in-to-out
1073 do
1074 test_all_match git reset --hard &&
1075 test_all_match git checkout -f -b merge-$type update-deep &&
1076 test_all_match git merge -m "$type" rename-$type &&
1077 test_all_match git rev-parse HEAD^{tree} || return 1
1078 done
1079 '
1080
1081 # Sparse-index fails to convert the index in the
1082 # final 'git cherry-pick' command.
1083 test_expect_success 'cherry-pick with conflicts' '
1084 init_repos &&
1085
1086 write_script edit-conflict <<-\EOF &&
1087 echo $1 >conflict
1088 EOF
1089
1090 test_all_match git checkout -b to-cherry-pick &&
1091 run_on_all ../edit-conflict ABC &&
1092 test_all_match git add conflict &&
1093 test_all_match git commit -m "conflict to pick" &&
1094
1095 test_all_match git checkout -B base HEAD~1 &&
1096 run_on_all ../edit-conflict DEF &&
1097 test_all_match git add conflict &&
1098 test_all_match git commit -m "conflict in base" &&
1099
1100 test_all_match test_must_fail git cherry-pick to-cherry-pick
1101 '
1102
1103 test_expect_success 'stash' '
1104 init_repos &&
1105
1106 write_script edit-contents <<-\EOF &&
1107 echo text >>$1
1108 EOF
1109
1110 # Stash a sparse directory (folder1)
1111 test_all_match git checkout -b test-branch rename-base &&
1112 test_all_match git reset --soft rename-out-to-out &&
1113 test_all_match git stash &&
1114 test_all_match git status --porcelain=v2 &&
1115
1116 # Apply the sparse directory stash without reinstating the index
1117 test_all_match git stash apply -q &&
1118 test_all_match git status --porcelain=v2 &&
1119
1120 # Reset to state where stash can be applied
1121 test_sparse_match git sparse-checkout reapply &&
1122 test_all_match git reset --hard rename-out-to-out &&
1123
1124 # Apply the sparse directory stash *with* reinstating the index
1125 test_all_match git stash apply --index -q &&
1126 test_all_match git status --porcelain=v2 &&
1127
1128 # Reset to state where we will get a conflict applying the stash
1129 test_sparse_match git sparse-checkout reapply &&
1130 test_all_match git reset --hard update-folder1 &&
1131
1132 # Apply the sparse directory stash with conflicts
1133 test_all_match test_must_fail git stash apply --index -q &&
1134 test_all_match test_must_fail git stash apply -q &&
1135 test_all_match git status --porcelain=v2 &&
1136
1137 # Reset to base branch
1138 test_sparse_match git sparse-checkout reapply &&
1139 test_all_match git reset --hard base &&
1140
1141 # Stash & unstash an untracked file outside of the sparse checkout
1142 # definition.
1143 run_on_sparse mkdir -p folder1 &&
1144 run_on_all ../edit-contents folder1/new &&
1145 test_all_match git stash -u &&
1146 test_all_match git status --porcelain=v2 &&
1147
1148 test_all_match git stash pop -q &&
1149 test_all_match git status --porcelain=v2
1150 '
1151
1152 test_expect_success 'checkout-index inside sparse definition' '
1153 init_repos &&
1154
1155 run_on_all rm -f deep/a &&
1156 test_all_match git checkout-index -- deep/a &&
1157 test_all_match git status --porcelain=v2 &&
1158
1159 echo test >>new-a &&
1160 run_on_all cp ../new-a a &&
1161 test_all_match test_must_fail git checkout-index -- a &&
1162 test_all_match git checkout-index -f -- a &&
1163 test_all_match git status --porcelain=v2
1164 '
1165
1166 test_expect_success 'checkout-index outside sparse definition' '
1167 init_repos &&
1168
1169 # Without --ignore-skip-worktree-bits, outside-of-cone files will trigger
1170 # an error
1171 test_sparse_match test_must_fail git checkout-index -- folder1/a &&
1172 test_i18ngrep "folder1/a has skip-worktree enabled" sparse-checkout-err &&
1173 test_path_is_missing folder1/a &&
1174
1175 # With --ignore-skip-worktree-bits, outside-of-cone files are checked out
1176 test_sparse_match git checkout-index --ignore-skip-worktree-bits -- folder1/a &&
1177 test_cmp sparse-checkout/folder1/a sparse-index/folder1/a &&
1178 test_cmp sparse-checkout/folder1/a full-checkout/folder1/a &&
1179
1180 run_on_sparse rm -rf folder1 &&
1181 echo test >new-a &&
1182 run_on_sparse mkdir -p folder1 &&
1183 run_on_all cp ../new-a folder1/a &&
1184
1185 test_all_match test_must_fail git checkout-index --ignore-skip-worktree-bits -- folder1/a &&
1186 test_all_match git checkout-index -f --ignore-skip-worktree-bits -- folder1/a &&
1187 test_cmp sparse-checkout/folder1/a sparse-index/folder1/a &&
1188 test_cmp sparse-checkout/folder1/a full-checkout/folder1/a
1189 '
1190
1191 test_expect_success 'checkout-index with folders' '
1192 init_repos &&
1193
1194 # Inside checkout definition
1195 test_all_match test_must_fail git checkout-index -f -- deep/ &&
1196
1197 # Outside checkout definition
1198 # Note: although all tests fail (as expected), the messaging differs. For
1199 # non-sparse index checkouts, the error is that the "file" does not appear
1200 # in the index; for sparse checkouts, the error is explicitly that the
1201 # entry is a sparse directory.
1202 run_on_all test_must_fail git checkout-index -f -- folder1/ &&
1203 test_cmp full-checkout-err sparse-checkout-err &&
1204 ! test_cmp full-checkout-err sparse-index-err &&
1205 grep "is a sparse directory" sparse-index-err
1206 '
1207
1208 test_expect_success 'checkout-index --all' '
1209 init_repos &&
1210
1211 test_all_match git checkout-index --all &&
1212 test_sparse_match test_path_is_missing folder1 &&
1213
1214 # --ignore-skip-worktree-bits will cause `skip-worktree` files to be
1215 # checked out, causing the outside-of-cone `folder1` to exist on-disk
1216 test_all_match git checkout-index --ignore-skip-worktree-bits --all &&
1217 test_all_match test_path_exists folder1
1218 '
1219
1220 test_expect_success 'clean' '
1221 init_repos &&
1222
1223 echo bogus >>.gitignore &&
1224 run_on_all cp ../.gitignore . &&
1225 test_all_match git add .gitignore &&
1226 test_all_match git commit -m "ignore bogus files" &&
1227
1228 run_on_sparse mkdir folder1 &&
1229 run_on_all mkdir -p deep/untracked-deep &&
1230 run_on_all touch folder1/bogus &&
1231 run_on_all touch folder1/untracked &&
1232 run_on_all touch deep/untracked-deep/bogus &&
1233 run_on_all touch deep/untracked-deep/untracked &&
1234
1235 test_all_match git status --porcelain=v2 &&
1236 test_all_match git clean -f &&
1237 test_all_match git status --porcelain=v2 &&
1238 test_sparse_match ls &&
1239 test_sparse_match ls folder1 &&
1240 run_on_all test_path_exists folder1/bogus &&
1241 run_on_all test_path_is_missing folder1/untracked &&
1242 run_on_all test_path_exists deep/untracked-deep/bogus &&
1243 run_on_all test_path_exists deep/untracked-deep/untracked &&
1244
1245 test_all_match git clean -fd &&
1246 test_all_match git status --porcelain=v2 &&
1247 test_sparse_match ls &&
1248 test_sparse_match ls folder1 &&
1249 run_on_all test_path_exists folder1/bogus &&
1250 run_on_all test_path_exists deep/untracked-deep/bogus &&
1251 run_on_all test_path_is_missing deep/untracked-deep/untracked &&
1252
1253 test_all_match git clean -xf &&
1254 test_all_match git status --porcelain=v2 &&
1255 test_sparse_match ls &&
1256 test_sparse_match ls folder1 &&
1257 run_on_all test_path_is_missing folder1/bogus &&
1258 run_on_all test_path_exists deep/untracked-deep/bogus &&
1259
1260 test_all_match git clean -xdf &&
1261 test_all_match git status --porcelain=v2 &&
1262 test_sparse_match ls &&
1263 test_sparse_match ls folder1 &&
1264 run_on_all test_path_is_missing deep/untracked-deep/bogus &&
1265
1266 test_sparse_match test_path_is_dir folder1
1267 '
1268
1269 for builtin in show rev-parse
1270 do
1271 test_expect_success "$builtin (cached blobs/trees)" "
1272 init_repos &&
1273
1274 test_all_match git $builtin :a &&
1275 test_all_match git $builtin :deep/a &&
1276 test_sparse_match git $builtin :folder1/a &&
1277
1278 # The error message differs depending on whether
1279 # the directory exists in the worktree.
1280 test_all_match test_must_fail git $builtin :deep/ &&
1281 test_must_fail git -C full-checkout $builtin :folder1/ &&
1282 test_sparse_match test_must_fail git $builtin :folder1/ &&
1283
1284 # Change the sparse cone for an extra case:
1285 run_on_sparse git sparse-checkout set deep/deeper1 &&
1286
1287 # deep/deeper2 is a sparse directory in the sparse index.
1288 test_sparse_match test_must_fail git $builtin :deep/deeper2/ &&
1289
1290 # deep/deeper2/deepest is not in the sparse index, but
1291 # will trigger an index expansion.
1292 test_sparse_match test_must_fail git $builtin :deep/deeper2/deepest/
1293 "
1294 done
1295
1296 test_expect_success 'submodule handling' '
1297 init_repos &&
1298
1299 test_sparse_match git sparse-checkout add modules &&
1300 test_all_match mkdir modules &&
1301 test_all_match touch modules/a &&
1302 test_all_match git add modules &&
1303 test_all_match git commit -m "add modules directory" &&
1304
1305 run_on_all git submodule add "$(pwd)/initial-repo" modules/sub &&
1306 test_all_match git commit -m "add submodule" &&
1307
1308 # having a submodule prevents "modules" from collapse
1309 test_sparse_match git sparse-checkout set deep/deeper1 &&
1310 git -C sparse-index ls-files --sparse --stage >cache &&
1311 grep "100644 .* modules/a" cache &&
1312 grep "160000 $(git -C initial-repo rev-parse HEAD) 0 modules/sub" cache
1313 '
1314
1315 # When working with a sparse index, some commands will need to expand the
1316 # index to operate properly. If those commands also write the index back
1317 # to disk, they need to convert the index to sparse before writing.
1318 # This test verifies that both of these events are logged in trace2 logs.
1319 test_expect_success 'sparse-index is expanded and converted back' '
1320 init_repos &&
1321
1322 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
1323 git -C sparse-index reset -- folder1/a &&
1324 test_region index convert_to_sparse trace2.txt &&
1325 test_region index ensure_full_index trace2.txt &&
1326
1327 # ls-files expands on read, but does not write.
1328 rm trace2.txt &&
1329 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1330 git -C sparse-index ls-files &&
1331 test_region index ensure_full_index trace2.txt
1332 '
1333
1334 test_expect_success 'index.sparse disabled inline uses full index' '
1335 init_repos &&
1336
1337 # When index.sparse is disabled inline with `git status`, the
1338 # index is expanded at the beginning of the execution then never
1339 # converted back to sparse. It is then written to disk as a full index.
1340 rm -f trace2.txt &&
1341 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1342 git -C sparse-index -c index.sparse=false status &&
1343 ! test_region index convert_to_sparse trace2.txt &&
1344 test_region index ensure_full_index trace2.txt &&
1345
1346 # Since index.sparse is set to true at a repo level, the index
1347 # is converted from full to sparse when read, then never expanded
1348 # over the course of `git status`. It is written to disk as a sparse
1349 # index.
1350 rm -f trace2.txt &&
1351 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1352 git -C sparse-index status &&
1353 test_region index convert_to_sparse trace2.txt &&
1354 ! test_region index ensure_full_index trace2.txt &&
1355
1356 # Now that the index has been written to disk as sparse, it is not
1357 # converted to sparse (or expanded to full) when read by `git status`.
1358 rm -f trace2.txt &&
1359 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1360 git -C sparse-index status &&
1361 ! test_region index convert_to_sparse trace2.txt &&
1362 ! test_region index ensure_full_index trace2.txt
1363 '
1364
1365 ensure_not_expanded () {
1366 rm -f trace2.txt &&
1367 if test -z "$WITHOUT_UNTRACKED_TXT"
1368 then
1369 echo >>sparse-index/untracked.txt
1370 fi &&
1371
1372 if test "$1" = "!"
1373 then
1374 shift &&
1375 test_must_fail env \
1376 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
1377 git -C sparse-index "$@" \
1378 >sparse-index-out \
1379 2>sparse-index-error || return 1
1380 else
1381 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
1382 git -C sparse-index "$@" \
1383 >sparse-index-out \
1384 2>sparse-index-error || return 1
1385 fi &&
1386 test_region ! index ensure_full_index trace2.txt
1387 }
1388
1389 test_expect_success 'sparse-index is not expanded' '
1390 init_repos &&
1391
1392 ensure_not_expanded status &&
1393 ensure_not_expanded ls-files --sparse &&
1394 ensure_not_expanded commit --allow-empty -m empty &&
1395 echo >>sparse-index/a &&
1396 ensure_not_expanded commit -a -m a &&
1397 echo >>sparse-index/a &&
1398 ensure_not_expanded commit --include a -m a &&
1399 echo >>sparse-index/deep/deeper1/a &&
1400 ensure_not_expanded commit --include deep/deeper1/a -m deeper &&
1401 ensure_not_expanded checkout rename-out-to-out &&
1402 ensure_not_expanded checkout - &&
1403 ensure_not_expanded switch rename-out-to-out &&
1404 ensure_not_expanded switch - &&
1405 ensure_not_expanded reset --hard &&
1406 ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
1407 ensure_not_expanded reset --hard &&
1408 ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
1409
1410 echo >>sparse-index/README.md &&
1411 ensure_not_expanded add -A &&
1412 echo >>sparse-index/extra.txt &&
1413 ensure_not_expanded add extra.txt &&
1414 echo >>sparse-index/untracked.txt &&
1415 ensure_not_expanded add . &&
1416
1417 ensure_not_expanded checkout-index -f a &&
1418 ensure_not_expanded checkout-index -f --all &&
1419 for ref in update-deep update-folder1 update-folder2 update-deep
1420 do
1421 echo >>sparse-index/README.md &&
1422 ensure_not_expanded reset --hard $ref || return 1
1423 done &&
1424
1425 ensure_not_expanded reset --mixed base &&
1426 ensure_not_expanded reset --hard update-deep &&
1427 ensure_not_expanded reset --keep base &&
1428 ensure_not_expanded reset --merge update-deep &&
1429 ensure_not_expanded reset --hard &&
1430
1431 ensure_not_expanded reset base -- deep/a &&
1432 ensure_not_expanded reset base -- nonexistent-file &&
1433 ensure_not_expanded reset deepest -- deep &&
1434
1435 # Although folder1 is outside the sparse definition, it exists as a
1436 # directory entry in the index, so the pathspec will not force the
1437 # index to be expanded.
1438 ensure_not_expanded reset deepest -- folder1 &&
1439 ensure_not_expanded reset deepest -- folder1/ &&
1440
1441 # Wildcard identifies only in-cone files, no index expansion
1442 ensure_not_expanded reset deepest -- deep/\* &&
1443
1444 # Wildcard identifies only full sparse directories, no index expansion
1445 ensure_not_expanded reset deepest -- folder\* &&
1446
1447 ensure_not_expanded clean -fd &&
1448
1449 ensure_not_expanded checkout -f update-deep &&
1450 test_config -C sparse-index pull.twohead ort &&
1451 (
1452 sane_unset GIT_TEST_MERGE_ALGORITHM &&
1453 for OPERATION in "merge -m merge" cherry-pick rebase
1454 do
1455 ensure_not_expanded merge -m merge update-folder1 &&
1456 ensure_not_expanded merge -m merge update-folder2 || return 1
1457 done
1458 )
1459 '
1460
1461 test_expect_success 'sparse-index is not expanded: merge conflict in cone' '
1462 init_repos &&
1463
1464 for side in right left
1465 do
1466 git -C sparse-index checkout -b expand-$side base &&
1467 echo $side >sparse-index/deep/a &&
1468 git -C sparse-index commit -a -m "$side" || return 1
1469 done &&
1470
1471 (
1472 sane_unset GIT_TEST_MERGE_ALGORITHM &&
1473 git -C sparse-index config pull.twohead ort &&
1474 ensure_not_expanded ! merge -m merged expand-right
1475 )
1476 '
1477
1478 test_expect_success 'sparse-index is not expanded: stash' '
1479 init_repos &&
1480
1481 echo >>sparse-index/a &&
1482 ensure_not_expanded stash &&
1483 ensure_not_expanded stash list &&
1484 ensure_not_expanded stash show stash@{0} &&
1485 ensure_not_expanded stash apply stash@{0} &&
1486 ensure_not_expanded stash drop stash@{0} &&
1487
1488 echo >>sparse-index/deep/new &&
1489 ensure_not_expanded stash -u &&
1490 (
1491 WITHOUT_UNTRACKED_TXT=1 &&
1492 ensure_not_expanded stash pop
1493 ) &&
1494
1495 ensure_not_expanded stash create &&
1496 oid=$(git -C sparse-index stash create) &&
1497 ensure_not_expanded stash store -m "test" $oid &&
1498 ensure_not_expanded reset --hard &&
1499 ensure_not_expanded stash pop
1500 '
1501
1502 test_expect_success 'sparse index is not expanded: diff' '
1503 init_repos &&
1504
1505 write_script edit-contents <<-\EOF &&
1506 echo text >>$1
1507 EOF
1508
1509 # Add file within cone
1510 test_sparse_match git sparse-checkout set deep &&
1511 run_on_all ../edit-contents deep/testfile &&
1512 test_all_match git add deep/testfile &&
1513 run_on_all ../edit-contents deep/testfile &&
1514
1515 test_all_match git diff &&
1516 test_all_match git diff --cached &&
1517 ensure_not_expanded diff &&
1518 ensure_not_expanded diff --cached &&
1519
1520 # Add file outside cone
1521 test_all_match git reset --hard &&
1522 run_on_all mkdir newdirectory &&
1523 run_on_all ../edit-contents newdirectory/testfile &&
1524 test_sparse_match git sparse-checkout set newdirectory &&
1525 test_all_match git add newdirectory/testfile &&
1526 run_on_all ../edit-contents newdirectory/testfile &&
1527 test_sparse_match git sparse-checkout set &&
1528
1529 test_all_match git diff &&
1530 test_all_match git diff --cached &&
1531 ensure_not_expanded diff &&
1532 ensure_not_expanded diff --cached &&
1533
1534 # Merge conflict outside cone
1535 # The sparse checkout will report a warning that is not in the
1536 # full checkout, so we use `run_on_all` instead of
1537 # `test_all_match`
1538 run_on_all git reset --hard &&
1539 test_all_match git checkout merge-left &&
1540 test_all_match test_must_fail git merge merge-right &&
1541
1542 test_all_match git diff &&
1543 test_all_match git diff --cached &&
1544 ensure_not_expanded diff &&
1545 ensure_not_expanded diff --cached
1546 '
1547
1548 test_expect_success 'sparse index is not expanded: show and rev-parse' '
1549 init_repos &&
1550
1551 ensure_not_expanded show :a &&
1552 ensure_not_expanded show :deep/a &&
1553 ensure_not_expanded rev-parse :a &&
1554 ensure_not_expanded rev-parse :deep/a
1555 '
1556
1557 test_expect_success 'sparse index is not expanded: update-index' '
1558 init_repos &&
1559
1560 deep_a_oid=$(git -C full-checkout rev-parse update-deep:deep/a) &&
1561 ensure_not_expanded update-index --cacheinfo 100644 $deep_a_oid deep/a &&
1562
1563 echo "test" >sparse-index/README.md &&
1564 echo "test2" >sparse-index/a &&
1565 rm -f sparse-index/deep/a &&
1566
1567 ensure_not_expanded update-index --add README.md &&
1568 ensure_not_expanded update-index a &&
1569 ensure_not_expanded update-index --remove deep/a &&
1570
1571 ensure_not_expanded reset --soft update-deep &&
1572 ensure_not_expanded update-index --add --remove --again
1573 '
1574
1575 test_expect_success 'sparse index is not expanded: blame' '
1576 init_repos &&
1577
1578 for file in a \
1579 deep/a \
1580 deep/deeper1/a \
1581 deep/deeper1/deepest/a
1582 do
1583 ensure_not_expanded blame $file || return 1
1584 done
1585 '
1586
1587 test_expect_success 'sparse index is not expanded: fetch/pull' '
1588 init_repos &&
1589
1590 git -C sparse-index remote add full "file://$(pwd)/full-checkout" &&
1591 ensure_not_expanded fetch full &&
1592 git -C full-checkout commit --allow-empty -m "for pull merge" &&
1593 git -C sparse-index commit --allow-empty -m "for pull merge" &&
1594 ensure_not_expanded pull full base
1595 '
1596
1597 test_expect_success 'sparse index is not expanded: read-tree' '
1598 init_repos &&
1599
1600 ensure_not_expanded checkout -b test-branch update-folder1 &&
1601 for MERGE_TREES in "base HEAD update-folder2" \
1602 "base HEAD rename-base" \
1603 "base update-folder2" \
1604 "base rename-base" \
1605 "update-folder2"
1606 do
1607 ensure_not_expanded read-tree -mu $MERGE_TREES &&
1608 ensure_not_expanded reset --hard || return 1
1609 done &&
1610
1611 rm -rf sparse-index/deep/deeper2 &&
1612 ensure_not_expanded add . &&
1613 ensure_not_expanded commit -m "test" &&
1614
1615 ensure_not_expanded read-tree --prefix=deep/deeper2 -u deepest
1616 '
1617
1618 test_expect_success 'ls-files' '
1619 init_repos &&
1620
1621 # Use a smaller sparse-checkout for reduced output
1622 test_sparse_match git sparse-checkout set &&
1623
1624 # Behavior agrees by default. Sparse index is expanded.
1625 test_all_match git ls-files &&
1626
1627 # With --sparse, the sparse index data changes behavior.
1628 git -C sparse-index ls-files --sparse >actual &&
1629
1630 cat >expect <<-\EOF &&
1631 a
1632 before/
1633 deep/
1634 e
1635 folder1-
1636 folder1.x
1637 folder1/
1638 folder10
1639 folder2/
1640 g
1641 x/
1642 z
1643 EOF
1644
1645 test_cmp expect actual &&
1646
1647 # With --sparse and no sparse index, nothing changes.
1648 git -C sparse-checkout ls-files >dense &&
1649 git -C sparse-checkout ls-files --sparse >sparse &&
1650 test_cmp dense sparse &&
1651
1652 # Set up a strange condition of having a file edit
1653 # outside of the sparse-checkout cone. We want to verify
1654 # that all modes handle this the same, and detect the
1655 # modification.
1656 write_script edit-content <<-\EOF &&
1657 mkdir -p folder1 &&
1658 echo content >>folder1/a
1659 EOF
1660 run_on_all ../edit-content &&
1661
1662 test_all_match git ls-files --modified &&
1663
1664 git -C sparse-index ls-files --sparse --modified >sparse-index-out &&
1665 cat >expect <<-\EOF &&
1666 folder1/a
1667 EOF
1668 test_cmp expect sparse-index-out &&
1669
1670 # Add folder1 to the sparse-checkout cone and
1671 # check that ls-files shows the expanded files.
1672 test_sparse_match git sparse-checkout add folder1 &&
1673 test_all_match git ls-files --modified &&
1674
1675 test_all_match git ls-files &&
1676 git -C sparse-index ls-files --sparse >actual &&
1677
1678 cat >expect <<-\EOF &&
1679 a
1680 before/
1681 deep/
1682 e
1683 folder1-
1684 folder1.x
1685 folder1/0/0/0
1686 folder1/0/1
1687 folder1/a
1688 folder10
1689 folder2/
1690 g
1691 x/
1692 z
1693 EOF
1694
1695 test_cmp expect actual &&
1696
1697 # Double-check index expansion is avoided
1698 ensure_not_expanded ls-files --sparse
1699 '
1700
1701 test_expect_success 'sparse index is not expanded: sparse-checkout' '
1702 init_repos &&
1703
1704 ensure_not_expanded sparse-checkout set deep/deeper2 &&
1705 ensure_not_expanded sparse-checkout set deep/deeper1 &&
1706 ensure_not_expanded sparse-checkout set deep &&
1707 ensure_not_expanded sparse-checkout add folder1 &&
1708 ensure_not_expanded sparse-checkout set deep/deeper1 &&
1709 ensure_not_expanded sparse-checkout set folder2 &&
1710
1711 # Demonstrate that the checks that "folder1/a" is a file
1712 # do not cause a sparse-index expansion (since it is in the
1713 # sparse-checkout cone).
1714 echo >>sparse-index/folder2/a &&
1715 git -C sparse-index add folder2/a &&
1716
1717 ensure_not_expanded sparse-checkout add folder1 &&
1718
1719 # Skip checks here, since deep/deeper1 is inside a sparse directory
1720 # that must be expanded to check whether `deep/deeper1` is a file
1721 # or not.
1722 ensure_not_expanded sparse-checkout set --skip-checks deep/deeper1 &&
1723 ensure_not_expanded sparse-checkout set
1724 '
1725
1726 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
1727 # in this scenario, but it shouldn't.
1728 test_expect_success 'reset mixed and checkout orphan' '
1729 init_repos &&
1730
1731 test_all_match git checkout rename-out-to-in &&
1732
1733 # Sparse checkouts do not agree with full checkouts about
1734 # how to report a directory/file conflict during a reset.
1735 # This command would fail with test_all_match because the
1736 # full checkout reports "T folder1/0/1" while a sparse
1737 # checkout reports "D folder1/0/1". This matches because
1738 # the sparse checkouts skip "adding" the other side of
1739 # the conflict.
1740 test_sparse_match git reset --mixed HEAD~1 &&
1741 test_sparse_match git ls-files --stage &&
1742 test_sparse_match git status --porcelain=v2 &&
1743
1744 # At this point, sparse-checkouts behave differently
1745 # from the full-checkout.
1746 test_sparse_match git checkout --orphan new-branch &&
1747 test_sparse_match git ls-files --stage &&
1748 test_sparse_match git status --porcelain=v2
1749 '
1750
1751 test_expect_success 'add everything with deep new file' '
1752 init_repos &&
1753
1754 run_on_sparse git sparse-checkout set deep/deeper1/deepest &&
1755
1756 run_on_all touch deep/deeper1/x &&
1757 test_all_match git add . &&
1758 test_all_match git status --porcelain=v2
1759 '
1760
1761 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
1762 # directory/file conflicts, even without sparse-checkout. Use this
1763 # test only as a documentation of the incorrect behavior, not a
1764 # measure of how it _should_ behave.
1765 test_expect_success 'checkout behaves oddly with df-conflict-1' '
1766 init_repos &&
1767
1768 test_sparse_match git sparse-checkout disable &&
1769
1770 write_script edit-content <<-\EOF &&
1771 echo content >>folder1/larger-content
1772 git add folder1
1773 EOF
1774
1775 run_on_all ../edit-content &&
1776 test_all_match git status --porcelain=v2 &&
1777
1778 git -C sparse-checkout sparse-checkout init --cone &&
1779 git -C sparse-index sparse-checkout init --cone --sparse-index &&
1780
1781 test_all_match git status --porcelain=v2 &&
1782
1783 # This checkout command should fail, because we have a staged
1784 # change to folder1/larger-content, but the destination changes
1785 # folder1 to a file.
1786 git -C full-checkout checkout df-conflict-1 \
1787 1>full-checkout-out \
1788 2>full-checkout-err &&
1789 git -C sparse-checkout checkout df-conflict-1 \
1790 1>sparse-checkout-out \
1791 2>sparse-checkout-err &&
1792 git -C sparse-index checkout df-conflict-1 \
1793 1>sparse-index-out \
1794 2>sparse-index-err &&
1795
1796 # Instead, the checkout deletes the folder1 file and adds the
1797 # folder1/larger-content file, leaving all other paths that were
1798 # in folder1/ as deleted (without any warning).
1799 cat >expect <<-EOF &&
1800 D folder1
1801 A folder1/larger-content
1802 EOF
1803 test_cmp expect full-checkout-out &&
1804 test_cmp expect sparse-checkout-out &&
1805
1806 # The sparse-index reports no output
1807 test_must_be_empty sparse-index-out &&
1808
1809 # stderr: Switched to branch df-conflict-1
1810 test_cmp full-checkout-err sparse-checkout-err &&
1811 test_cmp full-checkout-err sparse-checkout-err
1812 '
1813
1814 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
1815 # directory/file conflicts, even without sparse-checkout. Use this
1816 # test only as a documentation of the incorrect behavior, not a
1817 # measure of how it _should_ behave.
1818 test_expect_success 'checkout behaves oddly with df-conflict-2' '
1819 init_repos &&
1820
1821 test_sparse_match git sparse-checkout disable &&
1822
1823 write_script edit-content <<-\EOF &&
1824 echo content >>folder2/larger-content
1825 git add folder2
1826 EOF
1827
1828 run_on_all ../edit-content &&
1829 test_all_match git status --porcelain=v2 &&
1830
1831 git -C sparse-checkout sparse-checkout init --cone &&
1832 git -C sparse-index sparse-checkout init --cone --sparse-index &&
1833
1834 test_all_match git status --porcelain=v2 &&
1835
1836 # This checkout command should fail, because we have a staged
1837 # change to folder1/larger-content, but the destination changes
1838 # folder1 to a file.
1839 git -C full-checkout checkout df-conflict-2 \
1840 1>full-checkout-out \
1841 2>full-checkout-err &&
1842 git -C sparse-checkout checkout df-conflict-2 \
1843 1>sparse-checkout-out \
1844 2>sparse-checkout-err &&
1845 git -C sparse-index checkout df-conflict-2 \
1846 1>sparse-index-out \
1847 2>sparse-index-err &&
1848
1849 # The full checkout deviates from the df-conflict-1 case here!
1850 # It drops the change to folder1/larger-content and leaves the
1851 # folder1 path as-is on disk. The sparse-index behaves the same.
1852 test_must_be_empty full-checkout-out &&
1853 test_must_be_empty sparse-index-out &&
1854
1855 # In the sparse-checkout case, the checkout deletes the folder1
1856 # file and adds the folder1/larger-content file, leaving all other
1857 # paths that were in folder1/ as deleted (without any warning).
1858 cat >expect <<-EOF &&
1859 D folder2
1860 A folder2/larger-content
1861 EOF
1862 test_cmp expect sparse-checkout-out &&
1863
1864 # Switched to branch df-conflict-1
1865 test_cmp full-checkout-err sparse-checkout-err &&
1866 test_cmp full-checkout-err sparse-index-err
1867 '
1868
1869 test_expect_success 'mv directory from out-of-cone to in-cone' '
1870 init_repos &&
1871
1872 # <source> as a sparse directory (or SKIP_WORKTREE_DIR without enabling
1873 # sparse index).
1874 test_all_match git mv --sparse folder1 deep &&
1875 test_all_match git status --porcelain=v2 &&
1876 test_sparse_match git ls-files -t &&
1877 git -C sparse-checkout ls-files -t >actual &&
1878 grep -e "H deep/folder1/0/0/0" actual &&
1879 grep -e "H deep/folder1/0/1" actual &&
1880 grep -e "H deep/folder1/a" actual &&
1881
1882 test_all_match git reset --hard &&
1883
1884 # <source> as a directory deeper than sparse index boundary (where
1885 # sparse index will expand).
1886 test_sparse_match git mv --sparse folder1/0 deep &&
1887 test_sparse_match git status --porcelain=v2 &&
1888 test_sparse_match git ls-files -t &&
1889 git -C sparse-checkout ls-files -t >actual &&
1890 grep -e "H deep/0/0/0" actual &&
1891 grep -e "H deep/0/1" actual
1892 '
1893
1894 test_expect_success 'rm pathspec inside sparse definition' '
1895 init_repos &&
1896
1897 test_all_match git rm deep/a &&
1898 test_all_match git status --porcelain=v2 &&
1899
1900 # test wildcard
1901 run_on_all git reset --hard &&
1902 test_all_match git rm deep/* &&
1903 test_all_match git status --porcelain=v2 &&
1904
1905 # test recursive rm
1906 run_on_all git reset --hard &&
1907 test_all_match git rm -r deep &&
1908 test_all_match git status --porcelain=v2
1909 '
1910
1911 test_expect_success 'rm pathspec outside sparse definition' '
1912 init_repos &&
1913
1914 for file in folder1/a folder1/0/1
1915 do
1916 test_sparse_match test_must_fail git rm $file &&
1917 test_sparse_match test_must_fail git rm --cached $file &&
1918 test_sparse_match git rm --sparse $file &&
1919 test_sparse_match git status --porcelain=v2 || return 1
1920 done &&
1921
1922 cat >folder1-full <<-EOF &&
1923 rm ${SQ}folder1/0/0/0${SQ}
1924 rm ${SQ}folder1/0/1${SQ}
1925 rm ${SQ}folder1/a${SQ}
1926 EOF
1927
1928 cat >folder1-sparse <<-EOF &&
1929 rm ${SQ}folder1/${SQ}
1930 EOF
1931
1932 # test wildcard
1933 run_on_sparse git reset --hard &&
1934 run_on_sparse git sparse-checkout reapply &&
1935 test_sparse_match test_must_fail git rm folder1/* &&
1936 run_on_sparse git rm --sparse folder1/* &&
1937 test_cmp folder1-full sparse-checkout-out &&
1938 test_cmp folder1-sparse sparse-index-out &&
1939 test_sparse_match git status --porcelain=v2 &&
1940
1941 # test recursive rm
1942 run_on_sparse git reset --hard &&
1943 run_on_sparse git sparse-checkout reapply &&
1944 test_sparse_match test_must_fail git rm --sparse folder1 &&
1945 run_on_sparse git rm --sparse -r folder1 &&
1946 test_cmp folder1-full sparse-checkout-out &&
1947 test_cmp folder1-sparse sparse-index-out &&
1948 test_sparse_match git status --porcelain=v2
1949 '
1950
1951 test_expect_success 'rm pathspec expands index when necessary' '
1952 init_repos &&
1953
1954 # in-cone pathspec (do not expand)
1955 ensure_not_expanded rm "deep/deep*" &&
1956 test_must_be_empty sparse-index-err &&
1957
1958 # out-of-cone pathspec (expand)
1959 ! ensure_not_expanded rm --sparse "folder1/a*" &&
1960 test_must_be_empty sparse-index-err &&
1961
1962 # pathspec that should expand index
1963 ! ensure_not_expanded rm "*/a" &&
1964 test_must_be_empty sparse-index-err &&
1965
1966 ! ensure_not_expanded rm "**a" &&
1967 test_must_be_empty sparse-index-err
1968 '
1969
1970 test_expect_success 'sparse index is not expanded: rm' '
1971 init_repos &&
1972
1973 ensure_not_expanded rm deep/a &&
1974
1975 # test in-cone wildcard
1976 git -C sparse-index reset --hard &&
1977 ensure_not_expanded rm deep/* &&
1978
1979 # test recursive rm
1980 git -C sparse-index reset --hard &&
1981 ensure_not_expanded rm -r deep
1982 '
1983
1984 test_done