3 test_description
='compare full workdir to sparse workdir'
10 test_expect_success
'setup' '
11 git init initial-repo &&
13 GIT_TEST_SPARSE_INDEX=0 &&
16 echo "after deep" >e &&
17 echo "after folder1" >g &&
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 &&
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 &&
47 cp -r deep/deeper1/0 folder1 &&
48 cp -r deep/deeper1/0 folder2 &&
49 echo >>folder1/0/0/0 &&
52 git commit -m "initial commit" &&
53 git checkout -b base &&
54 for dir in folder1 folder2 deep
56 git checkout -b update-$dir base &&
57 echo "updated $dir" >$dir/a &&
58 git commit -a -m "update $dir" || return 1
61 git checkout -b rename-base base &&
62 cat >folder1/larger-content <<-\EOF &&
69 cp folder1/larger-content folder2/ &&
70 cp folder1/larger-content deep/deeper1/ &&
72 git commit -m "add interesting rename content" &&
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 &&
79 echo stuff >>deep/deeper1/a &&
81 git commit -m "rename folder1/... to folder2/..." &&
83 git checkout -b rename-out-to-in rename-base &&
84 mv folder1/a deep/deeper1/b &&
85 echo more stuff >>deep/deeper1/a &&
88 echo >>folder2/0/1/1 &&
89 mv folder1/larger-content deep/deeper1/edited-content &&
90 echo >>deep/deeper1/edited-content &&
92 git commit -m "rename folder1/... to deep/deeper1/..." &&
94 git checkout -b rename-in-to-out rename-base &&
95 mv deep/deeper1/a folder1/b &&
99 mv deep/deeper1/larger-content folder1/edited-content &&
100 echo >>folder1/edited-content &&
102 git commit -m "rename deep/deeper1/... to folder1/..." &&
104 git checkout -b df-conflict-1 base &&
106 echo content >folder1 &&
108 git commit -m "dir to file" &&
110 git checkout -b df-conflict-2 base &&
112 echo content >folder2 &&
114 git commit -m "dir to file" &&
116 git checkout -b fd-conflict base &&
121 git commit -m "file to dir" &&
123 for side in left right
125 git checkout -b merge-$side base &&
126 echo $side >>deep/deeper2/a &&
127 echo $side >>folder1/a &&
128 echo $side >>folder2/a &&
130 git commit -m "$side" || return 1
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" &&
139 git checkout -f base &&
145 rm -rf full-checkout sparse-checkout sparse-index
&&
147 # create repos in initial state
148 cp -r initial-repo full-checkout
&&
149 git
-C full-checkout
reset --hard &&
151 cp -r initial-repo sparse-checkout
&&
152 git
-C sparse-checkout
reset --hard &&
154 cp -r initial-repo sparse-index
&&
155 git
-C sparse-index
reset --hard &&
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
167 cd sparse-checkout
&&
168 GIT_PROGRESS_DELAY
=100000 "$@" >..
/sparse-checkout-out
2>..
/sparse-checkout-err
172 GIT_PROGRESS_DELAY
=100000 "$@" >..
/sparse-index-out
2>..
/sparse-index-err
179 GIT_PROGRESS_DELAY
=100000 "$@" >..
/full-checkout-out
2>..
/full-checkout-err
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
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
198 test_sparse_unstaged
() {
200 for repo
in sparse-checkout sparse-index
202 # Skip "unmerged" paths
203 git
-C $repo diff --staged --diff-filter=u
-- "$file" >diff &&
204 test_must_be_empty
diff ||
return 1
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
() {
215 git
-C sparse-index sparse-checkout
set --skip-checks $CONE_DIRS &&
216 git
-C sparse-index ls-files
--sparse --stage >cache
&&
218 # Check that the directories outside of the sparse-checkout cone
219 # have sparse directory entries.
220 for dir
in $SPARSE_DIRS
222 TREE
=$
(git
-C sparse-index rev-parse HEAD
:$dir) &&
223 grep "040000 $TREE 0 $dir/" cache \
227 # Check that the directories in the sparse-checkout cone
228 # are not sparse directory entries.
229 for dir
in $CONE_DIRS
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 \
239 test_expect_success
'sparse-index contents' '
242 # Remove deep, add three other directories.
243 test_sparse_checkout_set \
244 "folder1 folder2 x" \
247 # Remove folder1, add deep
248 test_sparse_checkout_set \
252 # Replace deep with deep/deeper2 (dropping deep/deeper1)
254 test_sparse_checkout_set \
255 "deep/deeper2 folder1 folder2 x" \
256 "before deep/deeper1" &&
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" &&
266 # Drop down to only files at root
267 test_sparse_checkout_set \
269 "before deep folder1 folder2 x" &&
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
276 test_expect_success
'expanded in-memory index matches full index' '
278 test_sparse_match git ls-files --stage
281 test_expect_success
'root directory cannot be sparse' '
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 &&
289 # Verify sparse directories still present, root directory is not sparse
290 cat >expect <<-EOF &&
296 git -C sparse-index ls-files --sparse >actual &&
297 test_cmp expect actual
300 test_expect_success
'status with options' '
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
316 test_expect_success
'status with diff in unexpanded sparse directory' '
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
323 test_expect_success
'status reports sparse-checkout' '
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
331 test_expect_success
'add, commit, checkout' '
334 write_script edit-contents <<-\EOF &&
337 run_on_all ../edit-contents README.md &&
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" &&
343 test_all_match git checkout HEAD~1 &&
344 test_all_match git checkout - &&
346 run_on_all ../edit-contents README.md &&
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" &&
352 test_all_match git checkout HEAD~1 &&
353 test_all_match git checkout - &&
355 run_on_all ../edit-contents deep/newfile &&
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" &&
363 test_all_match git checkout HEAD~1 &&
364 test_all_match git checkout -
367 test_expect_success
'deep changes during checkout' '
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
375 test_expect_success
'checkout with modified sparse directory' '
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
383 test_expect_success
'add outside sparse cone' '
386 run_on_sparse mkdir folder1 &&
387 run_on_sparse ../edit-contents folder1/a &&
388 run_on_sparse ../edit-contents folder1/newfile &&
389 test_sparse_match test_must_fail git add folder1/a &&
390 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
391 test_sparse_unstaged folder1/a &&
392 test_sparse_match test_must_fail git add folder1/newfile &&
393 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
394 test_sparse_unstaged folder1/newfile
397 test_expect_success
'commit including unstaged changes' '
400 write_script edit-file <<-\EOF &&
404 run_on_all ../edit-file 1 a &&
405 run_on_all ../edit-file 1 deep/a &&
407 test_all_match git commit -m "-a" -a &&
408 test_all_match git status --porcelain=v2 &&
410 run_on_all ../edit-file 2 a &&
411 run_on_all ../edit-file 2 deep/a &&
413 test_all_match git commit -m "--include" --include deep/a &&
414 test_all_match git status --porcelain=v2 &&
415 test_all_match git commit -m "--include" --include a &&
416 test_all_match git status --porcelain=v2 &&
418 run_on_all ../edit-file 3 a &&
419 run_on_all ../edit-file 3 deep/a &&
421 test_all_match git commit -m "--amend" -a --amend &&
422 test_all_match git status --porcelain=v2
425 test_expect_success
'status/add: outside sparse cone' '
428 # folder1 is at HEAD, but outside the sparse cone
429 run_on_sparse mkdir folder1 &&
430 cp initial-repo/folder1/a sparse-checkout/folder1/a &&
431 cp initial-repo/folder1/a sparse-index/folder1/a &&
433 test_sparse_match git status &&
435 write_script edit-contents <<-\EOF &&
438 run_on_all ../edit-contents folder1/a &&
439 run_on_all ../edit-contents folder1/new &&
441 test_sparse_match git status --porcelain=v2 &&
443 # Adding the path outside of the sparse-checkout cone should fail.
444 test_sparse_match test_must_fail git add folder1/a &&
445 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
446 test_sparse_unstaged folder1/a &&
447 test_all_match git add --refresh folder1/a &&
448 test_must_be_empty sparse-checkout-err &&
449 test_sparse_unstaged folder1/a &&
450 test_sparse_match test_must_fail git add folder1/new &&
451 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
452 test_sparse_unstaged folder1/new &&
453 test_sparse_match git add --sparse folder1/a &&
454 test_sparse_match git add --sparse folder1/new &&
456 test_all_match git add --sparse . &&
457 test_all_match git status --porcelain=v2 &&
458 test_all_match git commit -m folder1/new &&
459 test_all_match git rev-parse HEAD^{tree} &&
461 run_on_all ../edit-contents folder1/newer &&
462 test_all_match git add --sparse folder1/ &&
463 test_all_match git status --porcelain=v2 &&
464 test_all_match git commit -m folder1/newer &&
465 test_all_match git rev-parse HEAD^{tree}
468 test_expect_success
'checkout and reset --hard' '
471 test_all_match git checkout update-folder1 &&
472 test_all_match git status --porcelain=v2 &&
474 test_all_match git checkout update-deep &&
475 test_all_match git status --porcelain=v2 &&
477 test_all_match git checkout -b reset-test &&
478 test_all_match git reset --hard deepest &&
479 test_all_match git reset --hard update-folder1 &&
480 test_all_match git reset --hard update-folder2
483 test_expect_success
'diff --cached' '
486 write_script edit-contents <<-\EOF &&
487 echo text >>README.md
489 run_on_all ../edit-contents &&
491 test_all_match git diff &&
492 test_all_match git diff --cached &&
493 test_all_match git add README.md &&
494 test_all_match git diff &&
495 test_all_match git diff --cached
498 # NEEDSWORK: sparse-checkout behaves differently from full-checkout when
499 # running this test with 'df-conflict-2' after 'df-conflict-1'.
500 test_expect_success
'diff with renames and conflicts' '
503 for branch in rename-out-to-out \
509 test_all_match git checkout rename-base &&
510 test_all_match git checkout $branch -- . &&
511 test_all_match git status --porcelain=v2 &&
512 test_all_match git diff --cached --no-renames &&
513 test_all_match git diff --cached --find-renames || return 1
517 test_expect_success
'diff with directory/file conflicts' '
520 for branch in rename-out-to-out \
527 git -C full-checkout reset --hard &&
528 test_sparse_match git reset --hard &&
529 test_all_match git checkout $branch &&
530 test_all_match git checkout rename-base -- . &&
531 test_all_match git status --porcelain=v2 &&
532 test_all_match git diff --cached --no-renames &&
533 test_all_match git diff --cached --find-renames || return 1
537 test_expect_success
'log with pathspec outside sparse definition' '
540 test_all_match git log -- a &&
541 test_all_match git log -- folder1/a &&
542 test_all_match git log -- folder2/a &&
543 test_all_match git log -- deep/a &&
544 test_all_match git log -- deep/deeper1/a &&
545 test_all_match git log -- deep/deeper1/deepest/a &&
547 test_all_match git checkout update-folder1 &&
548 test_all_match git log -- folder1/a
551 test_expect_success
'blame with pathspec inside sparse definition' '
557 deep/deeper1/deepest/a
559 test_all_match git blame $file
563 # Without a revision specified, blame will error if passed any file that
564 # is not present in the working directory (even if the file is tracked).
565 # Here we just verify that this is also true with sparse checkouts.
566 test_expect_success
'blame with pathspec outside sparse definition' '
568 test_sparse_match git sparse-checkout set &&
573 deep/deeper1/deepest/a
575 test_sparse_match test_must_fail git blame $file &&
576 cat >expect <<-EOF &&
577 fatal: Cannot lstat '"'"'$file'"'"': No such file or directory
579 # We compare sparse-checkout-err and sparse-index-err in
580 # `test_sparse_match`. Given we know they are the same, we
581 # only check the content of sparse-index-err here.
582 test_cmp expect sparse-index-err
586 test_expect_success
'checkout and reset (mixed)' '
589 test_all_match git checkout -b reset-test update-deep &&
590 test_all_match git reset deepest &&
592 # Because skip-worktree is preserved, resetting to update-folder1
593 # will show worktree changes for folder1/a in full-checkout, but not
594 # in sparse-checkout or sparse-index.
595 git -C full-checkout reset update-folder1 >full-checkout-out &&
596 test_sparse_match git reset update-folder1 &&
597 grep "M folder1/a" full-checkout-out &&
598 ! grep "M folder1/a" sparse-checkout-out &&
599 run_on_sparse test_path_is_missing folder1
602 test_expect_success
'checkout and reset (merge)' '
605 write_script edit-contents <<-\EOF &&
609 test_all_match git checkout -b reset-test update-deep &&
610 run_on_all ../edit-contents a &&
611 test_all_match git reset --merge deepest &&
612 test_all_match git status --porcelain=v2 &&
614 test_all_match git reset --hard update-deep &&
615 run_on_all ../edit-contents deep/a &&
616 test_all_match test_must_fail git reset --merge deepest
619 test_expect_success
'checkout and reset (keep)' '
622 write_script edit-contents <<-\EOF &&
626 test_all_match git checkout -b reset-test update-deep &&
627 run_on_all ../edit-contents a &&
628 test_all_match git reset --keep deepest &&
629 test_all_match git status --porcelain=v2 &&
631 test_all_match git reset --hard update-deep &&
632 run_on_all ../edit-contents deep/a &&
633 test_all_match test_must_fail git reset --keep deepest
636 test_expect_success
'reset with pathspecs inside sparse definition' '
639 write_script edit-contents <<-\EOF &&
643 test_all_match git checkout -b reset-test update-deep &&
644 run_on_all ../edit-contents deep/a &&
646 test_all_match git reset base -- deep/a &&
647 test_all_match git status --porcelain=v2 &&
649 test_all_match git reset base -- nonexistent-file &&
650 test_all_match git status --porcelain=v2 &&
652 test_all_match git reset deepest -- deep &&
653 test_all_match git status --porcelain=v2
656 # Although the working tree differs between full and sparse checkouts after
657 # reset, the state of the index is the same.
658 test_expect_success
'reset with pathspecs outside sparse definition' '
660 test_all_match git checkout -b reset-test base &&
662 test_sparse_match git reset update-folder1 -- folder1 &&
663 git -C full-checkout reset update-folder1 -- folder1 &&
664 test_all_match git ls-files -s -- folder1 &&
666 test_sparse_match git reset update-folder2 -- folder2/a &&
667 git -C full-checkout reset update-folder2 -- folder2/a &&
668 test_all_match git ls-files -s -- folder2/a
671 test_expect_success
'reset with wildcard pathspec' '
674 test_all_match git reset update-deep -- deep\* &&
675 test_all_match git ls-files -s -- deep &&
677 test_all_match git reset deepest -- deep\*\*\* &&
678 test_all_match git ls-files -s -- deep &&
680 # The following `git reset`s result in updating the index on files with
681 # `skip-worktree` enabled. To avoid failing due to discrepencies in reported
682 # "modified" files, `test_sparse_match` reset is performed separately from
683 # "full-checkout" reset, then the index contents of all repos are verified.
685 test_sparse_match git reset update-folder1 -- \*/a &&
686 git -C full-checkout reset update-folder1 -- \*/a &&
687 test_all_match git ls-files -s -- deep/a folder1/a &&
689 test_sparse_match git reset update-folder2 -- folder\* &&
690 git -C full-checkout reset update-folder2 -- folder\* &&
691 test_all_match git ls-files -s -- folder10 folder1 folder2 &&
693 test_sparse_match git reset base -- folder1/\* &&
694 git -C full-checkout reset base -- folder1/\* &&
695 test_all_match git ls-files -s -- folder1
698 test_expect_success
'reset hard with removed sparse dir' '
701 run_on_all git rm -r --sparse folder1 &&
702 test_all_match git status --porcelain=v2 &&
704 test_all_match git reset --hard &&
705 test_all_match git status --porcelain=v2 &&
707 cat >expect <<-\EOF &&
711 git -C sparse-index ls-files --sparse folder1 >out &&
715 test_expect_success
'update-index modify outside sparse definition' '
718 write_script edit-contents <<-\EOF &&
722 # Create & modify folder1/a
723 # Note that this setup is a manual way of reaching the erroneous
724 # condition in which a `skip-worktree` enabled, outside-of-cone file
725 # exists on disk. It is used here to ensure `update-index` is stable
726 # and behaves predictably if such a condition occurs.
727 run_on_sparse mkdir -p folder1 &&
728 run_on_sparse cp ../initial-repo/folder1/a folder1/a &&
729 run_on_all ../edit-contents folder1/a &&
731 # If file has skip-worktree enabled, but the file is present, it is
732 # treated the same as if skip-worktree is disabled
733 test_all_match git status --porcelain=v2 &&
734 test_all_match git update-index folder1/a &&
735 test_all_match git status --porcelain=v2 &&
737 # When skip-worktree is disabled (even on files outside sparse cone), file
738 # is updated in the index
739 test_sparse_match git update-index --no-skip-worktree folder1/a &&
740 test_all_match git status --porcelain=v2 &&
741 test_all_match git update-index folder1/a &&
742 test_all_match git status --porcelain=v2
745 test_expect_success
'update-index --add outside sparse definition' '
748 write_script edit-contents <<-\EOF &&
752 # Create folder1, add new file
753 run_on_sparse mkdir -p folder1 &&
754 run_on_all ../edit-contents folder1/b &&
756 # The *untracked* out-of-cone file is added to the index because it does
757 # not have a `skip-worktree` bit to signal that it should be ignored
758 # (unlike in `git add`, which will fail due to the file being outside
759 # the sparse checkout definition).
760 test_all_match git update-index --add folder1/b &&
761 test_all_match git status --porcelain=v2
764 # NEEDSWORK: `--remove`, unlike the rest of `update-index`, does not ignore
765 # `skip-worktree` entries by default and will remove them from the index.
766 # The `--ignore-skip-worktree-entries` flag must be used in conjunction with
767 # `--remove` to ignore the `skip-worktree` entries and prevent their removal
769 test_expect_success
'update-index --remove outside sparse definition' '
772 # When --ignore-skip-worktree-entries is _not_ specified:
773 # out-of-cone, not-on-disk files are removed from the index
774 test_sparse_match git update-index --remove folder1/a &&
775 cat >expect <<-EOF &&
778 test_sparse_match git diff --cached --name-status &&
779 test_cmp expect sparse-checkout-out &&
782 test_all_match git reset --hard &&
784 # When --ignore-skip-worktree-entries is specified, out-of-cone
785 # (skip-worktree) files are ignored
786 test_sparse_match git update-index --remove --ignore-skip-worktree-entries folder1/a &&
787 test_sparse_match git diff --cached --name-status &&
788 test_must_be_empty sparse-checkout-out &&
791 test_all_match git reset --hard &&
793 # --force-remove supercedes --ignore-skip-worktree-entries, removing
794 # a skip-worktree file from the index (and disk) when both are specified
796 test_sparse_match git update-index --force-remove --ignore-skip-worktree-entries folder1/a &&
797 cat >expect <<-EOF &&
800 test_sparse_match git diff --cached --name-status &&
801 test_cmp expect sparse-checkout-out
804 test_expect_success
'update-index with directories' '
807 # update-index will exit silently when provided with a directory name
808 # containing a trailing slash
809 test_all_match git update-index deep/ folder1/ &&
810 grep "Ignoring path deep/" sparse-checkout-err &&
811 grep "Ignoring path folder1/" sparse-checkout-err &&
813 # When update-index is given a directory name WITHOUT a trailing slash, it will
814 # behave in different ways depending on the status of the directory on disk:
815 # * if it exists, the command exits with an error ("add individual files instead")
816 # * if it does NOT exist (e.g., in a sparse-checkout), it is assumed to be a
817 # file and either triggers an error ("does not exist and --remove not passed")
818 # or is ignored completely (when using --remove)
819 test_all_match test_must_fail git update-index deep &&
820 run_on_all test_must_fail git update-index folder1 &&
821 test_must_fail git -C full-checkout update-index --remove folder1 &&
822 test_sparse_match git update-index --remove folder1 &&
823 test_all_match git status --porcelain=v2
826 test_expect_success
'update-index --again file outside sparse definition' '
829 test_all_match git checkout -b test-reupdate &&
831 # Update HEAD without modifying the index to introduce a difference in
833 test_sparse_match git reset --soft update-folder1 &&
835 # Because folder1/a differs in the index vs HEAD,
836 # `git update-index --no-skip-worktree --again` will effectively perform
837 # `git update-index --no-skip-worktree folder1/a` and remove the skip-worktree
838 # flag from folder1/a
839 test_sparse_match git update-index --no-skip-worktree --again &&
840 test_sparse_match git status --porcelain=v2 &&
842 cat >expect <<-EOF &&
845 test_sparse_match git diff --name-status &&
846 test_cmp expect sparse-checkout-out
849 test_expect_success
'update-index --cacheinfo' '
852 deep_a_oid=$(git -C full-checkout rev-parse update-deep:deep/a) &&
853 folder2_oid=$(git -C full-checkout rev-parse update-folder2:folder2) &&
854 folder1_a_oid=$(git -C full-checkout rev-parse update-folder1:folder1/a) &&
856 test_all_match git update-index --cacheinfo 100644 $deep_a_oid deep/a &&
857 test_all_match git status --porcelain=v2 &&
859 # Cannot add sparse directory, even in sparse index case
860 test_all_match test_must_fail git update-index --add --cacheinfo 040000 $folder2_oid folder2/ &&
862 # Sparse match only: the new outside-of-cone entry is added *without* skip-worktree,
863 # so `git status` reports it as "deleted" in the worktree
864 test_sparse_match git update-index --add --cacheinfo 100644 $folder1_a_oid folder1/a &&
865 test_sparse_match git status --porcelain=v2 &&
866 cat >expect <<-EOF &&
869 test_sparse_match git status --short -- folder1/a &&
870 test_cmp expect sparse-checkout-out &&
872 # To return folder1/a to "normal" for a sparse checkout (ignored &
873 # outside-of-cone), add the skip-worktree flag.
874 test_sparse_match git update-index --skip-worktree folder1/a &&
875 cat >expect <<-EOF &&
878 test_sparse_match git ls-files -t -- folder1/a &&
879 test_cmp expect sparse-checkout-out
882 for MERGE_TREES
in "base HEAD update-folder2" \
883 "update-folder1 update-folder2" \
886 test_expect_success
"'read-tree -mu $MERGE_TREES' with files outside sparse definition" '
889 # Although the index matches, without --no-sparse-checkout, outside-of-
890 # definition files will not exist on disk for sparse checkouts
891 test_all_match git read-tree -mu $MERGE_TREES &&
892 test_all_match git status --porcelain=v2 &&
893 test_path_is_missing sparse-checkout/folder2 &&
894 test_path_is_missing sparse-index/folder2 &&
896 test_all_match git read-tree --reset -u HEAD &&
897 test_all_match git status --porcelain=v2 &&
899 test_all_match git read-tree -mu --no-sparse-checkout $MERGE_TREES &&
900 test_all_match git status --porcelain=v2 &&
901 test_cmp sparse-checkout/folder2/a sparse-index/folder2/a &&
902 test_cmp sparse-checkout/folder2/a full-checkout/folder2/a
907 test_expect_success
'read-tree --merge with edit/edit conflicts in sparse directories' '
910 # Merge of multiple changes to same directory (but not same files) should
912 test_all_match git read-tree -mu base rename-base update-folder1 &&
913 test_all_match git status --porcelain=v2 &&
915 test_all_match git reset --hard &&
917 test_all_match git read-tree -mu rename-base update-folder2 &&
918 test_all_match git status --porcelain=v2 &&
920 test_all_match git reset --hard &&
922 test_all_match test_must_fail git read-tree -mu base update-folder1 rename-out-to-in &&
923 test_all_match test_must_fail git read-tree -mu rename-out-to-in update-folder1
926 test_expect_success
'read-tree --prefix' '
929 # If files differing between the index and target <commit-ish> exist
930 # inside the prefix, `read-tree --prefix` should fail
931 test_all_match test_must_fail git read-tree --prefix=deep/ deepest &&
932 test_all_match test_must_fail git read-tree --prefix=folder1/ update-folder1 &&
934 # If no differing index entries exist matching the prefix,
935 # `read-tree --prefix` updates the index successfully
936 test_all_match git rm -rf deep/deeper1/deepest/ &&
937 test_all_match git read-tree --prefix=deep/deeper1/deepest -u deepest &&
938 test_all_match git status --porcelain=v2 &&
940 test_all_match git rm -rf --sparse folder1/ &&
941 test_all_match git read-tree --prefix=folder1/ -u update-folder1 &&
942 test_all_match git status --porcelain=v2 &&
944 test_all_match git rm -rf --sparse folder2/0 &&
945 test_all_match git read-tree --prefix=folder2/0/ -u rename-out-to-out &&
946 test_all_match git status --porcelain=v2
949 test_expect_success
'read-tree --merge with directory-file conflicts' '
952 test_all_match git checkout -b test-branch rename-base &&
954 # Although the index matches, without --no-sparse-checkout, outside-of-
955 # definition files will not exist on disk for sparse checkouts
956 test_sparse_match git read-tree -mu rename-out-to-out &&
957 test_sparse_match git status --porcelain=v2 &&
958 test_path_is_missing sparse-checkout/folder2 &&
959 test_path_is_missing sparse-index/folder2 &&
961 test_sparse_match git read-tree --reset -u HEAD &&
962 test_sparse_match git status --porcelain=v2 &&
964 test_sparse_match git read-tree -mu --no-sparse-checkout rename-out-to-out &&
965 test_sparse_match git status --porcelain=v2 &&
966 test_cmp sparse-checkout/folder2/0/1 sparse-index/folder2/0/1
969 test_expect_success
'merge, cherry-pick, and rebase' '
972 for OPERATION in "merge -m merge" cherry-pick "rebase --apply" "rebase --merge"
974 test_all_match git checkout -B temp update-deep &&
975 test_all_match git $OPERATION update-folder1 &&
976 test_all_match git rev-parse HEAD^{tree} &&
977 test_all_match git $OPERATION update-folder2 &&
978 test_all_match git rev-parse HEAD^{tree} || return 1
982 test_expect_success
'merge with conflict outside cone' '
985 test_all_match git checkout -b merge-tip merge-left &&
986 test_all_match git status --porcelain=v2 &&
987 test_all_match test_must_fail git merge -m merge merge-right &&
988 test_all_match git status --porcelain=v2 &&
990 # Resolve the conflict in different ways:
991 # 1. Revert to the base
992 test_all_match git checkout base -- deep/deeper2/a &&
993 test_all_match git status --porcelain=v2 &&
995 # 2. Add the file with conflict markers
996 test_sparse_match test_must_fail git add folder1/a &&
997 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
998 test_sparse_unstaged folder1/a &&
999 test_all_match git add --sparse folder1/a &&
1000 test_all_match git status --porcelain=v2 &&
1002 # 3. Rename the file to another sparse filename and
1003 # accept conflict markers as resolved content.
1004 run_on_all mv folder2/a folder2/z &&
1005 test_sparse_match test_must_fail git add folder2 &&
1006 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
1007 test_sparse_unstaged folder2/z &&
1008 test_all_match git add --sparse folder2 &&
1009 test_all_match git status --porcelain=v2 &&
1011 test_all_match git merge --continue &&
1012 test_all_match git status --porcelain=v2 &&
1013 test_all_match git rev-parse HEAD^{tree}
1016 test_expect_success
'cherry-pick/rebase with conflict outside cone' '
1019 for OPERATION in cherry-pick rebase
1021 test_all_match git checkout -B tip &&
1022 test_all_match git reset --hard merge-left &&
1023 test_all_match git status --porcelain=v2 &&
1024 test_all_match test_must_fail git $OPERATION merge-right &&
1025 test_all_match git status --porcelain=v2 &&
1027 # Resolve the conflict in different ways:
1028 # 1. Revert to the base
1029 test_all_match git checkout base -- deep/deeper2/a &&
1030 test_all_match git status --porcelain=v2 &&
1032 # 2. Add the file with conflict markers
1033 # NEEDSWORK: Even though the merge conflict removed the
1034 # SKIP_WORKTREE bit from the index entry for folder1/a, we should
1035 # warn that this is a problematic add.
1036 test_sparse_match test_must_fail git add folder1/a &&
1037 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
1038 test_sparse_unstaged folder1/a &&
1039 test_all_match git add --sparse folder1/a &&
1040 test_all_match git status --porcelain=v2 &&
1042 # 3. Rename the file to another sparse filename and
1043 # accept conflict markers as resolved content.
1044 # NEEDSWORK: This mode now fails, because folder2/z is
1045 # outside of the sparse-checkout cone and does not match an
1046 # existing index entry with the SKIP_WORKTREE bit cleared.
1047 run_on_all mv folder2/a folder2/z &&
1048 test_sparse_match test_must_fail git add folder2 &&
1049 grep "Disable or modify the sparsity rules" sparse-checkout-err &&
1050 test_sparse_unstaged folder2/z &&
1051 test_all_match git add --sparse folder2 &&
1052 test_all_match git status --porcelain=v2 &&
1054 test_all_match git $OPERATION --continue &&
1055 test_all_match git status --porcelain=v2 &&
1056 test_all_match git rev-parse HEAD^{tree} || return 1
1060 test_expect_success
'merge with outside renames' '
1063 for type in out-to-out out-to-in in-to-out
1065 test_all_match git reset --hard &&
1066 test_all_match git checkout -f -b merge-$type update-deep &&
1067 test_all_match git merge -m "$type" rename-$type &&
1068 test_all_match git rev-parse HEAD^{tree} || return 1
1072 # Sparse-index fails to convert the index in the
1073 # final 'git cherry-pick' command.
1074 test_expect_success
'cherry-pick with conflicts' '
1077 write_script edit-conflict <<-\EOF &&
1081 test_all_match git checkout -b to-cherry-pick &&
1082 run_on_all ../edit-conflict ABC &&
1083 test_all_match git add conflict &&
1084 test_all_match git commit -m "conflict to pick" &&
1086 test_all_match git checkout -B base HEAD~1 &&
1087 run_on_all ../edit-conflict DEF &&
1088 test_all_match git add conflict &&
1089 test_all_match git commit -m "conflict in base" &&
1091 test_all_match test_must_fail git cherry-pick to-cherry-pick
1094 test_expect_success
'stash' '
1097 write_script edit-contents <<-\EOF &&
1101 # Stash a sparse directory (folder1)
1102 test_all_match git checkout -b test-branch rename-base &&
1103 test_all_match git reset --soft rename-out-to-out &&
1104 test_all_match git stash &&
1105 test_all_match git status --porcelain=v2 &&
1107 # Apply the sparse directory stash without reinstating the index
1108 test_all_match git stash apply -q &&
1109 test_all_match git status --porcelain=v2 &&
1111 # Reset to state where stash can be applied
1112 test_sparse_match git sparse-checkout reapply &&
1113 test_all_match git reset --hard rename-out-to-out &&
1115 # Apply the sparse directory stash *with* reinstating the index
1116 test_all_match git stash apply --index -q &&
1117 test_all_match git status --porcelain=v2 &&
1119 # Reset to state where we will get a conflict applying the stash
1120 test_sparse_match git sparse-checkout reapply &&
1121 test_all_match git reset --hard update-folder1 &&
1123 # Apply the sparse directory stash with conflicts
1124 test_all_match test_must_fail git stash apply --index -q &&
1125 test_all_match test_must_fail git stash apply -q &&
1126 test_all_match git status --porcelain=v2 &&
1128 # Reset to base branch
1129 test_sparse_match git sparse-checkout reapply &&
1130 test_all_match git reset --hard base &&
1132 # Stash & unstash an untracked file outside of the sparse checkout
1134 run_on_sparse mkdir -p folder1 &&
1135 run_on_all ../edit-contents folder1/new &&
1136 test_all_match git stash -u &&
1137 test_all_match git status --porcelain=v2 &&
1139 test_all_match git stash pop -q &&
1140 test_all_match git status --porcelain=v2
1143 test_expect_success
'checkout-index inside sparse definition' '
1146 run_on_all rm -f deep/a &&
1147 test_all_match git checkout-index -- deep/a &&
1148 test_all_match git status --porcelain=v2 &&
1150 echo test >>new-a &&
1151 run_on_all cp ../new-a a &&
1152 test_all_match test_must_fail git checkout-index -- a &&
1153 test_all_match git checkout-index -f -- a &&
1154 test_all_match git status --porcelain=v2
1157 test_expect_success
'checkout-index outside sparse definition' '
1160 # Without --ignore-skip-worktree-bits, outside-of-cone files will trigger
1162 test_sparse_match test_must_fail git checkout-index -- folder1/a &&
1163 test_i18ngrep "folder1/a has skip-worktree enabled" sparse-checkout-err &&
1164 test_path_is_missing folder1/a &&
1166 # With --ignore-skip-worktree-bits, outside-of-cone files are checked out
1167 test_sparse_match git checkout-index --ignore-skip-worktree-bits -- folder1/a &&
1168 test_cmp sparse-checkout/folder1/a sparse-index/folder1/a &&
1169 test_cmp sparse-checkout/folder1/a full-checkout/folder1/a &&
1171 run_on_sparse rm -rf folder1 &&
1173 run_on_sparse mkdir -p folder1 &&
1174 run_on_all cp ../new-a folder1/a &&
1176 test_all_match test_must_fail git checkout-index --ignore-skip-worktree-bits -- folder1/a &&
1177 test_all_match git checkout-index -f --ignore-skip-worktree-bits -- folder1/a &&
1178 test_cmp sparse-checkout/folder1/a sparse-index/folder1/a &&
1179 test_cmp sparse-checkout/folder1/a full-checkout/folder1/a
1182 test_expect_success
'checkout-index with folders' '
1185 # Inside checkout definition
1186 test_all_match test_must_fail git checkout-index -f -- deep/ &&
1188 # Outside checkout definition
1189 # Note: although all tests fail (as expected), the messaging differs. For
1190 # non-sparse index checkouts, the error is that the "file" does not appear
1191 # in the index; for sparse checkouts, the error is explicitly that the
1192 # entry is a sparse directory.
1193 run_on_all test_must_fail git checkout-index -f -- folder1/ &&
1194 test_cmp full-checkout-err sparse-checkout-err &&
1195 ! test_cmp full-checkout-err sparse-index-err &&
1196 grep "is a sparse directory" sparse-index-err
1199 test_expect_success
'checkout-index --all' '
1202 test_all_match git checkout-index --all &&
1203 test_sparse_match test_path_is_missing folder1 &&
1205 # --ignore-skip-worktree-bits will cause `skip-worktree` files to be
1206 # checked out, causing the outside-of-cone `folder1` to exist on-disk
1207 test_all_match git checkout-index --ignore-skip-worktree-bits --all &&
1208 test_all_match test_path_exists folder1
1211 test_expect_success
'clean' '
1214 echo bogus >>.gitignore &&
1215 run_on_all cp ../.gitignore . &&
1216 test_all_match git add .gitignore &&
1217 test_all_match git commit -m "ignore bogus files" &&
1219 run_on_sparse mkdir folder1 &&
1220 run_on_all mkdir -p deep/untracked-deep &&
1221 run_on_all touch folder1/bogus &&
1222 run_on_all touch folder1/untracked &&
1223 run_on_all touch deep/untracked-deep/bogus &&
1224 run_on_all touch deep/untracked-deep/untracked &&
1226 test_all_match git status --porcelain=v2 &&
1227 test_all_match git clean -f &&
1228 test_all_match git status --porcelain=v2 &&
1229 test_sparse_match ls &&
1230 test_sparse_match ls folder1 &&
1231 run_on_all test_path_exists folder1/bogus &&
1232 run_on_all test_path_is_missing folder1/untracked &&
1233 run_on_all test_path_exists deep/untracked-deep/bogus &&
1234 run_on_all test_path_exists deep/untracked-deep/untracked &&
1236 test_all_match git clean -fd &&
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_exists deep/untracked-deep/bogus &&
1242 run_on_all test_path_is_missing deep/untracked-deep/untracked &&
1244 test_all_match git clean -xf &&
1245 test_all_match git status --porcelain=v2 &&
1246 test_sparse_match ls &&
1247 test_sparse_match ls folder1 &&
1248 run_on_all test_path_is_missing folder1/bogus &&
1249 run_on_all test_path_exists deep/untracked-deep/bogus &&
1251 test_all_match git clean -xdf &&
1252 test_all_match git status --porcelain=v2 &&
1253 test_sparse_match ls &&
1254 test_sparse_match ls folder1 &&
1255 run_on_all test_path_is_missing deep/untracked-deep/bogus &&
1257 test_sparse_match test_path_is_dir folder1
1260 for builtin in show rev-parse
1262 test_expect_success
"$builtin (cached blobs/trees)" "
1265 test_all_match git $builtin :a &&
1266 test_all_match git $builtin :deep/a &&
1267 test_sparse_match git $builtin :folder1/a &&
1269 # The error message differs depending on whether
1270 # the directory exists in the worktree.
1271 test_all_match test_must_fail git $builtin :deep/ &&
1272 test_must_fail git -C full-checkout $builtin :folder1/ &&
1273 test_sparse_match test_must_fail git $builtin :folder1/ &&
1275 # Change the sparse cone for an extra case:
1276 run_on_sparse git sparse-checkout set deep/deeper1 &&
1278 # deep/deeper2 is a sparse directory in the sparse index.
1279 test_sparse_match test_must_fail git $builtin :deep/deeper2/ &&
1281 # deep/deeper2/deepest is not in the sparse index, but
1282 # will trigger an index expansion.
1283 test_sparse_match test_must_fail git $builtin :deep/deeper2/deepest/
1287 test_expect_success
'submodule handling' '
1290 test_sparse_match git sparse-checkout add modules &&
1291 test_all_match mkdir modules &&
1292 test_all_match touch modules/a &&
1293 test_all_match git add modules &&
1294 test_all_match git commit -m "add modules directory" &&
1296 run_on_all git submodule add "$(pwd)/initial-repo" modules/sub &&
1297 test_all_match git commit -m "add submodule" &&
1299 # having a submodule prevents "modules" from collapse
1300 test_sparse_match git sparse-checkout set deep/deeper1 &&
1301 git -C sparse-index ls-files --sparse --stage >cache &&
1302 grep "100644 .* modules/a" cache &&
1303 grep "160000 $(git -C initial-repo rev-parse HEAD) 0 modules/sub" cache
1306 # When working with a sparse index, some commands will need to expand the
1307 # index to operate properly. If those commands also write the index back
1308 # to disk, they need to convert the index to sparse before writing.
1309 # This test verifies that both of these events are logged in trace2 logs.
1310 test_expect_success
'sparse-index is expanded and converted back' '
1313 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
1314 git -C sparse-index reset -- folder1/a &&
1315 test_region index convert_to_sparse trace2.txt &&
1316 test_region index ensure_full_index trace2.txt &&
1318 # ls-files expands on read, but does not write.
1320 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1321 git -C sparse-index ls-files &&
1322 test_region index ensure_full_index trace2.txt
1325 test_expect_success
'index.sparse disabled inline uses full index' '
1328 # When index.sparse is disabled inline with `git status`, the
1329 # index is expanded at the beginning of the execution then never
1330 # converted back to sparse. It is then written to disk as a full index.
1332 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1333 git -C sparse-index -c index.sparse=false status &&
1334 ! test_region index convert_to_sparse trace2.txt &&
1335 test_region index ensure_full_index trace2.txt &&
1337 # Since index.sparse is set to true at a repo level, the index
1338 # is converted from full to sparse when read, then never expanded
1339 # over the course of `git status`. It is written to disk as a sparse
1342 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1343 git -C sparse-index status &&
1344 test_region index convert_to_sparse trace2.txt &&
1345 ! test_region index ensure_full_index trace2.txt &&
1347 # Now that the index has been written to disk as sparse, it is not
1348 # converted to sparse (or expanded to full) when read by `git status`.
1350 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
1351 git -C sparse-index status &&
1352 ! test_region index convert_to_sparse trace2.txt &&
1353 ! test_region index ensure_full_index trace2.txt
1356 ensure_not_expanded
() {
1358 if test -z "$WITHOUT_UNTRACKED_TXT"
1360 echo >>sparse-index
/untracked.txt
1366 test_must_fail env \
1367 GIT_TRACE2_EVENT
="$(pwd)/trace2.txt" \
1368 git
-C sparse-index
"$@" ||
return 1
1370 GIT_TRACE2_EVENT
="$(pwd)/trace2.txt" \
1371 git
-C sparse-index
"$@" ||
return 1
1373 test_region
! index ensure_full_index trace2.txt
1376 test_expect_success
'sparse-index is not expanded' '
1379 ensure_not_expanded status &&
1380 ensure_not_expanded ls-files --sparse &&
1381 ensure_not_expanded commit --allow-empty -m empty &&
1382 echo >>sparse-index/a &&
1383 ensure_not_expanded commit -a -m a &&
1384 echo >>sparse-index/a &&
1385 ensure_not_expanded commit --include a -m a &&
1386 echo >>sparse-index/deep/deeper1/a &&
1387 ensure_not_expanded commit --include deep/deeper1/a -m deeper &&
1388 ensure_not_expanded checkout rename-out-to-out &&
1389 ensure_not_expanded checkout - &&
1390 ensure_not_expanded switch rename-out-to-out &&
1391 ensure_not_expanded switch - &&
1392 ensure_not_expanded reset --hard &&
1393 ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
1394 ensure_not_expanded reset --hard &&
1395 ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
1397 echo >>sparse-index/README.md &&
1398 ensure_not_expanded add -A &&
1399 echo >>sparse-index/extra.txt &&
1400 ensure_not_expanded add extra.txt &&
1401 echo >>sparse-index/untracked.txt &&
1402 ensure_not_expanded add . &&
1404 ensure_not_expanded checkout-index -f a &&
1405 ensure_not_expanded checkout-index -f --all &&
1406 for ref in update-deep update-folder1 update-folder2 update-deep
1408 echo >>sparse-index/README.md &&
1409 ensure_not_expanded reset --hard $ref || return 1
1412 ensure_not_expanded reset --mixed base &&
1413 ensure_not_expanded reset --hard update-deep &&
1414 ensure_not_expanded reset --keep base &&
1415 ensure_not_expanded reset --merge update-deep &&
1416 ensure_not_expanded reset --hard &&
1418 ensure_not_expanded reset base -- deep/a &&
1419 ensure_not_expanded reset base -- nonexistent-file &&
1420 ensure_not_expanded reset deepest -- deep &&
1422 # Although folder1 is outside the sparse definition, it exists as a
1423 # directory entry in the index, so the pathspec will not force the
1424 # index to be expanded.
1425 ensure_not_expanded reset deepest -- folder1 &&
1426 ensure_not_expanded reset deepest -- folder1/ &&
1428 # Wildcard identifies only in-cone files, no index expansion
1429 ensure_not_expanded reset deepest -- deep/\* &&
1431 # Wildcard identifies only full sparse directories, no index expansion
1432 ensure_not_expanded reset deepest -- folder\* &&
1434 ensure_not_expanded clean -fd &&
1436 ensure_not_expanded checkout -f update-deep &&
1437 test_config -C sparse-index pull.twohead ort &&
1439 sane_unset GIT_TEST_MERGE_ALGORITHM &&
1440 for OPERATION in "merge -m merge" cherry-pick rebase
1442 ensure_not_expanded merge -m merge update-folder1 &&
1443 ensure_not_expanded merge -m merge update-folder2 || return 1
1448 test_expect_success
'sparse-index is not expanded: merge conflict in cone' '
1451 for side in right left
1453 git -C sparse-index checkout -b expand-$side base &&
1454 echo $side >sparse-index/deep/a &&
1455 git -C sparse-index commit -a -m "$side" || return 1
1459 sane_unset GIT_TEST_MERGE_ALGORITHM &&
1460 git -C sparse-index config pull.twohead ort &&
1461 ensure_not_expanded ! merge -m merged expand-right
1465 test_expect_success
'sparse-index is not expanded: stash' '
1468 echo >>sparse-index/a &&
1469 ensure_not_expanded stash &&
1470 ensure_not_expanded stash list &&
1471 ensure_not_expanded stash show stash@{0} &&
1472 ensure_not_expanded stash apply stash@{0} &&
1473 ensure_not_expanded stash drop stash@{0} &&
1475 echo >>sparse-index/deep/new &&
1476 ensure_not_expanded stash -u &&
1478 WITHOUT_UNTRACKED_TXT=1 &&
1479 ensure_not_expanded stash pop
1482 ensure_not_expanded stash create &&
1483 oid=$(git -C sparse-index stash create) &&
1484 ensure_not_expanded stash store -m "test" $oid &&
1485 ensure_not_expanded reset --hard &&
1486 ensure_not_expanded stash pop
1489 test_expect_success
'sparse index is not expanded: diff' '
1492 write_script edit-contents <<-\EOF &&
1496 # Add file within cone
1497 test_sparse_match git sparse-checkout set deep &&
1498 run_on_all ../edit-contents deep/testfile &&
1499 test_all_match git add deep/testfile &&
1500 run_on_all ../edit-contents deep/testfile &&
1502 test_all_match git diff &&
1503 test_all_match git diff --cached &&
1504 ensure_not_expanded diff &&
1505 ensure_not_expanded diff --cached &&
1507 # Add file outside cone
1508 test_all_match git reset --hard &&
1509 run_on_all mkdir newdirectory &&
1510 run_on_all ../edit-contents newdirectory/testfile &&
1511 test_sparse_match git sparse-checkout set newdirectory &&
1512 test_all_match git add newdirectory/testfile &&
1513 run_on_all ../edit-contents newdirectory/testfile &&
1514 test_sparse_match git sparse-checkout set &&
1516 test_all_match git diff &&
1517 test_all_match git diff --cached &&
1518 ensure_not_expanded diff &&
1519 ensure_not_expanded diff --cached &&
1521 # Merge conflict outside cone
1522 # The sparse checkout will report a warning that is not in the
1523 # full checkout, so we use `run_on_all` instead of
1525 run_on_all git reset --hard &&
1526 test_all_match git checkout merge-left &&
1527 test_all_match test_must_fail git merge merge-right &&
1529 test_all_match git diff &&
1530 test_all_match git diff --cached &&
1531 ensure_not_expanded diff &&
1532 ensure_not_expanded diff --cached
1535 test_expect_success
'sparse index is not expanded: show and rev-parse' '
1538 ensure_not_expanded show :a &&
1539 ensure_not_expanded show :deep/a &&
1540 ensure_not_expanded rev-parse :a &&
1541 ensure_not_expanded rev-parse :deep/a
1544 test_expect_success
'sparse index is not expanded: update-index' '
1547 deep_a_oid=$(git -C full-checkout rev-parse update-deep:deep/a) &&
1548 ensure_not_expanded update-index --cacheinfo 100644 $deep_a_oid deep/a &&
1550 echo "test" >sparse-index/README.md &&
1551 echo "test2" >sparse-index/a &&
1552 rm -f sparse-index/deep/a &&
1554 ensure_not_expanded update-index --add README.md &&
1555 ensure_not_expanded update-index a &&
1556 ensure_not_expanded update-index --remove deep/a &&
1558 ensure_not_expanded reset --soft update-deep &&
1559 ensure_not_expanded update-index --add --remove --again
1562 test_expect_success
'sparse index is not expanded: blame' '
1568 deep/deeper1/deepest/a
1570 ensure_not_expanded blame $file
1574 test_expect_success
'sparse index is not expanded: fetch/pull' '
1577 git -C sparse-index remote add full "file://$(pwd)/full-checkout" &&
1578 ensure_not_expanded fetch full &&
1579 git -C full-checkout commit --allow-empty -m "for pull merge" &&
1580 git -C sparse-index commit --allow-empty -m "for pull merge" &&
1581 ensure_not_expanded pull full base
1584 test_expect_success
'sparse index is not expanded: read-tree' '
1587 ensure_not_expanded checkout -b test-branch update-folder1 &&
1588 for MERGE_TREES in "base HEAD update-folder2" \
1589 "base HEAD rename-base" \
1590 "base update-folder2" \
1591 "base rename-base" \
1594 ensure_not_expanded read-tree -mu $MERGE_TREES &&
1595 ensure_not_expanded reset --hard || return 1
1598 rm -rf sparse-index/deep/deeper2 &&
1599 ensure_not_expanded add . &&
1600 ensure_not_expanded commit -m "test" &&
1602 ensure_not_expanded read-tree --prefix=deep/deeper2 -u deepest
1605 test_expect_success
'ls-files' '
1608 # Use a smaller sparse-checkout for reduced output
1609 test_sparse_match git sparse-checkout set &&
1611 # Behavior agrees by default. Sparse index is expanded.
1612 test_all_match git ls-files &&
1614 # With --sparse, the sparse index data changes behavior.
1615 git -C sparse-index ls-files --sparse >actual &&
1617 cat >expect <<-\EOF &&
1632 test_cmp expect actual &&
1634 # With --sparse and no sparse index, nothing changes.
1635 git -C sparse-checkout ls-files >dense &&
1636 git -C sparse-checkout ls-files --sparse >sparse &&
1637 test_cmp dense sparse &&
1639 # Set up a strange condition of having a file edit
1640 # outside of the sparse-checkout cone. We want to verify
1641 # that all modes handle this the same, and detect the
1643 write_script edit-content <<-\EOF &&
1645 echo content >>folder1/a
1647 run_on_all ../edit-content &&
1649 test_all_match git ls-files --modified &&
1651 git -C sparse-index ls-files --sparse --modified >sparse-index-out &&
1652 cat >expect <<-\EOF &&
1655 test_cmp expect sparse-index-out &&
1657 # Add folder1 to the sparse-checkout cone and
1658 # check that ls-files shows the expanded files.
1659 test_sparse_match git sparse-checkout add folder1 &&
1660 test_all_match git ls-files --modified &&
1662 test_all_match git ls-files &&
1663 git -C sparse-index ls-files --sparse >actual &&
1665 cat >expect <<-\EOF &&
1682 test_cmp expect actual &&
1684 # Double-check index expansion is avoided
1685 ensure_not_expanded ls-files --sparse
1688 test_expect_success
'sparse index is not expanded: sparse-checkout' '
1691 ensure_not_expanded sparse-checkout set deep/deeper2 &&
1692 ensure_not_expanded sparse-checkout set deep/deeper1 &&
1693 ensure_not_expanded sparse-checkout set deep &&
1694 ensure_not_expanded sparse-checkout add folder1 &&
1695 ensure_not_expanded sparse-checkout set deep/deeper1 &&
1696 ensure_not_expanded sparse-checkout set folder2 &&
1698 # Demonstrate that the checks that "folder1/a" is a file
1699 # do not cause a sparse-index expansion (since it is in the
1700 # sparse-checkout cone).
1701 echo >>sparse-index/folder2/a &&
1702 git -C sparse-index add folder2/a &&
1704 ensure_not_expanded sparse-checkout add folder1 &&
1706 # Skip checks here, since deep/deeper1 is inside a sparse directory
1707 # that must be expanded to check whether `deep/deeper1` is a file
1709 ensure_not_expanded sparse-checkout set --skip-checks deep/deeper1 &&
1710 ensure_not_expanded sparse-checkout set
1713 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
1714 # in this scenario, but it shouldn't.
1715 test_expect_success
'reset mixed and checkout orphan' '
1718 test_all_match git checkout rename-out-to-in &&
1720 # Sparse checkouts do not agree with full checkouts about
1721 # how to report a directory/file conflict during a reset.
1722 # This command would fail with test_all_match because the
1723 # full checkout reports "T folder1/0/1" while a sparse
1724 # checkout reports "D folder1/0/1". This matches because
1725 # the sparse checkouts skip "adding" the other side of
1727 test_sparse_match git reset --mixed HEAD~1 &&
1728 test_sparse_match git ls-files --stage &&
1729 test_sparse_match git status --porcelain=v2 &&
1731 # At this point, sparse-checkouts behave differently
1732 # from the full-checkout.
1733 test_sparse_match git checkout --orphan new-branch &&
1734 test_sparse_match git ls-files --stage &&
1735 test_sparse_match git status --porcelain=v2
1738 test_expect_success
'add everything with deep new file' '
1741 run_on_sparse git sparse-checkout set deep/deeper1/deepest &&
1743 run_on_all touch deep/deeper1/x &&
1744 test_all_match git add . &&
1745 test_all_match git status --porcelain=v2
1748 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
1749 # directory/file conflicts, even without sparse-checkout. Use this
1750 # test only as a documentation of the incorrect behavior, not a
1751 # measure of how it _should_ behave.
1752 test_expect_success
'checkout behaves oddly with df-conflict-1' '
1755 test_sparse_match git sparse-checkout disable &&
1757 write_script edit-content <<-\EOF &&
1758 echo content >>folder1/larger-content
1762 run_on_all ../edit-content &&
1763 test_all_match git status --porcelain=v2 &&
1765 git -C sparse-checkout sparse-checkout init --cone &&
1766 git -C sparse-index sparse-checkout init --cone --sparse-index &&
1768 test_all_match git status --porcelain=v2 &&
1770 # This checkout command should fail, because we have a staged
1771 # change to folder1/larger-content, but the destination changes
1772 # folder1 to a file.
1773 git -C full-checkout checkout df-conflict-1 \
1774 1>full-checkout-out \
1775 2>full-checkout-err &&
1776 git -C sparse-checkout checkout df-conflict-1 \
1777 1>sparse-checkout-out \
1778 2>sparse-checkout-err &&
1779 git -C sparse-index checkout df-conflict-1 \
1780 1>sparse-index-out \
1781 2>sparse-index-err &&
1783 # Instead, the checkout deletes the folder1 file and adds the
1784 # folder1/larger-content file, leaving all other paths that were
1785 # in folder1/ as deleted (without any warning).
1786 cat >expect <<-EOF &&
1788 A folder1/larger-content
1790 test_cmp expect full-checkout-out &&
1791 test_cmp expect sparse-checkout-out &&
1793 # The sparse-index reports no output
1794 test_must_be_empty sparse-index-out &&
1796 # stderr: Switched to branch df-conflict-1
1797 test_cmp full-checkout-err sparse-checkout-err &&
1798 test_cmp full-checkout-err sparse-checkout-err
1801 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
1802 # directory/file conflicts, even without sparse-checkout. Use this
1803 # test only as a documentation of the incorrect behavior, not a
1804 # measure of how it _should_ behave.
1805 test_expect_success
'checkout behaves oddly with df-conflict-2' '
1808 test_sparse_match git sparse-checkout disable &&
1810 write_script edit-content <<-\EOF &&
1811 echo content >>folder2/larger-content
1815 run_on_all ../edit-content &&
1816 test_all_match git status --porcelain=v2 &&
1818 git -C sparse-checkout sparse-checkout init --cone &&
1819 git -C sparse-index sparse-checkout init --cone --sparse-index &&
1821 test_all_match git status --porcelain=v2 &&
1823 # This checkout command should fail, because we have a staged
1824 # change to folder1/larger-content, but the destination changes
1825 # folder1 to a file.
1826 git -C full-checkout checkout df-conflict-2 \
1827 1>full-checkout-out \
1828 2>full-checkout-err &&
1829 git -C sparse-checkout checkout df-conflict-2 \
1830 1>sparse-checkout-out \
1831 2>sparse-checkout-err &&
1832 git -C sparse-index checkout df-conflict-2 \
1833 1>sparse-index-out \
1834 2>sparse-index-err &&
1836 # The full checkout deviates from the df-conflict-1 case here!
1837 # It drops the change to folder1/larger-content and leaves the
1838 # folder1 path as-is on disk. The sparse-index behaves the same.
1839 test_must_be_empty full-checkout-out &&
1840 test_must_be_empty sparse-index-out &&
1842 # In the sparse-checkout case, the checkout deletes the folder1
1843 # file and adds the folder1/larger-content file, leaving all other
1844 # paths that were in folder1/ as deleted (without any warning).
1845 cat >expect <<-EOF &&
1847 A folder2/larger-content
1849 test_cmp expect sparse-checkout-out &&
1851 # Switched to branch df-conflict-1
1852 test_cmp full-checkout-err sparse-checkout-err &&
1853 test_cmp full-checkout-err sparse-index-err