packfile: convert has_packed_and_bad() to object_id
[git/debian.git] / t / t1092-sparse-checkout-compatibility.sh
blobddc86bb4152361fbda501c24c3be97b47aefdf6d
1 #!/bin/sh
3 test_description='compare full workdir to sparse workdir'
5 GIT_TEST_SPLIT_INDEX=0
6 GIT_TEST_SPARSE_INDEX=
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 git init initial-repo &&
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 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 &&
24 cp a folder1 &&
25 cp a folder2 &&
26 cp a x &&
27 cp a deep &&
28 cp a deep/before &&
29 cp a deep/deeper1 &&
30 cp a deep/deeper2 &&
31 cp a deep/later &&
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 &&
38 >folder1- &&
39 >folder1.x &&
40 >folder10 &&
41 cp -r deep/deeper1/0 folder1 &&
42 cp -r deep/deeper1/0 folder2 &&
43 echo >>folder1/0/0/0 &&
44 echo >>folder2/0/1 &&
45 git add . &&
46 git commit -m "initial commit" &&
47 git checkout -b base &&
48 for dir in folder1 folder2 deep
50 git checkout -b update-$dir &&
51 echo "updated $dir" >$dir/a &&
52 git commit -a -m "update $dir" || return 1
53 done &&
55 git checkout -b rename-base base &&
56 cat >folder1/larger-content <<-\EOF &&
57 matching
58 lines
59 help
60 inexact
61 renames
62 EOF
63 cp folder1/larger-content folder2/ &&
64 cp folder1/larger-content deep/deeper1/ &&
65 git add . &&
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 &&
72 echo >>folder2/0/1 &&
73 echo stuff >>deep/deeper1/a &&
74 git add . &&
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 &&
80 rm folder2/0/1 &&
81 mkdir folder2/0/1 &&
82 echo >>folder2/0/1/1 &&
83 mv folder1/larger-content deep/deeper1/edited-content &&
84 echo >>deep/deeper1/edited-content &&
85 git add . &&
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 &&
90 echo >>folder2/0/1 &&
91 rm -rf folder1/0/0 &&
92 echo >>folder1/0/0 &&
93 mv deep/deeper1/larger-content folder1/edited-content &&
94 echo >>folder1/edited-content &&
95 git add . &&
96 git commit -m "rename deep/deeper1/... to folder1/..." &&
98 git checkout -b df-conflict-1 base &&
99 rm -rf folder1 &&
100 echo content >folder1 &&
101 git add . &&
102 git commit -m "dir to file" &&
104 git checkout -b df-conflict-2 base &&
105 rm -rf folder2 &&
106 echo content >folder2 &&
107 git add . &&
108 git commit -m "dir to file" &&
110 git checkout -b fd-conflict base &&
111 rm a &&
112 mkdir a &&
113 echo content >a/a &&
114 git add . &&
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 &&
123 git add . &&
124 git commit -m "$side" || return 1
125 done &&
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 &&
132 git reset --hard
136 init_repos () {
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
157 run_on_sparse () {
159 cd sparse-checkout &&
160 GIT_PROGRESS_DELAY=100000 "$@" >../sparse-checkout-out 2>../sparse-checkout-err
161 ) &&
163 cd sparse-index &&
164 GIT_PROGRESS_DELAY=100000 "$@" >../sparse-index-out 2>../sparse-index-err
168 run_on_all () {
170 cd full-checkout &&
171 GIT_PROGRESS_DELAY=100000 "$@" >../full-checkout-out 2>../full-checkout-err
172 ) &&
173 run_on_sparse "$@"
176 test_all_match () {
177 run_on_all "$@" &&
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' '
191 init_repos &&
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 \
198 || return 1
199 done &&
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 \
208 || return 1
209 done &&
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 \
218 || return 1
219 done &&
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' '
230 init_repos &&
231 test_sparse_match test-tool read-cache --expand --table
234 test_expect_success 'status with options' '
235 init_repos &&
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' '
251 init_repos &&
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' '
259 init_repos &&
261 write_script edit-contents <<-\EOF &&
262 echo text >>$1
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' '
295 init_repos &&
297 write_script edit-file <<-\EOF &&
298 echo $1 >$2
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' '
323 init_repos &&
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 &&
333 echo text >>$1
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' '
360 init_repos &&
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' '
375 init_repos &&
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' '
392 init_repos &&
394 for branch in rename-out-to-out \
395 rename-out-to-in \
396 rename-in-to-out \
397 df-conflict-1 \
398 fd-conflict
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
405 done
408 test_expect_success 'diff with directory/file conflicts' '
409 init_repos &&
411 for branch in rename-out-to-out \
412 rename-out-to-in \
413 rename-in-to-out \
414 df-conflict-1 \
415 df-conflict-2 \
416 fd-conflict
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
425 done
428 test_expect_success 'log with pathspec outside sparse definition' '
429 init_repos &&
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' '
443 init_repos &&
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' '
454 init_repos &&
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 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
463 # in this scenario, but it shouldn't.
464 test_expect_failure 'checkout and reset (mixed)' '
465 init_repos &&
467 test_all_match git checkout -b reset-test update-deep &&
468 test_all_match git reset deepest &&
469 test_all_match git reset update-folder1 &&
470 test_all_match git reset update-folder2
473 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
474 # in this scenario, but it shouldn't.
475 test_expect_success 'checkout and reset (mixed) [sparse]' '
476 init_repos &&
478 test_sparse_match git checkout -b reset-test update-deep &&
479 test_sparse_match git reset deepest &&
480 test_sparse_match git reset update-folder1 &&
481 test_sparse_match git reset update-folder2
484 test_expect_success 'merge' '
485 init_repos &&
487 test_all_match git checkout -b merge update-deep &&
488 test_all_match git merge -m "folder1" update-folder1 &&
489 test_all_match git rev-parse HEAD^{tree} &&
490 test_all_match git merge -m "folder2" update-folder2 &&
491 test_all_match git rev-parse HEAD^{tree}
494 # NEEDSWORK: This test is documenting current behavior, but that
495 # behavior can be confusing to users so there is desire to change it.
496 # Right now, users might be using this flow to work through conflicts,
497 # so any solution should present advice to users who try this sequence
498 # of commands to follow whatever new method we create.
499 test_expect_success 'merge with conflict outside cone' '
500 init_repos &&
502 test_all_match git checkout -b merge-tip merge-left &&
503 test_all_match git status --porcelain=v2 &&
504 test_all_match test_must_fail git merge -m merge merge-right &&
505 test_all_match git status --porcelain=v2 &&
507 # Resolve the conflict in different ways:
508 # 1. Revert to the base
509 test_all_match git checkout base -- deep/deeper2/a &&
510 test_all_match git status --porcelain=v2 &&
512 # 2. Add the file with conflict markers
513 test_all_match git add folder1/a &&
514 test_all_match git status --porcelain=v2 &&
516 # 3. Rename the file to another sparse filename and
517 # accept conflict markers as resolved content.
518 run_on_all mv folder2/a folder2/z &&
519 test_all_match git add folder2 &&
520 test_all_match git status --porcelain=v2 &&
522 test_all_match git merge --continue &&
523 test_all_match git status --porcelain=v2 &&
524 test_all_match git rev-parse HEAD^{tree}
527 test_expect_success 'merge with outside renames' '
528 init_repos &&
530 for type in out-to-out out-to-in in-to-out
532 test_all_match git reset --hard &&
533 test_all_match git checkout -f -b merge-$type update-deep &&
534 test_all_match git merge -m "$type" rename-$type &&
535 test_all_match git rev-parse HEAD^{tree} || return 1
536 done
539 # Sparse-index fails to convert the index in the
540 # final 'git cherry-pick' command.
541 test_expect_success 'cherry-pick with conflicts' '
542 init_repos &&
544 write_script edit-conflict <<-\EOF &&
545 echo $1 >conflict
548 test_all_match git checkout -b to-cherry-pick &&
549 run_on_all ../edit-conflict ABC &&
550 test_all_match git add conflict &&
551 test_all_match git commit -m "conflict to pick" &&
553 test_all_match git checkout -B base HEAD~1 &&
554 run_on_all ../edit-conflict DEF &&
555 test_all_match git add conflict &&
556 test_all_match git commit -m "conflict in base" &&
558 test_all_match test_must_fail git cherry-pick to-cherry-pick
561 test_expect_success 'clean' '
562 init_repos &&
564 echo bogus >>.gitignore &&
565 run_on_all cp ../.gitignore . &&
566 test_all_match git add .gitignore &&
567 test_all_match git commit -m "ignore bogus files" &&
569 run_on_sparse mkdir folder1 &&
570 run_on_all touch folder1/bogus &&
572 test_all_match git status --porcelain=v2 &&
573 test_all_match git clean -f &&
574 test_all_match git status --porcelain=v2 &&
575 test_sparse_match ls &&
576 test_sparse_match ls folder1 &&
578 test_all_match git clean -xf &&
579 test_all_match git status --porcelain=v2 &&
580 test_sparse_match ls &&
581 test_sparse_match ls folder1 &&
583 test_all_match git clean -xdf &&
584 test_all_match git status --porcelain=v2 &&
585 test_sparse_match ls &&
586 test_sparse_match ls folder1 &&
588 test_sparse_match test_path_is_dir folder1
591 test_expect_success 'submodule handling' '
592 init_repos &&
594 test_all_match mkdir modules &&
595 test_all_match touch modules/a &&
596 test_all_match git add modules &&
597 test_all_match git commit -m "add modules directory" &&
599 run_on_all git submodule add "$(pwd)/initial-repo" modules/sub &&
600 test_all_match git commit -m "add submodule" &&
602 # having a submodule prevents "modules" from collapse
603 test-tool -C sparse-index read-cache --table >cache &&
604 grep "100644 blob .* modules/a" cache &&
605 grep "160000 commit $(git -C initial-repo rev-parse HEAD) modules/sub" cache
608 test_expect_success 'sparse-index is expanded and converted back' '
609 init_repos &&
611 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
612 git -C sparse-index -c core.fsmonitor="" reset --hard &&
613 test_region index convert_to_sparse trace2.txt &&
614 test_region index ensure_full_index trace2.txt
617 ensure_not_expanded () {
618 rm -f trace2.txt &&
619 echo >>sparse-index/untracked.txt &&
620 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
621 git -C sparse-index "$@" &&
622 test_region ! index ensure_full_index trace2.txt
625 test_expect_success 'sparse-index is not expanded' '
626 init_repos &&
628 ensure_not_expanded status &&
629 ensure_not_expanded commit --allow-empty -m empty &&
630 echo >>sparse-index/a &&
631 ensure_not_expanded commit -a -m a &&
632 echo >>sparse-index/a &&
633 ensure_not_expanded commit --include a -m a &&
634 echo >>sparse-index/deep/deeper1/a &&
635 ensure_not_expanded commit --include deep/deeper1/a -m deeper &&
636 ensure_not_expanded checkout rename-out-to-out &&
637 ensure_not_expanded checkout - &&
638 ensure_not_expanded switch rename-out-to-out &&
639 ensure_not_expanded switch - &&
640 git -C sparse-index reset --hard &&
641 ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
642 git -C sparse-index reset --hard &&
643 ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
645 echo >>sparse-index/README.md &&
646 ensure_not_expanded add -A &&
647 echo >>sparse-index/extra.txt &&
648 ensure_not_expanded add extra.txt &&
649 echo >>sparse-index/untracked.txt &&
650 ensure_not_expanded add .
653 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
654 # in this scenario, but it shouldn't.
655 test_expect_success 'reset mixed and checkout orphan' '
656 init_repos &&
658 test_all_match git checkout rename-out-to-in &&
660 # Sparse checkouts do not agree with full checkouts about
661 # how to report a directory/file conflict during a reset.
662 # This command would fail with test_all_match because the
663 # full checkout reports "T folder1/0/1" while a sparse
664 # checkout reports "D folder1/0/1". This matches because
665 # the sparse checkouts skip "adding" the other side of
666 # the conflict.
667 test_sparse_match git reset --mixed HEAD~1 &&
668 test_sparse_match test-tool read-cache --table --expand &&
669 test_sparse_match git status --porcelain=v2 &&
671 # At this point, sparse-checkouts behave differently
672 # from the full-checkout.
673 test_sparse_match git checkout --orphan new-branch &&
674 test_sparse_match test-tool read-cache --table --expand &&
675 test_sparse_match git status --porcelain=v2
678 test_expect_success 'add everything with deep new file' '
679 init_repos &&
681 run_on_sparse git sparse-checkout set deep/deeper1/deepest &&
683 run_on_all touch deep/deeper1/x &&
684 test_all_match git add . &&
685 test_all_match git status --porcelain=v2
688 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
689 # directory/file conflicts, even without sparse-checkout. Use this
690 # test only as a documentation of the incorrect behavior, not a
691 # measure of how it _should_ behave.
692 test_expect_success 'checkout behaves oddly with df-conflict-1' '
693 init_repos &&
695 test_sparse_match git sparse-checkout disable &&
697 write_script edit-content <<-\EOF &&
698 echo content >>folder1/larger-content
699 git add folder1
702 run_on_all ../edit-content &&
703 test_all_match git status --porcelain=v2 &&
705 git -C sparse-checkout sparse-checkout init --cone &&
706 git -C sparse-index sparse-checkout init --cone --sparse-index &&
708 test_all_match git status --porcelain=v2 &&
710 # This checkout command should fail, because we have a staged
711 # change to folder1/larger-content, but the destination changes
712 # folder1 to a file.
713 git -C full-checkout checkout df-conflict-1 \
714 1>full-checkout-out \
715 2>full-checkout-err &&
716 git -C sparse-checkout checkout df-conflict-1 \
717 1>sparse-checkout-out \
718 2>sparse-checkout-err &&
719 git -C sparse-index checkout df-conflict-1 \
720 1>sparse-index-out \
721 2>sparse-index-err &&
723 # Instead, the checkout deletes the folder1 file and adds the
724 # folder1/larger-content file, leaving all other paths that were
725 # in folder1/ as deleted (without any warning).
726 cat >expect <<-EOF &&
727 D folder1
728 A folder1/larger-content
730 test_cmp expect full-checkout-out &&
731 test_cmp expect sparse-checkout-out &&
733 # The sparse-index reports no output
734 test_must_be_empty sparse-index-out &&
736 # stderr: Switched to branch df-conflict-1
737 test_cmp full-checkout-err sparse-checkout-err &&
738 test_cmp full-checkout-err sparse-checkout-err
741 # NEEDSWORK: 'git checkout' behaves incorrectly in the case of
742 # directory/file conflicts, even without sparse-checkout. Use this
743 # test only as a documentation of the incorrect behavior, not a
744 # measure of how it _should_ behave.
745 test_expect_success 'checkout behaves oddly with df-conflict-2' '
746 init_repos &&
748 test_sparse_match git sparse-checkout disable &&
750 write_script edit-content <<-\EOF &&
751 echo content >>folder2/larger-content
752 git add folder2
755 run_on_all ../edit-content &&
756 test_all_match git status --porcelain=v2 &&
758 git -C sparse-checkout sparse-checkout init --cone &&
759 git -C sparse-index sparse-checkout init --cone --sparse-index &&
761 test_all_match git status --porcelain=v2 &&
763 # This checkout command should fail, because we have a staged
764 # change to folder1/larger-content, but the destination changes
765 # folder1 to a file.
766 git -C full-checkout checkout df-conflict-2 \
767 1>full-checkout-out \
768 2>full-checkout-err &&
769 git -C sparse-checkout checkout df-conflict-2 \
770 1>sparse-checkout-out \
771 2>sparse-checkout-err &&
772 git -C sparse-index checkout df-conflict-2 \
773 1>sparse-index-out \
774 2>sparse-index-err &&
776 # The full checkout deviates from the df-conflict-1 case here!
777 # It drops the change to folder1/larger-content and leaves the
778 # folder1 path as-is on disk. The sparse-index behaves the same.
779 test_must_be_empty full-checkout-out &&
780 test_must_be_empty sparse-index-out &&
782 # In the sparse-checkout case, the checkout deletes the folder1
783 # file and adds the folder1/larger-content file, leaving all other
784 # paths that were in folder1/ as deleted (without any warning).
785 cat >expect <<-EOF &&
786 D folder2
787 A folder2/larger-content
789 test_cmp expect sparse-checkout-out &&
791 # Switched to branch df-conflict-1
792 test_cmp full-checkout-err sparse-checkout-err &&
793 test_cmp full-checkout-err sparse-index-err
796 test_done