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 x &&
20 mkdir deep/deeper1 deep/deeper2 deep/before deep/later &&
21 mkdir deep/deeper1/deepest &&
22 echo "after deeper1" >deep/e &&
23 echo "after deepest" >deep/deeper1/e &&
32 cp a deep/deeper1/deepest &&
33 cp -r deep/deeper1/deepest deep/deeper2 &&
34 mkdir deep/deeper1/0 &&
35 mkdir deep/deeper1/0/0 &&
36 touch deep/deeper1/0/1 &&
37 touch deep/deeper1/0/0/0 &&
41 cp -r deep/deeper1/0 folder1 &&
42 cp -r deep/deeper1/0 folder2 &&
43 echo >>folder1/0/0/0 &&
46 git commit -m "initial commit" &&
47 git checkout -b base &&
48 for dir in folder1 folder2 deep
50 git checkout -b update-$dir base &&
51 echo "updated $dir" >$dir/a &&
52 git commit -a -m "update $dir" || return 1
55 git checkout -b rename-base base &&
56 cat >folder1/larger-content <<-\EOF &&
63 cp folder1/larger-content folder2/ &&
64 cp folder1/larger-content deep/deeper1/ &&
66 git commit -m "add interesting rename content" &&
68 git checkout -b rename-out-to-out rename-base &&
69 mv folder1/a folder2/b &&
70 mv folder1/larger-content folder2/edited-content &&
71 echo >>folder2/edited-content &&
73 echo stuff >>deep/deeper1/a &&
75 git commit -m "rename folder1/... to folder2/..." &&
77 git checkout -b rename-out-to-in rename-base &&
78 mv folder1/a deep/deeper1/b &&
79 echo more stuff >>deep/deeper1/a &&
82 echo >>folder2/0/1/1 &&
83 mv folder1/larger-content deep/deeper1/edited-content &&
84 echo >>deep/deeper1/edited-content &&
86 git commit -m "rename folder1/... to deep/deeper1/..." &&
88 git checkout -b rename-in-to-out rename-base &&
89 mv deep/deeper1/a folder1/b &&
93 mv deep/deeper1/larger-content folder1/edited-content &&
94 echo >>folder1/edited-content &&
96 git commit -m "rename deep/deeper1/... to folder1/..." &&
98 git checkout -b df-conflict-1 base &&
100 echo content >folder1 &&
102 git commit -m "dir to file" &&
104 git checkout -b df-conflict-2 base &&
106 echo content >folder2 &&
108 git commit -m "dir to file" &&
110 git checkout -b fd-conflict base &&
115 git commit -m "file to dir" &&
117 for side in left right
119 git checkout -b merge-$side base &&
120 echo $side >>deep/deeper2/a &&
121 echo $side >>folder1/a &&
122 echo $side >>folder2/a &&
124 git commit -m "$side" || return 1
127 git checkout -b deepest base &&
128 echo "updated deepest" >deep/deeper1/deepest/a &&
129 git commit -a -m "update deepest" &&
131 git checkout -f base &&
137 rm -rf full-checkout sparse-checkout sparse-index
&&
139 # create repos in initial state
140 cp -r initial-repo full-checkout
&&
141 git
-C full-checkout
reset --hard &&
143 cp -r initial-repo sparse-checkout
&&
144 git
-C sparse-checkout
reset --hard &&
146 cp -r initial-repo sparse-index
&&
147 git
-C sparse-index
reset --hard &&
149 # initialize sparse-checkout definitions
150 git
-C sparse-checkout sparse-checkout init
--cone &&
151 git
-C sparse-checkout sparse-checkout
set deep
&&
152 git
-C sparse-index sparse-checkout init
--cone --sparse-index &&
153 test_cmp_config
-C sparse-index true index.sparse
&&
154 git
-C sparse-index sparse-checkout
set deep
159 cd sparse-checkout
&&
160 GIT_PROGRESS_DELAY
=100000 "$@" >..
/sparse-checkout-out
2>..
/sparse-checkout-err
164 GIT_PROGRESS_DELAY
=100000 "$@" >..
/sparse-index-out
2>..
/sparse-index-err
171 GIT_PROGRESS_DELAY
=100000 "$@" >..
/full-checkout-out
2>..
/full-checkout-err
178 test_cmp full-checkout-out sparse-checkout-out
&&
179 test_cmp full-checkout-out sparse-index-out
&&
180 test_cmp full-checkout-err sparse-checkout-err
&&
181 test_cmp full-checkout-err sparse-index-err
184 test_sparse_match
() {
185 run_on_sparse
"$@" &&
186 test_cmp sparse-checkout-out sparse-index-out
&&
187 test_cmp sparse-checkout-err sparse-index-err
190 test_expect_success
'sparse-index contents' '
193 test-tool -C sparse-index read-cache --table >cache &&
194 for dir in folder1 folder2 x
196 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
197 grep "040000 tree $TREE $dir/" cache \
201 git -C sparse-index sparse-checkout set folder1 &&
203 test-tool -C sparse-index read-cache --table >cache &&
204 for dir in deep folder2 x
206 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
207 grep "040000 tree $TREE $dir/" cache \
211 git -C sparse-index sparse-checkout set deep/deeper1 &&
213 test-tool -C sparse-index read-cache --table >cache &&
214 for dir in deep/deeper2 folder1 folder2 x
216 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
217 grep "040000 tree $TREE $dir/" cache \
221 # Disabling the sparse-index removes tree entries with full ones
222 git -C sparse-index sparse-checkout init --no-sparse-index &&
224 test-tool -C sparse-index read-cache --table >cache &&
225 ! grep "040000 tree" cache &&
226 test_sparse_match test-tool read-cache --table
229 test_expect_success
'expanded in-memory index matches full index' '
231 test_sparse_match test-tool read-cache --expand --table
234 test_expect_success
'status with options' '
236 test_sparse_match ls &&
237 test_all_match git status --porcelain=v2 &&
238 test_all_match git status --porcelain=v2 -z -u &&
239 test_all_match git status --porcelain=v2 -uno &&
240 run_on_all touch README.md &&
241 test_all_match git status --porcelain=v2 &&
242 test_all_match git status --porcelain=v2 -z -u &&
243 test_all_match git status --porcelain=v2 -uno &&
244 test_all_match git add README.md &&
245 test_all_match git status --porcelain=v2 &&
246 test_all_match git status --porcelain=v2 -z -u &&
247 test_all_match git status --porcelain=v2 -uno
250 test_expect_success
'status reports sparse-checkout' '
252 git -C sparse-checkout status >full &&
253 git -C sparse-index status >sparse &&
254 test_i18ngrep "You are in a sparse checkout with " full &&
255 test_i18ngrep "You are in a sparse checkout." sparse
258 test_expect_success
'add, commit, checkout' '
261 write_script edit-contents <<-\EOF &&
264 run_on_all ../edit-contents README.md &&
266 test_all_match git add README.md &&
267 test_all_match git status --porcelain=v2 &&
268 test_all_match git commit -m "Add README.md" &&
270 test_all_match git checkout HEAD~1 &&
271 test_all_match git checkout - &&
273 run_on_all ../edit-contents README.md &&
275 test_all_match git add -A &&
276 test_all_match git status --porcelain=v2 &&
277 test_all_match git commit -m "Extend README.md" &&
279 test_all_match git checkout HEAD~1 &&
280 test_all_match git checkout - &&
282 run_on_all ../edit-contents deep/newfile &&
284 test_all_match git status --porcelain=v2 -uno &&
285 test_all_match git status --porcelain=v2 &&
286 test_all_match git add . &&
287 test_all_match git status --porcelain=v2 &&
288 test_all_match git commit -m "add deep/newfile" &&
290 test_all_match git checkout HEAD~1 &&
291 test_all_match git checkout -
294 test_expect_success
'commit including unstaged changes' '
297 write_script edit-file <<-\EOF &&
301 run_on_all ../edit-file 1 a &&
302 run_on_all ../edit-file 1 deep/a &&
304 test_all_match git commit -m "-a" -a &&
305 test_all_match git status --porcelain=v2 &&
307 run_on_all ../edit-file 2 a &&
308 run_on_all ../edit-file 2 deep/a &&
310 test_all_match git commit -m "--include" --include deep/a &&
311 test_all_match git status --porcelain=v2 &&
312 test_all_match git commit -m "--include" --include a &&
313 test_all_match git status --porcelain=v2 &&
315 run_on_all ../edit-file 3 a &&
316 run_on_all ../edit-file 3 deep/a &&
318 test_all_match git commit -m "--amend" -a --amend &&
319 test_all_match git status --porcelain=v2
322 test_expect_success
'status/add: outside sparse cone' '
325 # folder1 is at HEAD, but outside the sparse cone
326 run_on_sparse mkdir folder1 &&
327 cp initial-repo/folder1/a sparse-checkout/folder1/a &&
328 cp initial-repo/folder1/a sparse-index/folder1/a &&
330 test_sparse_match git status &&
332 write_script edit-contents <<-\EOF &&
335 run_on_sparse ../edit-contents folder1/a &&
336 run_on_all ../edit-contents folder1/new &&
338 test_sparse_match git status --porcelain=v2 &&
340 # Adding the path outside of the sparse-checkout cone should fail.
341 test_sparse_match test_must_fail git add folder1/a &&
342 test_sparse_match test_must_fail git add --refresh folder1/a &&
344 # NEEDSWORK: Adding a newly-tracked file outside the cone succeeds
345 test_sparse_match git add folder1/new &&
347 test_all_match git add . &&
348 test_all_match git status --porcelain=v2 &&
349 test_all_match git commit -m folder1/new &&
350 test_all_match git rev-parse HEAD^{tree} &&
352 run_on_all ../edit-contents folder1/newer &&
353 test_all_match git add folder1/ &&
354 test_all_match git status --porcelain=v2 &&
355 test_all_match git commit -m folder1/newer &&
356 test_all_match git rev-parse HEAD^{tree}
359 test_expect_success
'checkout and reset --hard' '
362 test_all_match git checkout update-folder1 &&
363 test_all_match git status --porcelain=v2 &&
365 test_all_match git checkout update-deep &&
366 test_all_match git status --porcelain=v2 &&
368 test_all_match git checkout -b reset-test &&
369 test_all_match git reset --hard deepest &&
370 test_all_match git reset --hard update-folder1 &&
371 test_all_match git reset --hard update-folder2
374 test_expect_success
'diff --staged' '
377 write_script edit-contents <<-\EOF &&
378 echo text >>README.md
380 run_on_all ../edit-contents &&
382 test_all_match git diff &&
383 test_all_match git diff --staged &&
384 test_all_match git add README.md &&
385 test_all_match git diff &&
386 test_all_match git diff --staged
389 # NEEDSWORK: sparse-checkout behaves differently from full-checkout when
390 # running this test with 'df-conflict-2' after 'df-conflict-1'.
391 test_expect_success
'diff with renames and conflicts' '
394 for branch in rename-out-to-out \
400 test_all_match git checkout rename-base &&
401 test_all_match git checkout $branch -- . &&
402 test_all_match git status --porcelain=v2 &&
403 test_all_match git diff --staged --no-renames &&
404 test_all_match git diff --staged --find-renames || return 1
408 test_expect_success
'diff with directory/file conflicts' '
411 for branch in rename-out-to-out \
418 git -C full-checkout reset --hard &&
419 test_sparse_match git reset --hard &&
420 test_all_match git checkout $branch &&
421 test_all_match git checkout rename-base -- . &&
422 test_all_match git status --porcelain=v2 &&
423 test_all_match git diff --staged --no-renames &&
424 test_all_match git diff --staged --find-renames || return 1
428 test_expect_success
'log with pathspec outside sparse definition' '
431 test_all_match git log -- a &&
432 test_all_match git log -- folder1/a &&
433 test_all_match git log -- folder2/a &&
434 test_all_match git log -- deep/a &&
435 test_all_match git log -- deep/deeper1/a &&
436 test_all_match git log -- deep/deeper1/deepest/a &&
438 test_all_match git checkout update-folder1 &&
439 test_all_match git log -- folder1/a
442 test_expect_success
'blame with pathspec inside sparse definition' '
445 test_all_match git blame a &&
446 test_all_match git blame deep/a &&
447 test_all_match git blame deep/deeper1/a &&
448 test_all_match git blame deep/deeper1/deepest/a
451 # TODO: blame currently does not support blaming files outside of the
452 # sparse definition. It complains that the file doesn't exist locally.
453 test_expect_failure
'blame with pathspec outside sparse definition' '
456 test_all_match git blame folder1/a &&
457 test_all_match git blame folder2/a &&
458 test_all_match git blame deep/deeper2/a &&
459 test_all_match git blame deep/deeper2/deepest/a
462 test_expect_success
'checkout and reset (mixed)' '
465 test_all_match git checkout -b reset-test update-deep &&
466 test_all_match git reset deepest &&
468 # Because skip-worktree is preserved, resetting to update-folder1
469 # will show worktree changes for folder1/a in full-checkout, but not
470 # in sparse-checkout or sparse-index.
471 git -C full-checkout reset update-folder1 >full-checkout-out &&
472 test_sparse_match git reset update-folder1 &&
473 grep "M folder1/a" full-checkout-out &&
474 ! grep "M folder1/a" sparse-checkout-out &&
475 run_on_sparse test_path_is_missing folder1
478 test_expect_success
'checkout and reset (merge)' '
481 write_script edit-contents <<-\EOF &&
485 test_all_match git checkout -b reset-test update-deep &&
486 run_on_all ../edit-contents a &&
487 test_all_match git reset --merge deepest &&
488 test_all_match git status --porcelain=v2 &&
490 test_all_match git reset --hard update-deep &&
491 run_on_all ../edit-contents deep/a &&
492 test_all_match test_must_fail git reset --merge deepest
495 test_expect_success
'checkout and reset (keep)' '
498 write_script edit-contents <<-\EOF &&
502 test_all_match git checkout -b reset-test update-deep &&
503 run_on_all ../edit-contents a &&
504 test_all_match git reset --keep deepest &&
505 test_all_match git status --porcelain=v2 &&
507 test_all_match git reset --hard update-deep &&
508 run_on_all ../edit-contents deep/a &&
509 test_all_match test_must_fail git reset --keep deepest
512 test_expect_success
'reset with pathspecs inside sparse definition' '
515 write_script edit-contents <<-\EOF &&
519 test_all_match git checkout -b reset-test update-deep &&
520 run_on_all ../edit-contents deep/a &&
522 test_all_match git reset base -- deep/a &&
523 test_all_match git status --porcelain=v2 &&
525 test_all_match git reset base -- nonexistent-file &&
526 test_all_match git status --porcelain=v2 &&
528 test_all_match git reset deepest -- deep &&
529 test_all_match git status --porcelain=v2
532 # Although the working tree differs between full and sparse checkouts after
533 # reset, the state of the index is the same.
534 test_expect_success
'reset with pathspecs outside sparse definition' '
536 test_all_match git checkout -b reset-test base &&
538 test_sparse_match git reset update-folder1 -- folder1 &&
539 git -C full-checkout reset update-folder1 -- folder1 &&
540 test_sparse_match git status --porcelain=v2 &&
541 test_all_match git rev-parse HEAD:folder1 &&
543 test_sparse_match git reset update-folder2 -- folder2/a &&
544 git -C full-checkout reset update-folder2 -- folder2/a &&
545 test_sparse_match git status --porcelain=v2 &&
546 test_all_match git rev-parse HEAD:folder2/a
549 test_expect_success
'reset with wildcard pathspec' '
552 test_all_match git reset update-deep -- deep\* &&
553 test_all_match git ls-files -s -- deep &&
555 test_all_match git reset deepest -- deep\*\*\* &&
556 test_all_match git ls-files -s -- deep &&
558 # The following `git reset`s result in updating the index on files with
559 # `skip-worktree` enabled. To avoid failing due to discrepencies in reported
560 # "modified" files, `test_sparse_match` reset is performed separately from
561 # "full-checkout" reset, then the index contents of all repos are verified.
563 test_sparse_match git reset update-folder1 -- \*/a &&
564 git -C full-checkout reset update-folder1 -- \*/a &&
565 test_all_match git ls-files -s -- deep/a folder1/a &&
567 test_sparse_match git reset update-folder2 -- folder\* &&
568 git -C full-checkout reset update-folder2 -- folder\* &&
569 test_all_match git ls-files -s -- folder10 folder1 folder2 &&
571 test_sparse_match git reset base -- folder1/\* &&
572 git -C full-checkout reset base -- folder1/\* &&
573 test_all_match git ls-files -s -- folder1
576 test_expect_success
'merge, cherry-pick, and rebase' '
579 for OPERATION in "merge -m merge" cherry-pick rebase
581 test_all_match git checkout -B temp update-deep &&
582 test_all_match git $OPERATION update-folder1 &&
583 test_all_match git rev-parse HEAD^{tree} &&
584 test_all_match git $OPERATION update-folder2 &&
585 test_all_match git rev-parse HEAD^{tree} || return 1
589 # NEEDSWORK: This test is documenting current behavior, but that
590 # behavior can be confusing to users so there is desire to change it.
591 # Right now, users might be using this flow to work through conflicts,
592 # so any solution should present advice to users who try this sequence
593 # of commands to follow whatever new method we create.
594 test_expect_success
'merge with conflict outside cone' '
597 test_all_match git checkout -b merge-tip merge-left &&
598 test_all_match git status --porcelain=v2 &&
599 test_all_match test_must_fail git merge -m merge merge-right &&
600 test_all_match git status --porcelain=v2 &&
602 # Resolve the conflict in different ways:
603 # 1. Revert to the base
604 test_all_match git checkout base -- deep/deeper2/a &&
605 test_all_match git status --porcelain=v2 &&
607 # 2. Add the file with conflict markers
608 test_all_match git add folder1/a &&
609 test_all_match git status --porcelain=v2 &&
611 # 3. Rename the file to another sparse filename and
612 # accept conflict markers as resolved content.
613 run_on_all mv folder2/a folder2/z &&
614 test_all_match git add folder2 &&
615 test_all_match git status --porcelain=v2 &&
617 test_all_match git merge --continue &&
618 test_all_match git status --porcelain=v2 &&
619 test_all_match git rev-parse HEAD^{tree}
622 test_expect_success
'cherry-pick/rebase with conflict outside cone' '
625 for OPERATION in cherry-pick rebase
627 test_all_match git checkout -B tip &&
628 test_all_match git reset --hard merge-left &&
629 test_all_match git status --porcelain=v2 &&
630 test_all_match test_must_fail git $OPERATION merge-right &&
631 test_all_match git status --porcelain=v2 &&
633 # Resolve the conflict in different ways:
634 # 1. Revert to the base
635 test_all_match git checkout base -- deep/deeper2/a &&
636 test_all_match git status --porcelain=v2 &&
638 # 2. Add the file with conflict markers
639 test_all_match git add folder1/a &&
640 test_all_match git status --porcelain=v2 &&
642 # 3. Rename the file to another sparse filename and
643 # accept conflict markers as resolved content.
644 run_on_all mv folder2/a folder2/z &&
645 test_all_match git add folder2 &&
646 test_all_match git status --porcelain=v2 &&
648 test_all_match git $OPERATION --continue &&
649 test_all_match git status --porcelain=v2 &&
650 test_all_match git rev-parse HEAD^{tree} || return 1
654 test_expect_success
'merge with outside renames' '
657 for type in out-to-out out-to-in in-to-out
659 test_all_match git reset --hard &&
660 test_all_match git checkout -f -b merge-$type update-deep &&
661 test_all_match git merge -m "$type" rename-$type &&
662 test_all_match git rev-parse HEAD^{tree} || return 1
666 # Sparse-index fails to convert the index in the
667 # final 'git cherry-pick' command.
668 test_expect_success
'cherry-pick with conflicts' '
671 write_script edit-conflict <<-\EOF &&
675 test_all_match git checkout -b to-cherry-pick &&
676 run_on_all ../edit-conflict ABC &&
677 test_all_match git add conflict &&
678 test_all_match git commit -m "conflict to pick" &&
680 test_all_match git checkout -B base HEAD~1 &&
681 run_on_all ../edit-conflict DEF &&
682 test_all_match git add conflict &&
683 test_all_match git commit -m "conflict in base" &&
685 test_all_match test_must_fail git cherry-pick to-cherry-pick
688 test_expect_success
'clean' '
691 echo bogus >>.gitignore &&
692 run_on_all cp ../.gitignore . &&
693 test_all_match git add .gitignore &&
694 test_all_match git commit -m "ignore bogus files" &&
696 run_on_sparse mkdir folder1 &&
697 run_on_all touch folder1/bogus &&
699 test_all_match git status --porcelain=v2 &&
700 test_all_match git clean -f &&
701 test_all_match git status --porcelain=v2 &&
702 test_sparse_match ls &&
703 test_sparse_match ls folder1 &&
705 test_all_match git clean -xf &&
706 test_all_match git status --porcelain=v2 &&
707 test_sparse_match ls &&
708 test_sparse_match ls folder1 &&
710 test_all_match git clean -xdf &&
711 test_all_match git status --porcelain=v2 &&
712 test_sparse_match ls &&
713 test_sparse_match ls folder1 &&
715 test_sparse_match test_path_is_dir folder1
718 test_expect_success
'submodule handling' '
721 test_all_match mkdir modules &&
722 test_all_match touch modules/a &&
723 test_all_match git add modules &&
724 test_all_match git commit -m "add modules directory" &&
726 run_on_all git submodule add "$(pwd)/initial-repo" modules/sub &&
727 test_all_match git commit -m "add submodule" &&
729 # having a submodule prevents "modules" from collapse
730 test-tool -C sparse-index read-cache --table >cache &&
731 grep "100644 blob .* modules/a" cache &&
732 grep "160000 commit $(git -C initial-repo rev-parse HEAD) modules/sub" cache
735 # When working with a sparse index, some commands will need to expand the
736 # index to operate properly. If those commands also write the index back
737 # to disk, they need to convert the index to sparse before writing.
738 # This test verifies that both of these events are logged in trace2 logs.
739 test_expect_success
'sparse-index is expanded and converted back' '
742 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
743 git -C sparse-index reset -- folder1/a &&
744 test_region index convert_to_sparse trace2.txt &&
745 test_region index ensure_full_index trace2.txt
748 ensure_not_expanded
() {
750 echo >>sparse-index
/untracked.txt
&&
756 GIT_TRACE2_EVENT
="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING
=10 \
757 git
-C sparse-index
"$@" ||
return 1
759 GIT_TRACE2_EVENT
="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING
=10 \
760 git
-C sparse-index
"$@" ||
return 1
762 test_region
! index ensure_full_index trace2.txt
765 test_expect_success
'sparse-index is not expanded' '
768 ensure_not_expanded status &&
769 ensure_not_expanded commit --allow-empty -m empty &&
770 echo >>sparse-index/a &&
771 ensure_not_expanded commit -a -m a &&
772 echo >>sparse-index/a &&
773 ensure_not_expanded commit --include a -m a &&
774 echo >>sparse-index/deep/deeper1/a &&
775 ensure_not_expanded commit --include deep/deeper1/a -m deeper &&
776 ensure_not_expanded checkout rename-out-to-out &&
777 ensure_not_expanded checkout - &&
778 ensure_not_expanded switch rename-out-to-out &&
779 ensure_not_expanded switch - &&
780 ensure_not_expanded reset --hard &&
781 ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
782 ensure_not_expanded reset --hard &&
783 ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
785 echo >>sparse-index/README.md &&
786 ensure_not_expanded add -A &&
787 echo >>sparse-index/extra.txt &&
788 ensure_not_expanded add extra.txt &&
789 echo >>sparse-index/untracked.txt &&
790 ensure_not_expanded add . &&
792 for ref in update-deep update-folder1 update-folder2 update-deep
794 echo >>sparse-index/README.md &&
795 ensure_not_expanded reset --hard $ref || return 1
798 ensure_not_expanded reset --hard update-deep &&
799 ensure_not_expanded reset --keep base &&
800 ensure_not_expanded reset --merge update-deep &&
801 ensure_not_expanded reset --hard &&
803 ensure_not_expanded checkout -f update-deep &&
804 test_config -C sparse-index pull.twohead ort &&
806 sane_unset GIT_TEST_MERGE_ALGORITHM &&
807 for OPERATION in "merge -m merge" cherry-pick rebase
809 ensure_not_expanded merge -m merge update-folder1 &&
810 ensure_not_expanded merge -m merge update-folder2 || return 1
815 test_expect_success
'sparse-index is not expanded: merge conflict in cone' '
818 for side in right left
820 git -C sparse-index checkout -b expand-$side base &&
821 echo $side >sparse-index/deep/a &&
822 git -C sparse-index commit -a -m "$side" || return 1
826 sane_unset GIT_TEST_MERGE_ALGORITHM &&
827 git -C sparse-index config pull.twohead ort &&
828 ensure_not_expanded ! merge -m merged expand-right
832 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
833 # in this scenario, but it shouldn't.
834 test_expect_success
'reset mixed and checkout orphan' '
837 test_all_match git checkout rename-out-to-in &&
839 # Sparse checkouts do not agree with full checkouts about
840 # how to report a directory/file conflict during a reset.
841 # This command would fail with test_all_match because the
842 # full checkout reports "T folder1/0/1" while a sparse
843 # checkout reports "D folder1/0/1". This matches because
844 # the sparse checkouts skip "adding" the other side of
846 test_sparse_match git reset --mixed HEAD~1 &&
847 test_sparse_match test-tool read-cache --table --expand &&
848 test_sparse_match git status --porcelain=v2 &&
850 # At this point, sparse-checkouts behave differently
851 # from the full-checkout.
852 test_sparse_match git checkout --orphan new-branch &&
853 test_sparse_match test-tool read-cache --table --expand &&
854 test_sparse_match git status --porcelain=v2
857 test_expect_success
'add everything with deep new file' '
860 run_on_sparse git sparse-checkout set deep/deeper1/deepest &&
862 run_on_all touch deep/deeper1/x &&
863 test_all_match git add . &&
864 test_all_match git status --porcelain=v2
867 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
868 # directory/file conflicts, even without sparse-checkout. Use this
869 # test only as a documentation of the incorrect behavior, not a
870 # measure of how it _should_ behave.
871 test_expect_success
'checkout behaves oddly with df-conflict-1' '
874 test_sparse_match git sparse-checkout disable &&
876 write_script edit-content <<-\EOF &&
877 echo content >>folder1/larger-content
881 run_on_all ../edit-content &&
882 test_all_match git status --porcelain=v2 &&
884 git -C sparse-checkout sparse-checkout init --cone &&
885 git -C sparse-index sparse-checkout init --cone --sparse-index &&
887 test_all_match git status --porcelain=v2 &&
889 # This checkout command should fail, because we have a staged
890 # change to folder1/larger-content, but the destination changes
892 git -C full-checkout checkout df-conflict-1 \
893 1>full-checkout-out \
894 2>full-checkout-err &&
895 git -C sparse-checkout checkout df-conflict-1 \
896 1>sparse-checkout-out \
897 2>sparse-checkout-err &&
898 git -C sparse-index checkout df-conflict-1 \
900 2>sparse-index-err &&
902 # Instead, the checkout deletes the folder1 file and adds the
903 # folder1/larger-content file, leaving all other paths that were
904 # in folder1/ as deleted (without any warning).
905 cat >expect <<-EOF &&
907 A folder1/larger-content
909 test_cmp expect full-checkout-out &&
910 test_cmp expect sparse-checkout-out &&
912 # The sparse-index reports no output
913 test_must_be_empty sparse-index-out &&
915 # stderr: Switched to branch df-conflict-1
916 test_cmp full-checkout-err sparse-checkout-err &&
917 test_cmp full-checkout-err sparse-checkout-err
920 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
921 # directory/file conflicts, even without sparse-checkout. Use this
922 # test only as a documentation of the incorrect behavior, not a
923 # measure of how it _should_ behave.
924 test_expect_success
'checkout behaves oddly with df-conflict-2' '
927 test_sparse_match git sparse-checkout disable &&
929 write_script edit-content <<-\EOF &&
930 echo content >>folder2/larger-content
934 run_on_all ../edit-content &&
935 test_all_match git status --porcelain=v2 &&
937 git -C sparse-checkout sparse-checkout init --cone &&
938 git -C sparse-index sparse-checkout init --cone --sparse-index &&
940 test_all_match git status --porcelain=v2 &&
942 # This checkout command should fail, because we have a staged
943 # change to folder1/larger-content, but the destination changes
945 git -C full-checkout checkout df-conflict-2 \
946 1>full-checkout-out \
947 2>full-checkout-err &&
948 git -C sparse-checkout checkout df-conflict-2 \
949 1>sparse-checkout-out \
950 2>sparse-checkout-err &&
951 git -C sparse-index checkout df-conflict-2 \
953 2>sparse-index-err &&
955 # The full checkout deviates from the df-conflict-1 case here!
956 # It drops the change to folder1/larger-content and leaves the
957 # folder1 path as-is on disk. The sparse-index behaves the same.
958 test_must_be_empty full-checkout-out &&
959 test_must_be_empty sparse-index-out &&
961 # In the sparse-checkout case, the checkout deletes the folder1
962 # file and adds the folder1/larger-content file, leaving all other
963 # paths that were in folder1/ as deleted (without any warning).
964 cat >expect <<-EOF &&
966 A folder2/larger-content
968 test_cmp expect sparse-checkout-out &&
970 # Switched to branch df-conflict-1
971 test_cmp full-checkout-err sparse-checkout-err &&
972 test_cmp full-checkout-err sparse-index-err