3 test_description
='sparse checkout builtin tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 GIT_TEST_SPLIT_INDEX
=false
9 export GIT_TEST_SPLIT_INDEX
14 # Do not replace this with 'ls "$1"', as "ls" with BSD-lineage
15 # enables "-A" by default for root and ends up including ".git" and
16 # such in its output. (Note, though, that running the test suite as
17 # root is generally not recommended.)
18 (cd "$1" && printf '%s\n' *)
22 list_files
"$1" >actual
&&
24 printf "%s\n" $@
>expect
&&
25 test_cmp expect actual
28 test_expect_success
'setup' '
33 mkdir folder1 folder2 deep &&
34 mkdir deep/deeper1 deep/deeper2 &&
35 mkdir deep/deeper1/deepest &&
41 cp a deep/deeper1/deepest &&
43 git commit -m "initial commit"
47 test_expect_success
'git sparse-checkout list (not sparse)' '
48 test_must_fail git -C repo sparse-checkout list >list 2>err &&
49 test_must_be_empty list &&
50 test_i18ngrep "this worktree is not sparse" err
53 test_expect_success
'git sparse-checkout list (not sparse)' '
54 git -C repo sparse-checkout set &&
55 rm repo/.git/info/sparse-checkout &&
56 git -C repo sparse-checkout list >list 2>err &&
57 test_must_be_empty list &&
58 test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err
61 test_expect_success
'git sparse-checkout list (populated)' '
62 test_when_finished rm -f repo/.git/info/sparse-checkout &&
63 cat >repo/.git/info/sparse-checkout <<-\EOF &&
69 cp repo/.git/info/sparse-checkout expect &&
70 git -C repo sparse-checkout list >list &&
74 test_expect_success
'git sparse-checkout init' '
75 git -C repo sparse-checkout init &&
76 cat >expect <<-\EOF &&
80 test_cmp expect repo/.git/info/sparse-checkout &&
81 test_cmp_config -C repo true core.sparsecheckout &&
85 test_expect_success
'git sparse-checkout init in empty repo' '
86 test_when_finished rm -rf empty-repo blank-template &&
87 git init --template= empty-repo &&
88 git -C empty-repo sparse-checkout init
91 test_expect_success
'git sparse-checkout list after init' '
92 git -C repo sparse-checkout list >actual &&
93 cat >expect <<-\EOF &&
97 test_cmp expect actual
100 test_expect_success
'init with existing sparse-checkout' '
101 echo "*folder*" >> repo/.git/info/sparse-checkout &&
102 git -C repo sparse-checkout init &&
103 cat >expect <<-\EOF &&
108 test_cmp expect repo/.git/info/sparse-checkout &&
109 check_files repo a folder1 folder2
112 test_expect_success
'clone --sparse' '
113 git clone --sparse "file://$(pwd)/repo" clone &&
114 git -C clone sparse-checkout list >actual &&
115 cat >expect <<-\EOF &&
119 test_cmp expect actual &&
123 test_expect_success
'switching to cone mode with non-cone mode patterns' '
124 git init bad-patterns &&
127 git sparse-checkout init &&
128 git sparse-checkout add dir &&
129 git config --worktree core.sparseCheckoutCone true &&
130 test_must_fail git sparse-checkout add dir 2>err &&
131 grep "existing sparse-checkout patterns do not use cone mode" err
135 test_expect_success
'interaction with clone --no-checkout (unborn index)' '
136 git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout &&
137 git -C clone_no_checkout sparse-checkout init --cone &&
138 git -C clone_no_checkout sparse-checkout set folder1 &&
140 git -C clone_no_checkout sparse-checkout list >actual &&
141 cat >expect <<-\EOF &&
144 test_cmp expect actual &&
146 # nothing checked out, expect "No such file or directory"
147 ! ls clone_no_checkout/* >actual &&
148 test_must_be_empty actual &&
149 test_path_is_missing clone_no_checkout/.git/index &&
151 # No branch is checked out until we manually switch to one
152 git -C clone_no_checkout switch main &&
153 test_path_is_file clone_no_checkout/.git/index &&
154 check_files clone_no_checkout a folder1
157 test_expect_success
'set enables config' '
158 git init worktree-config &&
160 cd worktree-config &&
161 test_commit test file &&
162 test_path_is_missing .git/config.worktree &&
163 git sparse-checkout set nothing &&
164 test_path_is_file .git/config.worktree &&
165 test_cmp_config true core.sparseCheckout
169 test_expect_success
'set sparse-checkout using builtin' '
170 git -C repo sparse-checkout set "/*" "!/*/" "*folder*" &&
171 cat >expect <<-\EOF &&
176 git -C repo sparse-checkout list >actual &&
177 test_cmp expect actual &&
178 test_cmp expect repo/.git/info/sparse-checkout &&
179 check_files repo a folder1 folder2
182 test_expect_success
'set sparse-checkout using --stdin' '
183 cat >expect <<-\EOF &&
189 git -C repo sparse-checkout set --stdin <expect &&
190 git -C repo sparse-checkout list >actual &&
191 test_cmp expect actual &&
192 test_cmp expect repo/.git/info/sparse-checkout &&
193 check_files repo "a folder1 folder2"
196 test_expect_success
'add to sparse-checkout' '
197 cat repo/.git/info/sparse-checkout >old &&
198 test_when_finished cp old repo/.git/info/sparse-checkout &&
206 git -C repo sparse-checkout add --stdin <add &&
207 git -C repo sparse-checkout list >actual &&
208 test_cmp expect actual &&
209 test_cmp expect repo/.git/info/sparse-checkout &&
210 check_files repo "a folder1 folder2"
213 test_expect_success
'worktree: add copies sparse-checkout patterns' '
214 cat repo/.git/info/sparse-checkout >old &&
215 test_when_finished cp old repo/.git/info/sparse-checkout &&
216 test_when_finished git -C repo worktree remove ../worktree &&
217 git -C repo sparse-checkout set --no-cone "/*" &&
218 git -C repo worktree add --quiet ../worktree 2>err &&
219 test_must_be_empty err &&
220 new="$(git -C worktree rev-parse --git-path info/sparse-checkout)" &&
221 test_path_is_file "$new" &&
222 test_cmp repo/.git/info/sparse-checkout "$new" &&
223 git -C worktree sparse-checkout set --cone &&
224 test_cmp_config -C worktree true core.sparseCheckoutCone &&
225 test_must_fail git -C repo core.sparseCheckoutCone
228 test_expect_success
'cone mode: match patterns' '
229 git -C repo config --worktree core.sparseCheckoutCone true &&
230 rm -rf repo/a repo/folder1 repo/folder2 &&
231 git -C repo read-tree -mu HEAD 2>err &&
232 test_i18ngrep ! "disabling cone patterns" err &&
233 git -C repo reset --hard &&
234 check_files repo a folder1 folder2
237 test_expect_success
'cone mode: warn on bad pattern' '
238 test_when_finished mv sparse-checkout repo/.git/info/ &&
239 cp repo/.git/info/sparse-checkout . &&
240 echo "!/deep/deeper/*" >>repo/.git/info/sparse-checkout &&
241 git -C repo read-tree -mu HEAD 2>err &&
242 test_i18ngrep "unrecognized negative pattern" err
245 test_expect_success
'sparse-checkout disable' '
246 test_when_finished rm -rf repo/.git/info/sparse-checkout &&
247 git -C repo sparse-checkout disable &&
248 test_path_is_file repo/.git/info/sparse-checkout &&
249 git -C repo config --list >config &&
250 test_must_fail git config core.sparseCheckout &&
251 check_files repo a deep folder1 folder2
254 test_expect_success
'sparse-index enabled and disabled' '
255 git -C repo sparse-checkout init --cone --sparse-index &&
256 test_cmp_config -C repo true index.sparse &&
257 git -C repo ls-files --sparse >sparse &&
258 git -C repo sparse-checkout disable &&
259 git -C repo ls-files --sparse >full &&
261 cat >expect <<-\EOF &&
269 +deep/deeper1/deepest/a
275 diff -u sparse full | tail -n +3 >actual &&
276 test_cmp expect actual &&
278 git -C repo config --list >config &&
279 test_cmp_config -C repo false index.sparse
282 test_expect_success
'cone mode: init and set' '
283 git -C repo sparse-checkout init --cone &&
284 git -C repo config --list >config &&
285 test_i18ngrep "core.sparsecheckoutcone=true" config &&
286 list_files repo >dir &&
288 test_cmp expect dir &&
289 git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
290 test_must_be_empty err &&
291 check_files repo a deep &&
292 check_files repo/deep a deeper1 &&
293 check_files repo/deep/deeper1 a deepest &&
294 cat >expect <<-\EOF &&
301 /deep/deeper1/deepest/
303 test_cmp expect repo/.git/info/sparse-checkout &&
304 git -C repo sparse-checkout set --stdin 2>err <<-\EOF &&
308 test_must_be_empty err &&
309 check_files repo a folder1 folder2
312 test_expect_success
'cone mode: list' '
313 cat >expect <<-\EOF &&
317 git -C repo sparse-checkout set --stdin <expect &&
318 git -C repo sparse-checkout list >actual 2>err &&
319 test_must_be_empty err &&
320 test_cmp expect actual
323 test_expect_success
'cone mode: set with nested folders' '
324 git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&
325 test_line_count = 0 err &&
326 cat >expect <<-\EOF &&
331 test_cmp repo/.git/info/sparse-checkout expect
334 test_expect_success
'cone mode: add independent path' '
335 git -C repo sparse-checkout set deep/deeper1 &&
336 git -C repo sparse-checkout add folder1 &&
337 cat >expect <<-\EOF &&
345 test_cmp expect repo/.git/info/sparse-checkout &&
346 check_files repo a deep folder1
349 test_expect_success
'cone mode: add sibling path' '
350 git -C repo sparse-checkout set deep/deeper1 &&
351 git -C repo sparse-checkout add deep/deeper2 &&
352 cat >expect <<-\EOF &&
360 test_cmp expect repo/.git/info/sparse-checkout &&
361 check_files repo a deep
364 test_expect_success
'cone mode: add parent path' '
365 git -C repo sparse-checkout set deep/deeper1 folder1 &&
366 git -C repo sparse-checkout add deep &&
367 cat >expect <<-\EOF &&
373 test_cmp expect repo/.git/info/sparse-checkout &&
374 check_files repo a deep folder1
377 test_expect_success
'not-up-to-date does not block rest of sparsification' '
378 test_when_finished git -C repo sparse-checkout disable &&
379 test_when_finished git -C repo reset --hard &&
380 git -C repo sparse-checkout set deep &&
382 echo update >repo/deep/deeper2/a &&
383 cp repo/.git/info/sparse-checkout expect &&
384 test_write_lines "!/deep/*/" "/deep/deeper1/" >>expect &&
386 git -C repo sparse-checkout set deep/deeper1 2>err &&
388 test_i18ngrep "The following paths are not up to date" err &&
389 test_cmp expect repo/.git/info/sparse-checkout &&
390 check_files repo/deep a deeper1 deeper2 &&
391 check_files repo/deep/deeper1 a deepest &&
392 check_files repo/deep/deeper1/deepest a &&
393 check_files repo/deep/deeper2 a
396 test_expect_success
'revert to old sparse-checkout on empty update' '
397 git init empty-test &&
401 git commit -m "test" &&
402 git sparse-checkout set nothing 2>err &&
403 test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err &&
404 test_i18ngrep ! ".git/index.lock" err &&
405 git sparse-checkout set file
409 test_expect_success
'fail when lock is taken' '
410 test_when_finished rm -rf repo/.git/info/sparse-checkout.lock &&
411 touch repo/.git/info/sparse-checkout.lock &&
412 test_must_fail git -C repo sparse-checkout set deep 2>err &&
413 test_i18ngrep "Unable to create .*\.lock" err
416 test_expect_success
'.gitignore should not warn about cone mode' '
417 git -C repo config --worktree core.sparseCheckoutCone true &&
418 echo "**/bin/*" >repo/.gitignore &&
419 git -C repo reset --hard 2>err &&
420 test_i18ngrep ! "disabling cone patterns" err
423 test_expect_success
'sparse-checkout (init|set|disable) warns with dirty status' '
424 git clone repo dirty &&
425 echo dirty >dirty/folder1/a &&
427 git -C dirty sparse-checkout init 2>err &&
428 test_i18ngrep "warning.*The following paths are not up to date" err &&
430 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err &&
431 test_i18ngrep "warning.*The following paths are not up to date" err &&
432 test_path_is_file dirty/folder1/a &&
434 git -C dirty sparse-checkout disable 2>err &&
435 test_must_be_empty err &&
437 git -C dirty reset --hard &&
438 git -C dirty sparse-checkout init &&
439 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* &&
440 test_path_is_missing dirty/folder1/a &&
441 git -C dirty sparse-checkout disable &&
442 test_path_is_file dirty/folder1/a
445 test_expect_success
'sparse-checkout (init|set|disable) warns with unmerged status' '
446 git clone repo unmerged &&
449 0 $ZERO_OID folder1/a
450 100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1 folder1/a
452 git -C unmerged update-index --index-info <input &&
454 git -C unmerged sparse-checkout init 2>err &&
455 test_i18ngrep "warning.*The following paths are unmerged" err &&
457 git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err &&
458 test_i18ngrep "warning.*The following paths are unmerged" err &&
459 test_path_is_file dirty/folder1/a &&
461 git -C unmerged sparse-checkout disable 2>err &&
462 test_i18ngrep "warning.*The following paths are unmerged" err &&
464 git -C unmerged reset --hard &&
465 git -C unmerged sparse-checkout init &&
466 git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* &&
467 git -C unmerged sparse-checkout disable
470 test_expect_failure
'sparse-checkout reapply' '
471 git clone repo tweak &&
473 echo dirty >tweak/deep/deeper2/a &&
476 0 $ZERO_OID folder1/a
477 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a
479 git -C tweak update-index --index-info <input &&
481 git -C tweak sparse-checkout init --cone 2>err &&
482 test_i18ngrep "warning.*The following paths are not up to date" err &&
483 test_i18ngrep "warning.*The following paths are unmerged" err &&
485 git -C tweak sparse-checkout set folder2 deep/deeper1 2>err &&
486 test_i18ngrep "warning.*The following paths are not up to date" err &&
487 test_i18ngrep "warning.*The following paths are unmerged" err &&
489 git -C tweak sparse-checkout reapply 2>err &&
490 test_i18ngrep "warning.*The following paths are not up to date" err &&
491 test_path_is_file tweak/deep/deeper2/a &&
492 test_i18ngrep "warning.*The following paths are unmerged" err &&
493 test_path_is_file tweak/folder1/a &&
495 git -C tweak checkout HEAD deep/deeper2/a &&
496 git -C tweak sparse-checkout reapply 2>err &&
497 test_i18ngrep ! "warning.*The following paths are not up to date" err &&
498 test_path_is_missing tweak/deep/deeper2/a &&
499 test_i18ngrep "warning.*The following paths are unmerged" err &&
500 test_path_is_file tweak/folder1/a &&
502 # NEEDSWORK: We are asking to update a file outside of the
503 # sparse-checkout cone, but this is no longer allowed.
504 git -C tweak add folder1/a &&
505 git -C tweak sparse-checkout reapply 2>err &&
506 test_must_be_empty err &&
507 test_path_is_missing tweak/deep/deeper2/a &&
508 test_path_is_missing tweak/folder1/a &&
510 git -C tweak sparse-checkout disable
513 test_expect_success
'reapply can handle config options' '
514 git -C repo sparse-checkout init --cone --no-sparse-index &&
515 git -C repo config --worktree --list >actual &&
516 cat >expect <<-\EOF &&
517 core.sparsecheckout=true
518 core.sparsecheckoutcone=true
521 test_cmp expect actual &&
523 git -C repo sparse-checkout reapply --no-cone --no-sparse-index &&
524 git -C repo config --worktree --list >actual &&
525 cat >expect <<-\EOF &&
526 core.sparsecheckout=true
527 core.sparsecheckoutcone=false
530 test_cmp expect actual &&
532 git -C repo sparse-checkout reapply --cone --sparse-index &&
533 git -C repo config --worktree --list >actual &&
534 cat >expect <<-\EOF &&
535 core.sparsecheckout=true
536 core.sparsecheckoutcone=true
539 test_cmp expect actual &&
541 git -C repo sparse-checkout disable
544 test_expect_success
'cone mode: set with core.ignoreCase=true' '
545 rm repo/.git/info/sparse-checkout &&
546 git -C repo sparse-checkout init --cone &&
547 git -C repo -c core.ignoreCase=true sparse-checkout set folder1 &&
548 cat >expect <<-\EOF &&
553 test_cmp expect repo/.git/info/sparse-checkout &&
554 check_files repo a folder1
557 test_expect_success
'interaction with submodules' '
558 git clone repo super &&
562 git submodule add ../repo modules/child &&
564 git commit -m "add submodule" &&
565 git sparse-checkout init --cone &&
566 git sparse-checkout set folder1
568 check_files super a folder1 modules &&
569 check_files super/modules/child a deep folder1 folder2
572 test_expect_success
'different sparse-checkouts with worktrees' '
573 git -C repo sparse-checkout set --cone deep folder1 &&
574 git -C repo worktree add --detach ../worktree &&
575 check_files worktree "a deep folder1" &&
576 git -C repo sparse-checkout set --cone folder1 &&
577 git -C worktree sparse-checkout set --cone deep/deeper1 &&
578 check_files repo "a folder1" &&
579 check_files worktree "a deep"
582 test_expect_success
'set using filename keeps file on-disk' '
583 git -C repo sparse-checkout set --skip-checks a deep &&
584 cat >expect <<-\EOF &&
590 test_cmp expect repo/.git/info/sparse-checkout &&
591 check_files repo a deep
594 check_read_tree_errors
() {
598 git
-C $REPO -c core.sparseCheckoutCone
=false read-tree
-mu HEAD
2>err
&&
599 test_must_be_empty err
&&
600 check_files
$REPO "$FILES" &&
601 git
-C $REPO read-tree
-mu HEAD
2>err
&&
604 test_must_be_empty err
606 test_i18ngrep
"$ERRORS" err
608 check_files
$REPO $FILES
611 test_expect_success
'pattern-checks: /A/**' '
612 cat >repo/.git/info/sparse-checkout <<-\EOF &&
617 check_read_tree_errors repo "a folder1" "disabling cone pattern matching"
620 test_expect_success
'pattern-checks: /A/**/B/' '
621 cat >repo/.git/info/sparse-checkout <<-\EOF &&
626 check_read_tree_errors repo "a deep" "disabling cone pattern matching" &&
627 check_files repo/deep "deeper1" &&
628 check_files repo/deep/deeper1 "deepest"
631 test_expect_success
'pattern-checks: too short' '
632 cat >repo/.git/info/sparse-checkout <<-\EOF &&
637 check_read_tree_errors repo "a" "disabling cone pattern matching"
639 test_expect_success
'pattern-checks: not too short' '
640 cat >repo/.git/info/sparse-checkout <<-\EOF &&
645 git -C repo read-tree -mu HEAD 2>err &&
646 test_must_be_empty err &&
650 test_expect_success
'pattern-checks: trailing "*"' '
651 cat >repo/.git/info/sparse-checkout <<-\EOF &&
656 check_read_tree_errors repo "a" "disabling cone pattern matching"
659 test_expect_success
'pattern-checks: starting "*"' '
660 cat >repo/.git/info/sparse-checkout <<-\EOF &&
665 check_read_tree_errors repo "a deep" "disabling cone pattern matching"
668 test_expect_success
'pattern-checks: contained glob characters' '
669 for c in "[a]" "\\" "?" "*"
671 cat >repo/.git/info/sparse-checkout <<-EOF &&
676 check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1
680 test_expect_success BSLASHPSPEC
'pattern-checks: escaped characters' '
681 git clone repo escaped &&
682 TREEOID=$(git -C escaped rev-parse HEAD:folder1) &&
683 NEWTREE=$(git -C escaped mktree <<-EOF
684 $(git -C escaped ls-tree HEAD)
685 040000 tree $TREEOID zbad\\dir
686 040000 tree $TREEOID zdoes*exist
687 040000 tree $TREEOID zglob[!a]?
690 COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) &&
691 git -C escaped reset --hard $COMMIT &&
692 check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
693 git -C escaped sparse-checkout init --cone &&
694 git -C escaped sparse-checkout set --skip-checks zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" &&
695 cat >expect <<-\EOF &&
705 test_cmp expect escaped/.git/info/sparse-checkout &&
706 check_read_tree_errors escaped "a zbad\\dir zdoes*exist zglob[!a]?" &&
707 git -C escaped ls-tree -d --name-only HEAD >list-expect &&
708 git -C escaped sparse-checkout set --stdin <list-expect &&
709 cat >expect <<-\EOF &&
719 test_cmp expect escaped/.git/info/sparse-checkout &&
720 check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
721 git -C escaped sparse-checkout list >list-actual &&
722 test_cmp list-expect list-actual
725 test_expect_success MINGW
'cone mode replaces backslashes with slashes' '
726 git -C repo sparse-checkout set deep\\deeper1 &&
727 cat >expect <<-\EOF &&
734 test_cmp expect repo/.git/info/sparse-checkout &&
735 check_files repo a deep &&
736 check_files repo/deep a deeper1
739 test_expect_success
'cone mode clears ignored subdirectories' '
740 rm repo/.git/info/sparse-checkout &&
742 git -C repo sparse-checkout init --cone &&
743 git -C repo sparse-checkout set deep/deeper1 &&
745 cat >repo/.gitignore <<-\EOF &&
750 git -C repo add .gitignore &&
751 git -C repo commit -m ".gitignore" &&
753 mkdir -p repo/obj repo/folder1/obj repo/deep/deeper2/obj &&
754 for file in folder1/obj/a obj/a folder1/file.o folder1.o \
755 deep/deeper2/obj/a deep/deeper2/file.o file.o
757 echo ignored >repo/$file || return 1
760 git -C repo status --porcelain=v2 >out &&
761 test_must_be_empty out &&
763 git -C repo sparse-checkout reapply &&
764 test_path_is_missing repo/folder1 &&
765 test_path_is_missing repo/deep/deeper2 &&
766 test_path_is_dir repo/obj &&
767 test_path_is_file repo/file.o &&
769 git -C repo status --porcelain=v2 >out &&
770 test_must_be_empty out &&
772 git -C repo sparse-checkout set deep/deeper2 &&
773 test_path_is_missing repo/deep/deeper1 &&
774 test_path_is_dir repo/deep/deeper2 &&
775 test_path_is_dir repo/obj &&
776 test_path_is_file repo/file.o &&
778 >repo/deep/deeper2/ignored.o &&
779 >repo/deep/deeper2/untracked &&
781 # When an untracked file is in the way, all untracked files
782 # (even ignored files) are preserved.
783 git -C repo sparse-checkout set folder1 2>err &&
784 grep "contains untracked files" err &&
785 test_path_is_file repo/deep/deeper2/ignored.o &&
786 test_path_is_file repo/deep/deeper2/untracked &&
788 # The rest of the cone matches expectation
789 test_path_is_missing repo/deep/deeper1 &&
790 test_path_is_dir repo/obj &&
791 test_path_is_file repo/file.o &&
793 git -C repo status --porcelain=v2 >out &&
794 echo "? deep/deeper2/untracked" >expect &&
798 test_expect_success
'malformed cone-mode patterns' '
799 git -C repo sparse-checkout init --cone &&
800 mkdir -p repo/foo/bar &&
801 touch repo/foo/bar/x repo/foo/y &&
802 cat >repo/.git/info/sparse-checkout <<-\EOF &&
810 # Listing the patterns will notice the duplicate pattern and
811 # emit a warning. It will list the patterns directly instead
812 # of using the cone-mode translation to a set of directories.
813 git -C repo sparse-checkout list >actual 2>err &&
814 test_cmp repo/.git/info/sparse-checkout actual &&
815 grep "warning: your sparse-checkout file may have issues: pattern .* is repeated" err &&
816 grep "warning: disabling cone pattern matching" err
819 test_expect_success
'set from subdir pays attention to prefix' '
820 git -C repo sparse-checkout disable &&
821 git -C repo/deep sparse-checkout set --cone deeper2 ../folder1 &&
823 git -C repo sparse-checkout list >actual &&
825 cat >expect <<-\EOF &&
829 test_cmp expect actual
832 test_expect_success
'add from subdir pays attention to prefix' '
833 git -C repo sparse-checkout set --cone deep/deeper2 &&
834 git -C repo/deep sparse-checkout add deeper1/deepest ../folder1 &&
836 git -C repo sparse-checkout list >actual &&
838 cat >expect <<-\EOF &&
843 test_cmp expect actual
846 test_expect_success
'set from subdir in non-cone mode throws an error' '
847 git -C repo sparse-checkout disable &&
848 test_must_fail git -C repo/deep sparse-checkout set --no-cone deeper2 ../folder1 2>error &&
850 grep "run from the toplevel directory in non-cone mode" error
853 test_expect_success
'set from subdir in non-cone mode throws an error' '
854 git -C repo sparse-checkout set --no-cone deep/deeper2 &&
855 test_must_fail git -C repo/deep sparse-checkout add deeper1/deepest ../folder1 2>error &&
857 grep "run from the toplevel directory in non-cone mode" error
860 test_expect_success
'by default, cone mode will error out when passed files' '
861 git -C repo sparse-checkout reapply --cone &&
862 test_must_fail git -C repo sparse-checkout add .gitignore 2>error &&
864 grep ".gitignore.*is not a directory" error
867 test_expect_success
'by default, non-cone mode will warn on individual files' '
868 git -C repo sparse-checkout reapply --no-cone &&
869 git -C repo sparse-checkout add .gitignore 2>warning &&
871 grep "pass a leading slash before paths.*if you want a single file" warning