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 --no-cone &&
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 reapply --no-cone &&
115 git -C clone sparse-checkout list >actual &&
116 cat >expect <<-\EOF &&
120 test_cmp expect actual &&
124 test_expect_success
'switching to cone mode with non-cone mode patterns' '
125 git init bad-patterns &&
128 git sparse-checkout init --no-cone &&
129 git sparse-checkout add dir &&
130 git config --worktree core.sparseCheckoutCone true &&
131 test_must_fail git sparse-checkout add dir 2>err &&
132 grep "existing sparse-checkout patterns do not use cone mode" err
136 test_expect_success
'interaction with clone --no-checkout (unborn index)' '
137 git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout &&
138 git -C clone_no_checkout sparse-checkout init --cone &&
139 git -C clone_no_checkout sparse-checkout set folder1 &&
141 git -C clone_no_checkout sparse-checkout list >actual &&
142 cat >expect <<-\EOF &&
145 test_cmp expect actual &&
147 # nothing checked out, expect "No such file or directory"
148 ! ls clone_no_checkout/* >actual &&
149 test_must_be_empty actual &&
150 test_path_is_missing clone_no_checkout/.git/index &&
152 # No branch is checked out until we manually switch to one
153 git -C clone_no_checkout switch main &&
154 test_path_is_file clone_no_checkout/.git/index &&
155 check_files clone_no_checkout a folder1
158 test_expect_success
'set enables config' '
159 git init worktree-config &&
161 cd worktree-config &&
162 test_commit test file &&
163 test_path_is_missing .git/config.worktree &&
164 git sparse-checkout set nothing &&
165 test_path_is_file .git/config.worktree &&
166 test_cmp_config true core.sparseCheckout
170 test_expect_success
'set sparse-checkout using builtin' '
171 git -C repo sparse-checkout set "/*" "!/*/" "*folder*" &&
172 cat >expect <<-\EOF &&
177 git -C repo sparse-checkout list >actual &&
178 test_cmp expect actual &&
179 test_cmp expect repo/.git/info/sparse-checkout &&
180 check_files repo a folder1 folder2
183 test_expect_success
'set sparse-checkout using --stdin' '
184 cat >expect <<-\EOF &&
190 git -C repo sparse-checkout set --stdin <expect &&
191 git -C repo sparse-checkout list >actual &&
192 test_cmp expect actual &&
193 test_cmp expect repo/.git/info/sparse-checkout &&
194 check_files repo "a folder1 folder2"
197 test_expect_success
'add to sparse-checkout' '
198 cat repo/.git/info/sparse-checkout >old &&
199 test_when_finished cp old repo/.git/info/sparse-checkout &&
207 git -C repo sparse-checkout add --stdin <add &&
208 git -C repo sparse-checkout list >actual &&
209 test_cmp expect actual &&
210 test_cmp expect repo/.git/info/sparse-checkout &&
211 check_files repo "a folder1 folder2"
214 test_expect_success
'worktree: add copies sparse-checkout patterns' '
215 cat repo/.git/info/sparse-checkout >old &&
216 test_when_finished cp old repo/.git/info/sparse-checkout &&
217 test_when_finished git -C repo worktree remove ../worktree &&
218 git -C repo sparse-checkout set --no-cone "/*" &&
219 git -C repo worktree add --quiet ../worktree 2>err &&
220 test_must_be_empty err &&
221 new="$(git -C worktree rev-parse --git-path info/sparse-checkout)" &&
222 test_path_is_file "$new" &&
223 test_cmp repo/.git/info/sparse-checkout "$new" &&
224 git -C worktree sparse-checkout set --cone &&
225 test_cmp_config -C worktree true core.sparseCheckoutCone &&
226 test_must_fail git -C repo core.sparseCheckoutCone
229 test_expect_success
'cone mode: match patterns' '
230 git -C repo config --worktree core.sparseCheckoutCone true &&
231 rm -rf repo/a repo/folder1 repo/folder2 &&
232 git -C repo read-tree -mu HEAD 2>err &&
233 test_i18ngrep ! "disabling cone patterns" err &&
234 git -C repo reset --hard &&
235 check_files repo a folder1 folder2
238 test_expect_success
'cone mode: warn on bad pattern' '
239 test_when_finished mv sparse-checkout repo/.git/info/ &&
240 cp repo/.git/info/sparse-checkout . &&
241 echo "!/deep/deeper/*" >>repo/.git/info/sparse-checkout &&
242 git -C repo read-tree -mu HEAD 2>err &&
243 test_i18ngrep "unrecognized negative pattern" err
246 test_expect_success
'sparse-checkout disable' '
247 test_when_finished rm -rf repo/.git/info/sparse-checkout &&
248 git -C repo sparse-checkout disable &&
249 test_path_is_file repo/.git/info/sparse-checkout &&
250 git -C repo config --list >config &&
251 test_must_fail git config core.sparseCheckout &&
252 check_files repo a deep folder1 folder2
255 test_expect_success
'sparse-index enabled and disabled' '
256 git -C repo sparse-checkout init --cone --sparse-index &&
257 test_cmp_config -C repo true index.sparse &&
258 git -C repo ls-files --sparse >sparse &&
259 git -C repo sparse-checkout disable &&
260 git -C repo ls-files --sparse >full &&
262 cat >expect <<-\EOF &&
270 +deep/deeper1/deepest/a
276 diff -u sparse full | tail -n +3 >actual &&
277 test_cmp expect actual &&
279 git -C repo config --list >config &&
280 test_cmp_config -C repo false index.sparse
283 test_expect_success
'cone mode: init and set' '
284 git -C repo sparse-checkout init --cone &&
285 git -C repo config --list >config &&
286 test_i18ngrep "core.sparsecheckoutcone=true" config &&
287 list_files repo >dir &&
289 test_cmp expect dir &&
290 git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
291 test_must_be_empty err &&
292 check_files repo a deep &&
293 check_files repo/deep a deeper1 &&
294 check_files repo/deep/deeper1 a deepest &&
295 cat >expect <<-\EOF &&
302 /deep/deeper1/deepest/
304 test_cmp expect repo/.git/info/sparse-checkout &&
305 git -C repo sparse-checkout set --stdin 2>err <<-\EOF &&
309 test_must_be_empty err &&
310 check_files repo a folder1 folder2
313 test_expect_success
'cone mode: list' '
314 cat >expect <<-\EOF &&
318 git -C repo sparse-checkout set --stdin <expect &&
319 git -C repo sparse-checkout list >actual 2>err &&
320 test_must_be_empty err &&
321 test_cmp expect actual
324 test_expect_success
'cone mode: set with nested folders' '
325 git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err &&
326 test_line_count = 0 err &&
327 cat >expect <<-\EOF &&
332 test_cmp repo/.git/info/sparse-checkout expect
335 test_expect_success
'cone mode: add independent path' '
336 git -C repo sparse-checkout set deep/deeper1 &&
337 git -C repo sparse-checkout add folder1 &&
338 cat >expect <<-\EOF &&
346 test_cmp expect repo/.git/info/sparse-checkout &&
347 check_files repo a deep folder1
350 test_expect_success
'cone mode: add sibling path' '
351 git -C repo sparse-checkout set deep/deeper1 &&
352 git -C repo sparse-checkout add deep/deeper2 &&
353 cat >expect <<-\EOF &&
361 test_cmp expect repo/.git/info/sparse-checkout &&
362 check_files repo a deep
365 test_expect_success
'cone mode: add parent path' '
366 git -C repo sparse-checkout set deep/deeper1 folder1 &&
367 git -C repo sparse-checkout add deep &&
368 cat >expect <<-\EOF &&
374 test_cmp expect repo/.git/info/sparse-checkout &&
375 check_files repo a deep folder1
378 test_expect_success
'not-up-to-date does not block rest of sparsification' '
379 test_when_finished git -C repo sparse-checkout disable &&
380 test_when_finished git -C repo reset --hard &&
381 git -C repo sparse-checkout set deep &&
383 echo update >repo/deep/deeper2/a &&
384 cp repo/.git/info/sparse-checkout expect &&
385 test_write_lines "!/deep/*/" "/deep/deeper1/" >>expect &&
387 git -C repo sparse-checkout set deep/deeper1 2>err &&
389 test_i18ngrep "The following paths are not up to date" err &&
390 test_cmp expect repo/.git/info/sparse-checkout &&
391 check_files repo/deep a deeper1 deeper2 &&
392 check_files repo/deep/deeper1 a deepest &&
393 check_files repo/deep/deeper1/deepest a &&
394 check_files repo/deep/deeper2 a
397 test_expect_success
'revert to old sparse-checkout on empty update' '
398 git init empty-test &&
402 git commit -m "test" &&
403 git sparse-checkout set nothing 2>err &&
404 test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err &&
405 test_i18ngrep ! ".git/index.lock" err &&
406 git sparse-checkout set --no-cone file
410 test_expect_success
'fail when lock is taken' '
411 test_when_finished rm -rf repo/.git/info/sparse-checkout.lock &&
412 touch repo/.git/info/sparse-checkout.lock &&
413 test_must_fail git -C repo sparse-checkout set deep 2>err &&
414 test_i18ngrep "Unable to create .*\.lock" err
417 test_expect_success
'.gitignore should not warn about cone mode' '
418 git -C repo config --worktree core.sparseCheckoutCone true &&
419 echo "**/bin/*" >repo/.gitignore &&
420 git -C repo reset --hard 2>err &&
421 test_i18ngrep ! "disabling cone patterns" err
424 test_expect_success
'sparse-checkout (init|set|disable) warns with dirty status' '
425 git clone repo dirty &&
426 echo dirty >dirty/folder1/a &&
428 git -C dirty sparse-checkout init --no-cone 2>err &&
429 test_i18ngrep "warning.*The following paths are not up to date" err &&
431 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err &&
432 test_i18ngrep "warning.*The following paths are not up to date" err &&
433 test_path_is_file dirty/folder1/a &&
435 git -C dirty sparse-checkout disable 2>err &&
436 test_must_be_empty err &&
438 git -C dirty reset --hard &&
439 git -C dirty sparse-checkout init --no-cone &&
440 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* &&
441 test_path_is_missing dirty/folder1/a &&
442 git -C dirty sparse-checkout disable &&
443 test_path_is_file dirty/folder1/a
446 test_expect_success
'sparse-checkout (init|set|disable) warns with unmerged status' '
447 git clone repo unmerged &&
450 0 $ZERO_OID folder1/a
451 100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1 folder1/a
453 git -C unmerged update-index --index-info <input &&
455 git -C unmerged sparse-checkout init --no-cone 2>err &&
456 test_i18ngrep "warning.*The following paths are unmerged" err &&
458 git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err &&
459 test_i18ngrep "warning.*The following paths are unmerged" err &&
460 test_path_is_file dirty/folder1/a &&
462 git -C unmerged sparse-checkout disable 2>err &&
463 test_i18ngrep "warning.*The following paths are unmerged" err &&
465 git -C unmerged reset --hard &&
466 git -C unmerged sparse-checkout init --no-cone &&
467 git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* &&
468 git -C unmerged sparse-checkout disable
471 test_expect_failure
'sparse-checkout reapply' '
472 git clone repo tweak &&
474 echo dirty >tweak/deep/deeper2/a &&
477 0 $ZERO_OID folder1/a
478 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a
480 git -C tweak update-index --index-info <input &&
482 git -C tweak sparse-checkout init --cone 2>err &&
483 test_i18ngrep "warning.*The following paths are not up to date" err &&
484 test_i18ngrep "warning.*The following paths are unmerged" err &&
486 git -C tweak sparse-checkout set folder2 deep/deeper1 2>err &&
487 test_i18ngrep "warning.*The following paths are not up to date" err &&
488 test_i18ngrep "warning.*The following paths are unmerged" err &&
490 git -C tweak sparse-checkout reapply 2>err &&
491 test_i18ngrep "warning.*The following paths are not up to date" err &&
492 test_path_is_file tweak/deep/deeper2/a &&
493 test_i18ngrep "warning.*The following paths are unmerged" err &&
494 test_path_is_file tweak/folder1/a &&
496 git -C tweak checkout HEAD deep/deeper2/a &&
497 git -C tweak sparse-checkout reapply 2>err &&
498 test_i18ngrep ! "warning.*The following paths are not up to date" err &&
499 test_path_is_missing tweak/deep/deeper2/a &&
500 test_i18ngrep "warning.*The following paths are unmerged" err &&
501 test_path_is_file tweak/folder1/a &&
503 # NEEDSWORK: We are asking to update a file outside of the
504 # sparse-checkout cone, but this is no longer allowed.
505 git -C tweak add folder1/a &&
506 git -C tweak sparse-checkout reapply 2>err &&
507 test_must_be_empty err &&
508 test_path_is_missing tweak/deep/deeper2/a &&
509 test_path_is_missing tweak/folder1/a &&
511 git -C tweak sparse-checkout disable
514 test_expect_success
'reapply can handle config options' '
515 git -C repo sparse-checkout init --cone --no-sparse-index &&
516 git -C repo config --worktree --list >actual &&
517 cat >expect <<-\EOF &&
518 core.sparsecheckout=true
519 core.sparsecheckoutcone=true
522 test_cmp expect actual &&
524 git -C repo sparse-checkout reapply --no-cone --no-sparse-index &&
525 git -C repo config --worktree --list >actual &&
526 cat >expect <<-\EOF &&
527 core.sparsecheckout=true
528 core.sparsecheckoutcone=false
531 test_cmp expect actual &&
533 git -C repo sparse-checkout reapply --cone --sparse-index &&
534 git -C repo config --worktree --list >actual &&
535 cat >expect <<-\EOF &&
536 core.sparsecheckout=true
537 core.sparsecheckoutcone=true
540 test_cmp expect actual &&
542 git -C repo sparse-checkout disable
545 test_expect_success
'cone mode: set with core.ignoreCase=true' '
546 rm repo/.git/info/sparse-checkout &&
547 git -C repo sparse-checkout init --cone &&
548 git -C repo -c core.ignoreCase=true sparse-checkout set folder1 &&
549 cat >expect <<-\EOF &&
554 test_cmp expect repo/.git/info/sparse-checkout &&
555 check_files repo a folder1
558 test_expect_success
'interaction with submodules' '
559 git clone repo super &&
563 git submodule add ../repo modules/child &&
565 git commit -m "add submodule" &&
566 git sparse-checkout init --cone &&
567 git sparse-checkout set folder1
569 check_files super a folder1 modules &&
570 check_files super/modules/child a deep folder1 folder2
573 test_expect_success
'different sparse-checkouts with worktrees' '
574 git -C repo sparse-checkout set --cone deep folder1 &&
575 git -C repo worktree add --detach ../worktree &&
576 check_files worktree "a deep folder1" &&
577 git -C repo sparse-checkout set --cone folder1 &&
578 git -C worktree sparse-checkout set --cone deep/deeper1 &&
579 check_files repo "a folder1" &&
580 check_files worktree "a deep"
583 test_expect_success
'set using filename keeps file on-disk' '
584 git -C repo sparse-checkout set --skip-checks a deep &&
585 cat >expect <<-\EOF &&
591 test_cmp expect repo/.git/info/sparse-checkout &&
592 check_files repo a deep
595 check_read_tree_errors
() {
599 git
-C $REPO -c core.sparseCheckoutCone
=false read-tree
-mu HEAD
2>err
&&
600 test_must_be_empty err
&&
601 check_files
$REPO "$FILES" &&
602 git
-C $REPO read-tree
-mu HEAD
2>err
&&
605 test_must_be_empty err
607 test_i18ngrep
"$ERRORS" err
609 check_files
$REPO $FILES
612 test_expect_success
'pattern-checks: /A/**' '
613 cat >repo/.git/info/sparse-checkout <<-\EOF &&
618 check_read_tree_errors repo "a folder1" "disabling cone pattern matching"
621 test_expect_success
'pattern-checks: /A/**/B/' '
622 cat >repo/.git/info/sparse-checkout <<-\EOF &&
627 check_read_tree_errors repo "a deep" "disabling cone pattern matching" &&
628 check_files repo/deep "deeper1" &&
629 check_files repo/deep/deeper1 "deepest"
632 test_expect_success
'pattern-checks: too short' '
633 cat >repo/.git/info/sparse-checkout <<-\EOF &&
638 check_read_tree_errors repo "a" "disabling cone pattern matching"
640 test_expect_success
'pattern-checks: not too short' '
641 cat >repo/.git/info/sparse-checkout <<-\EOF &&
646 git -C repo read-tree -mu HEAD 2>err &&
647 test_must_be_empty err &&
651 test_expect_success
'pattern-checks: trailing "*"' '
652 cat >repo/.git/info/sparse-checkout <<-\EOF &&
657 check_read_tree_errors repo "a" "disabling cone pattern matching"
660 test_expect_success
'pattern-checks: starting "*"' '
661 cat >repo/.git/info/sparse-checkout <<-\EOF &&
666 check_read_tree_errors repo "a deep" "disabling cone pattern matching"
669 test_expect_success
'pattern-checks: contained glob characters' '
670 for c in "[a]" "\\" "?" "*"
672 cat >repo/.git/info/sparse-checkout <<-EOF &&
677 check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1
681 test_expect_success BSLASHPSPEC
'pattern-checks: escaped characters' '
682 git clone repo escaped &&
683 TREEOID=$(git -C escaped rev-parse HEAD:folder1) &&
684 NEWTREE=$(git -C escaped mktree <<-EOF
685 $(git -C escaped ls-tree HEAD)
686 040000 tree $TREEOID zbad\\dir
687 040000 tree $TREEOID zdoes*exist
688 040000 tree $TREEOID zglob[!a]?
691 COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) &&
692 git -C escaped reset --hard $COMMIT &&
693 check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
694 git -C escaped sparse-checkout init --cone &&
695 git -C escaped sparse-checkout set --skip-checks zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" &&
696 cat >expect <<-\EOF &&
706 test_cmp expect escaped/.git/info/sparse-checkout &&
707 check_read_tree_errors escaped "a zbad\\dir zdoes*exist zglob[!a]?" &&
708 git -C escaped ls-tree -d --name-only HEAD >list-expect &&
709 git -C escaped sparse-checkout set --stdin <list-expect &&
710 cat >expect <<-\EOF &&
720 test_cmp expect escaped/.git/info/sparse-checkout &&
721 check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? &&
722 git -C escaped sparse-checkout list >list-actual &&
723 test_cmp list-expect list-actual
726 test_expect_success MINGW
'cone mode replaces backslashes with slashes' '
727 git -C repo sparse-checkout set deep\\deeper1 &&
728 cat >expect <<-\EOF &&
735 test_cmp expect repo/.git/info/sparse-checkout &&
736 check_files repo a deep &&
737 check_files repo/deep a deeper1
740 test_expect_success
'cone mode clears ignored subdirectories' '
741 rm repo/.git/info/sparse-checkout &&
743 git -C repo sparse-checkout init --cone &&
744 git -C repo sparse-checkout set deep/deeper1 &&
746 cat >repo/.gitignore <<-\EOF &&
751 git -C repo add .gitignore &&
752 git -C repo commit -m ".gitignore" &&
754 mkdir -p repo/obj repo/folder1/obj repo/deep/deeper2/obj &&
755 for file in folder1/obj/a obj/a folder1/file.o folder1.o \
756 deep/deeper2/obj/a deep/deeper2/file.o file.o
758 echo ignored >repo/$file || return 1
761 git -C repo status --porcelain=v2 >out &&
762 test_must_be_empty out &&
764 git -C repo sparse-checkout reapply &&
765 test_path_is_missing repo/folder1 &&
766 test_path_is_missing repo/deep/deeper2 &&
767 test_path_is_dir repo/obj &&
768 test_path_is_file repo/file.o &&
770 git -C repo status --porcelain=v2 >out &&
771 test_must_be_empty out &&
773 git -C repo sparse-checkout set deep/deeper2 &&
774 test_path_is_missing repo/deep/deeper1 &&
775 test_path_is_dir repo/deep/deeper2 &&
776 test_path_is_dir repo/obj &&
777 test_path_is_file repo/file.o &&
779 >repo/deep/deeper2/ignored.o &&
780 >repo/deep/deeper2/untracked &&
782 # When an untracked file is in the way, all untracked files
783 # (even ignored files) are preserved.
784 git -C repo sparse-checkout set folder1 2>err &&
785 grep "contains untracked files" err &&
786 test_path_is_file repo/deep/deeper2/ignored.o &&
787 test_path_is_file repo/deep/deeper2/untracked &&
789 # The rest of the cone matches expectation
790 test_path_is_missing repo/deep/deeper1 &&
791 test_path_is_dir repo/obj &&
792 test_path_is_file repo/file.o &&
794 git -C repo status --porcelain=v2 >out &&
795 echo "? deep/deeper2/untracked" >expect &&
799 test_expect_success
'malformed cone-mode patterns' '
800 git -C repo sparse-checkout init --cone &&
801 mkdir -p repo/foo/bar &&
802 touch repo/foo/bar/x repo/foo/y &&
803 cat >repo/.git/info/sparse-checkout <<-\EOF &&
811 # Listing the patterns will notice the duplicate pattern and
812 # emit a warning. It will list the patterns directly instead
813 # of using the cone-mode translation to a set of directories.
814 git -C repo sparse-checkout list >actual 2>err &&
815 test_cmp repo/.git/info/sparse-checkout actual &&
816 grep "warning: your sparse-checkout file may have issues: pattern .* is repeated" err &&
817 grep "warning: disabling cone pattern matching" err
820 test_expect_success
'set from subdir pays attention to prefix' '
821 git -C repo sparse-checkout disable &&
822 git -C repo/deep sparse-checkout set --cone deeper2 ../folder1 &&
824 git -C repo sparse-checkout list >actual &&
826 cat >expect <<-\EOF &&
830 test_cmp expect actual
833 test_expect_success
'add from subdir pays attention to prefix' '
834 git -C repo sparse-checkout set --cone deep/deeper2 &&
835 git -C repo/deep sparse-checkout add deeper1/deepest ../folder1 &&
837 git -C repo sparse-checkout list >actual &&
839 cat >expect <<-\EOF &&
844 test_cmp expect actual
847 test_expect_success
'set from subdir in non-cone mode throws an error' '
848 git -C repo sparse-checkout disable &&
849 test_must_fail git -C repo/deep sparse-checkout set --no-cone deeper2 ../folder1 2>error &&
851 grep "run from the toplevel directory in non-cone mode" error
854 test_expect_success
'set from subdir in non-cone mode throws an error' '
855 git -C repo sparse-checkout set --no-cone deep/deeper2 &&
856 test_must_fail git -C repo/deep sparse-checkout add deeper1/deepest ../folder1 2>error &&
858 grep "run from the toplevel directory in non-cone mode" error
861 test_expect_success
'by default, cone mode will error out when passed files' '
862 git -C repo sparse-checkout reapply --cone &&
863 test_must_fail git -C repo sparse-checkout add .gitignore 2>error &&
865 grep ".gitignore.*is not a directory" error
868 test_expect_success
'by default, non-cone mode will warn on individual files' '
869 git -C repo sparse-checkout reapply --no-cone &&
870 git -C repo sparse-checkout add .gitignore 2>warning &&
872 grep "pass a leading slash before paths.*if you want a single file" warning