rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t1091-sparse-checkout-builtin.sh
blob9a900310186d3876f873d5da5ff94dca4a3da35c
1 #!/bin/sh
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
11 . ./test-lib.sh
13 list_files() {
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' *)
21 check_files() {
22 list_files "$1" >actual &&
23 shift &&
24 printf "%s\n" $@ >expect &&
25 test_cmp expect actual
28 test_expect_success 'setup' '
29 git init repo &&
31 cd repo &&
32 echo "initial" >a &&
33 mkdir folder1 folder2 deep &&
34 mkdir deep/deeper1 deep/deeper2 &&
35 mkdir deep/deeper1/deepest &&
36 cp a folder1 &&
37 cp a folder2 &&
38 cp a deep &&
39 cp a deep/deeper1 &&
40 cp a deep/deeper2 &&
41 cp a deep/deeper1/deepest &&
42 git add . &&
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 &&
64 /folder1/*
65 /deep/
66 **/a
67 !*bin*
68 EOF
69 cp repo/.git/info/sparse-checkout expect &&
70 git -C repo sparse-checkout list >list &&
71 test_cmp expect list
74 test_expect_success 'git sparse-checkout init' '
75 git -C repo sparse-checkout init &&
76 cat >expect <<-\EOF &&
78 !/*/
79 EOF
80 test_cmp expect repo/.git/info/sparse-checkout &&
81 test_cmp_config -C repo true core.sparsecheckout &&
82 check_files repo a
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 &&
95 !/*/
96 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 &&
105 !/*/
106 *folder*
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 &&
117 !/*/
119 test_cmp expect actual &&
120 check_files clone a
123 test_expect_success 'switching to cone mode with non-cone mode patterns' '
124 git init bad-patterns &&
126 cd 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 &&
142 folder1
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 &&
173 !/*/
174 *folder*
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 &&
185 !/*/
186 /folder1/
187 /folder2/
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 &&
199 cat >add <<-\EOF &&
200 pattern1
201 /folder1/
202 pattern2
204 cat old >expect &&
205 cat add >>expect &&
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 &&
262 @@ -1,4 +1,7 @@
264 -deep/
265 -folder1/
266 -folder2/
267 +deep/a
268 +deep/deeper1/a
269 +deep/deeper1/deepest/a
270 +deep/deeper2/a
271 +folder1/a
272 +folder2/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 &&
287 echo a >expect &&
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 &&
296 !/*/
297 /deep/
298 !/deep/*/
299 /deep/deeper1/
300 !/deep/deeper1/*/
301 /deep/deeper1/deepest/
303 test_cmp expect repo/.git/info/sparse-checkout &&
304 git -C repo sparse-checkout set --stdin 2>err <<-\EOF &&
305 folder1
306 folder2
308 test_must_be_empty err &&
309 check_files repo a folder1 folder2
312 test_expect_success 'cone mode: list' '
313 cat >expect <<-\EOF &&
314 folder1
315 folder2
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 &&
328 !/*/
329 /deep/
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 &&
339 !/*/
340 /deep/
341 !/deep/*/
342 /deep/deeper1/
343 /folder1/
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 &&
354 !/*/
355 /deep/
356 !/deep/*/
357 /deep/deeper1/
358 /deep/deeper2/
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 &&
369 !/*/
370 /deep/
371 /folder1/
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 &&
399 echo >file &&
400 git add file &&
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 &&
448 cat >input <<-EOF &&
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 &&
475 cat >input <<-EOF &&
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
519 index.sparse=false
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
528 index.sparse=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
537 index.sparse=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 &&
550 !/*/
551 /folder1/
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 &&
560 cd super &&
561 mkdir modules &&
562 git submodule add ../repo modules/child &&
563 git add . &&
564 git commit -m "add submodule" &&
565 git sparse-checkout init --cone &&
566 git sparse-checkout set folder1
567 ) &&
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 &&
586 !/*/
588 /deep/
590 test_cmp expect repo/.git/info/sparse-checkout &&
591 check_files repo a deep
594 check_read_tree_errors () {
595 REPO=$1
596 FILES=$2
597 ERRORS=$3
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 &&
602 if test -z "$ERRORS"
603 then
604 test_must_be_empty err
605 else
606 test_i18ngrep "$ERRORS" err
607 fi &&
608 check_files $REPO $FILES
611 test_expect_success 'pattern-checks: /A/**' '
612 cat >repo/.git/info/sparse-checkout <<-\EOF &&
614 !/*/
615 /folder1/**
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 &&
623 !/*/
624 /deep/**/deepest
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 &&
634 !/*/
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 &&
642 !/*/
645 git -C repo read-tree -mu HEAD 2>err &&
646 test_must_be_empty err &&
647 check_files repo a
650 test_expect_success 'pattern-checks: trailing "*"' '
651 cat >repo/.git/info/sparse-checkout <<-\EOF &&
653 !/*/
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 &&
662 !/*/
663 *eep/
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 &&
673 !/*/
674 something$c-else/
676 check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1
677 done
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]?
689 ) &&
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 &&
697 !/*/
698 /zbad\\dir/
699 !/zbad\\dir/*/
700 /zbad\\dir/bogus/
701 /zdoes\*exist/
702 /zdoes\*not\*exist/
703 /zglob\[!a]\?/
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 &&
711 !/*/
712 /deep/
713 /folder1/
714 /folder2/
715 /zbad\\dir/
716 /zdoes\*exist/
717 /zglob\[!a]\?/
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 &&
729 !/*/
730 /deep/
731 !/deep/*/
732 /deep/deeper1/
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 &&
746 obj/
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
758 done &&
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 &&
795 test_cmp expect out
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 &&
804 !/*/
805 /foo/
806 !/foo/*/
807 /foo/\*/
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 &&
826 deep/deeper2
827 folder1
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 &&
839 deep/deeper1/deepest
840 deep/deeper2
841 folder1
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
874 test_done