The eleventh batch
[git/gitster.git] / t / t0008-ignores.sh
blob02a18d4fdbd244dcc99290a28695ce7a89107d3a
1 #!/bin/sh
3 test_description=check-ignore
5 TEST_PASSES_SANITIZE_LEAK=true
6 TEST_CREATE_REPO_NO_TEMPLATE=1
7 . ./test-lib.sh
9 init_vars () {
10 global_excludes="global-excludes"
13 enable_global_excludes () {
14 init_vars &&
15 git config core.excludesfile "$global_excludes"
18 expect_in () {
19 dest="$HOME/expected-$1" text="$2"
20 if test -z "$text"
21 then
22 >"$dest" # avoid newline
23 else
24 echo "$text" >"$dest"
28 expect () {
29 expect_in stdout "$1"
32 expect_from_stdin () {
33 cat >"$HOME/expected-stdout"
36 test_stderr () {
37 expected="$1"
38 expect_in stderr "$1" &&
39 test_cmp "$HOME/expected-stderr" "$HOME/stderr"
42 broken_c_unquote () {
43 "$PERL_PATH" -pe 's/^"//; s/\\//; s/"$//; tr/\n/\0/' "$@"
46 broken_c_unquote_verbose () {
47 "$PERL_PATH" -pe 's/ "/ /; s/\\//; s/"$//; tr/:\t\n/\0/' "$@"
50 stderr_contains () {
51 regexp="$1"
52 if test_grep "$regexp" "$HOME/stderr"
53 then
54 return 0
55 else
56 echo "didn't find /$regexp/ in $HOME/stderr"
57 cat "$HOME/stderr"
58 return 1
62 stderr_empty_on_success () {
63 expect_code="$1"
64 if test $expect_code = 0
65 then
66 test_stderr ""
67 else
68 # If we expect failure then stderr might or might not be empty
69 # due to --quiet - the caller can check its contents
70 return 0
74 test_check_ignore () {
75 args="$1" expect_code="${2:-0}" global_args="$3"
77 init_vars &&
78 rm -f "$HOME/stdout" "$HOME/stderr" "$HOME/cmd" &&
79 echo git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $no_index_opt $args \
80 >"$HOME/cmd" &&
81 echo "$expect_code" >"$HOME/expected-exit-code" &&
82 test_expect_code "$expect_code" \
83 git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $no_index_opt $args \
84 >"$HOME/stdout" 2>"$HOME/stderr" &&
85 test_cmp "$HOME/expected-stdout" "$HOME/stdout" &&
86 stderr_empty_on_success "$expect_code"
89 # Runs the same code with 4 different levels of output verbosity:
91 # 1. with -q / --quiet
92 # 2. with default verbosity
93 # 3. with -v / --verbose
94 # 4. with -v / --verbose, *and* -n / --non-matching
96 # expecting success each time. Takes advantage of the fact that
97 # check-ignore --verbose output is the same as normal output except
98 # for the extra first column.
100 # A parameter is used to determine if the tests are run with the
101 # normal case (using the index), or with the --no-index option.
103 # Arguments:
104 # - (optional) prereqs for this test, e.g. 'SYMLINKS'
105 # - test name
106 # - output to expect from the fourth verbosity mode (the output
107 # from the other verbosity modes is automatically inferred
108 # from this value)
109 # - code to run (should invoke test_check_ignore)
110 # - index option: --index or --no-index
111 test_expect_success_multiple () {
112 prereq=
113 if test $# -eq 5
114 then
115 prereq=$1
116 shift
118 if test "$4" = "--index"
119 then
120 no_index_opt=
121 else
122 no_index_opt=$4
124 testname="$1" expect_all="$2" code="$3"
126 expect_verbose=$( echo "$expect_all" | grep -v '^:: ' )
127 expect=$( echo "$expect_verbose" | sed -e 's/.* //' )
129 test_expect_success $prereq "$testname${no_index_opt:+ with $no_index_opt}" '
130 expect "$expect" &&
131 eval "$code"
134 # --quiet is only valid when a single pattern is passed
135 if test $( echo "$expect_all" | wc -l ) = 1
136 then
137 for quiet_opt in '-q' '--quiet'
139 opts="${no_index_opt:+$no_index_opt }$quiet_opt"
140 test_expect_success $prereq "$testname${opts:+ with $opts}" "
141 expect '' &&
142 $code
144 done
145 quiet_opt=
148 for verbose_opt in '-v' '--verbose'
150 for non_matching_opt in '' '-n' '--non-matching'
152 if test -n "$non_matching_opt"
153 then
154 my_expect="$expect_all"
155 else
156 my_expect="$expect_verbose"
159 test_code="
160 expect '$my_expect' &&
161 $code
163 opts="${no_index_opt:+$no_index_opt }$verbose_opt${non_matching_opt:+ $non_matching_opt}"
164 test_expect_success $prereq "$testname${opts:+ with $opts}" "$test_code"
165 done
166 done
167 verbose_opt=
168 non_matching_opt=
169 no_index_opt=
172 test_expect_success_multi () {
173 test_expect_success_multiple "$@" "--index"
176 test_expect_success_no_index_multi () {
177 test_expect_success_multiple "$@" "--no-index"
180 test_expect_success 'setup' '
181 init_vars &&
182 mkdir -p a/b/ignored-dir a/submodule b &&
183 if test_have_prereq SYMLINKS
184 then
185 ln -s b a/symlink
186 fi &&
188 cd a/submodule &&
189 git init &&
190 echo a >a &&
191 git add a &&
192 git commit -m"commit in submodule"
193 ) &&
194 git add a/submodule &&
195 cat <<-\EOF >.gitignore &&
197 ignored-*
198 top-level-dir/
200 for dir in . a
202 : >$dir/not-ignored &&
203 : >$dir/ignored-and-untracked &&
204 : >$dir/ignored-but-in-index || return 1
205 done &&
206 git add -f ignored-but-in-index a/ignored-but-in-index &&
207 cat <<-\EOF >a/.gitignore &&
208 two*
209 *three
211 cat <<-\EOF >a/b/.gitignore &&
212 four
213 five
214 # this comment should affect the line numbers
216 ignored-dir/
217 # and so should this blank line:
219 !on*
220 !two
222 echo "seven" >a/b/ignored-dir/.gitignore &&
223 test -n "$HOME" &&
224 cat <<-\EOF >"$global_excludes" &&
225 globalone
226 !globaltwo
227 globalthree
229 mkdir .git/info &&
230 cat <<-\EOF >.git/info/exclude
231 per-repo
235 ############################################################################
237 # test invalid inputs
239 test_expect_success_multi '. corner-case' ':: .' '
240 test_check_ignore . 1
243 test_expect_success_multi 'empty command line' '' '
244 test_check_ignore "" 128 &&
245 stderr_contains "fatal: no path specified"
248 test_expect_success_multi '--stdin with empty STDIN' '' '
249 test_check_ignore "--stdin" 1 </dev/null &&
250 test_stderr ""
253 test_expect_success '-q with multiple args' '
254 expect "" &&
255 test_check_ignore "-q one two" 128 &&
256 stderr_contains "fatal: --quiet is only valid with a single pathname"
259 test_expect_success '--quiet with multiple args' '
260 expect "" &&
261 test_check_ignore "--quiet one two" 128 &&
262 stderr_contains "fatal: --quiet is only valid with a single pathname"
265 for verbose_opt in '-v' '--verbose'
267 for quiet_opt in '-q' '--quiet'
269 test_expect_success "$quiet_opt $verbose_opt" "
270 expect '' &&
271 test_check_ignore '$quiet_opt $verbose_opt foo' 128 &&
272 stderr_contains 'fatal: cannot have both --quiet and --verbose'
274 done
275 done
277 test_expect_success '--quiet with multiple args' '
278 expect "" &&
279 test_check_ignore "--quiet one two" 128 &&
280 stderr_contains "fatal: --quiet is only valid with a single pathname"
283 test_expect_success_multi 'erroneous use of --' '' '
284 test_check_ignore "--" 128 &&
285 stderr_contains "fatal: no path specified"
288 test_expect_success_multi '--stdin with superfluous arg' '' '
289 test_check_ignore "--stdin foo" 128 &&
290 stderr_contains "fatal: cannot specify pathnames with --stdin"
293 test_expect_success_multi '--stdin -z with superfluous arg' '' '
294 test_check_ignore "--stdin -z foo" 128 &&
295 stderr_contains "fatal: cannot specify pathnames with --stdin"
298 test_expect_success_multi '-z without --stdin' '' '
299 test_check_ignore "-z" 128 &&
300 stderr_contains "fatal: -z only makes sense with --stdin"
303 test_expect_success_multi '-z without --stdin and superfluous arg' '' '
304 test_check_ignore "-z foo" 128 &&
305 stderr_contains "fatal: -z only makes sense with --stdin"
308 test_expect_success_multi 'needs work tree' '' '
310 cd .git &&
311 test_check_ignore "foo" 128
312 ) &&
313 stderr_contains "fatal: this operation must be run in a work tree"
316 ############################################################################
318 # test standard ignores
320 # First make sure that the presence of a file in the working tree
321 # does not impact results, but that the presence of a file in the
322 # index does unless the --no-index option is used.
324 for subdir in '' 'a/'
326 if test -z "$subdir"
327 then
328 where="at top-level"
329 else
330 where="in subdir $subdir"
333 test_expect_success_multi "non-existent file $where not ignored" \
334 ":: ${subdir}non-existent" \
335 "test_check_ignore '${subdir}non-existent' 1"
337 test_expect_success_no_index_multi "non-existent file $where not ignored" \
338 ":: ${subdir}non-existent" \
339 "test_check_ignore '${subdir}non-existent' 1"
341 test_expect_success_multi "non-existent file $where ignored" \
342 ".gitignore:1:one ${subdir}one" \
343 "test_check_ignore '${subdir}one'"
345 test_expect_success_no_index_multi "non-existent file $where ignored" \
346 ".gitignore:1:one ${subdir}one" \
347 "test_check_ignore '${subdir}one'"
349 test_expect_success_multi "existing untracked file $where not ignored" \
350 ":: ${subdir}not-ignored" \
351 "test_check_ignore '${subdir}not-ignored' 1"
353 test_expect_success_no_index_multi "existing untracked file $where not ignored" \
354 ":: ${subdir}not-ignored" \
355 "test_check_ignore '${subdir}not-ignored' 1"
357 test_expect_success_multi "existing tracked file $where not ignored" \
358 ":: ${subdir}ignored-but-in-index" \
359 "test_check_ignore '${subdir}ignored-but-in-index' 1"
361 test_expect_success_no_index_multi "existing tracked file $where shown as ignored" \
362 ".gitignore:2:ignored-* ${subdir}ignored-but-in-index" \
363 "test_check_ignore '${subdir}ignored-but-in-index'"
365 test_expect_success_multi "existing untracked file $where ignored" \
366 ".gitignore:2:ignored-* ${subdir}ignored-and-untracked" \
367 "test_check_ignore '${subdir}ignored-and-untracked'"
369 test_expect_success_no_index_multi "existing untracked file $where ignored" \
370 ".gitignore:2:ignored-* ${subdir}ignored-and-untracked" \
371 "test_check_ignore '${subdir}ignored-and-untracked'"
373 test_expect_success_multi "mix of file types $where" \
374 ":: ${subdir}non-existent
375 .gitignore:1:one ${subdir}one
376 :: ${subdir}not-ignored
377 :: ${subdir}ignored-but-in-index
378 .gitignore:2:ignored-* ${subdir}ignored-and-untracked" \
379 "test_check_ignore '
380 ${subdir}non-existent
381 ${subdir}one
382 ${subdir}not-ignored
383 ${subdir}ignored-but-in-index
384 ${subdir}ignored-and-untracked'
387 test_expect_success_no_index_multi "mix of file types $where" \
388 ":: ${subdir}non-existent
389 .gitignore:1:one ${subdir}one
390 :: ${subdir}not-ignored
391 .gitignore:2:ignored-* ${subdir}ignored-but-in-index
392 .gitignore:2:ignored-* ${subdir}ignored-and-untracked" \
393 "test_check_ignore '
394 ${subdir}non-existent
395 ${subdir}one
396 ${subdir}not-ignored
397 ${subdir}ignored-but-in-index
398 ${subdir}ignored-and-untracked'
400 done
402 # Having established the above, from now on we mostly test against
403 # files which do not exist in the working tree or index.
405 test_expect_success 'sub-directory local ignore' '
406 expect "a/3-three" &&
407 test_check_ignore "a/3-three a/three-not-this-one"
410 test_expect_success 'sub-directory local ignore with --verbose' '
411 expect "a/.gitignore:2:*three a/3-three" &&
412 test_check_ignore "--verbose a/3-three a/three-not-this-one"
415 test_expect_success 'local ignore inside a sub-directory' '
416 expect "3-three" &&
418 cd a &&
419 test_check_ignore "3-three three-not-this-one"
422 test_expect_success 'local ignore inside a sub-directory with --verbose' '
423 expect "a/.gitignore:2:*three 3-three" &&
425 cd a &&
426 test_check_ignore "--verbose 3-three three-not-this-one"
430 test_expect_success 'nested include of negated pattern' '
431 expect "" &&
432 test_check_ignore "a/b/one" 1
435 test_expect_success 'nested include of negated pattern with -q' '
436 expect "" &&
437 test_check_ignore "-q a/b/one" 1
440 test_expect_success 'nested include of negated pattern with -v' '
441 expect "a/b/.gitignore:8:!on* a/b/one" &&
442 test_check_ignore "-v a/b/one" 0
445 test_expect_success 'nested include of negated pattern with -v -n' '
446 expect "a/b/.gitignore:8:!on* a/b/one" &&
447 test_check_ignore "-v -n a/b/one" 0
450 ############################################################################
452 # test ignored sub-directories
454 test_expect_success_multi 'ignored sub-directory' \
455 'a/b/.gitignore:5:ignored-dir/ a/b/ignored-dir' '
456 test_check_ignore "a/b/ignored-dir"
459 test_expect_success 'multiple files inside ignored sub-directory' '
460 expect_from_stdin <<-\EOF &&
461 a/b/ignored-dir/foo
462 a/b/ignored-dir/twoooo
463 a/b/ignored-dir/seven
465 test_check_ignore "a/b/ignored-dir/foo a/b/ignored-dir/twoooo a/b/ignored-dir/seven"
468 test_expect_success 'multiple files inside ignored sub-directory with -v' '
469 expect_from_stdin <<-\EOF &&
470 a/b/.gitignore:5:ignored-dir/ a/b/ignored-dir/foo
471 a/b/.gitignore:5:ignored-dir/ a/b/ignored-dir/twoooo
472 a/b/.gitignore:5:ignored-dir/ a/b/ignored-dir/seven
474 test_check_ignore "-v a/b/ignored-dir/foo a/b/ignored-dir/twoooo a/b/ignored-dir/seven"
477 test_expect_success 'cd to ignored sub-directory' '
478 expect_from_stdin <<-\EOF &&
480 twoooo
481 seven
482 ../../one
485 cd a/b/ignored-dir &&
486 test_check_ignore "foo twoooo ../one seven ../../one"
490 test_expect_success 'cd to ignored sub-directory with -v' '
491 expect_from_stdin <<-\EOF &&
492 a/b/.gitignore:5:ignored-dir/ foo
493 a/b/.gitignore:5:ignored-dir/ twoooo
494 a/b/.gitignore:8:!on* ../one
495 a/b/.gitignore:5:ignored-dir/ seven
496 .gitignore:1:one ../../one
499 cd a/b/ignored-dir &&
500 test_check_ignore "-v foo twoooo ../one seven ../../one"
504 ############################################################################
506 # test handling of symlinks
508 test_expect_success_multi SYMLINKS 'symlink' ':: a/symlink' '
509 test_check_ignore "a/symlink" 1
512 test_expect_success_multi SYMLINKS 'beyond a symlink' '' '
513 test_check_ignore "a/symlink/foo" 128 &&
514 test_stderr "fatal: pathspec '\''a/symlink/foo'\'' is beyond a symbolic link"
517 test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' '
519 cd a &&
520 test_check_ignore "symlink/foo" 128
521 ) &&
522 test_stderr "fatal: pathspec '\''symlink/foo'\'' is beyond a symbolic link"
525 ############################################################################
527 # test handling of submodules
529 test_expect_success_multi 'submodule' '' '
530 test_check_ignore "a/submodule/one" 128 &&
531 test_stderr "fatal: Pathspec '\''a/submodule/one'\'' is in submodule '\''a/submodule'\''"
534 test_expect_success_multi 'submodule from subdirectory' '' '
536 cd a &&
537 test_check_ignore "submodule/one" 128
538 ) &&
539 test_stderr "fatal: Pathspec '\''submodule/one'\'' is in submodule '\''a/submodule'\''"
542 ############################################################################
544 # test handling of global ignore files
546 test_expect_success 'global ignore not yet enabled' '
547 expect_from_stdin <<-\EOF &&
548 .git/info/exclude:1:per-repo per-repo
549 a/.gitignore:2:*three a/globalthree
550 .git/info/exclude:1:per-repo a/per-repo
552 test_check_ignore "-v globalone per-repo a/globalthree a/per-repo not-ignored a/globaltwo"
555 test_expect_success 'global ignore' '
556 enable_global_excludes &&
557 expect_from_stdin <<-\EOF &&
558 globalone
559 per-repo
560 globalthree
561 a/globalthree
562 a/per-repo
564 test_check_ignore "globalone per-repo globalthree a/globalthree a/per-repo not-ignored globaltwo"
567 test_expect_success 'global ignore with -v' '
568 enable_global_excludes &&
569 expect_from_stdin <<-EOF &&
570 $global_excludes:1:globalone globalone
571 .git/info/exclude:1:per-repo per-repo
572 $global_excludes:3:globalthree globalthree
573 a/.gitignore:2:*three a/globalthree
574 .git/info/exclude:1:per-repo a/per-repo
575 $global_excludes:2:!globaltwo globaltwo
577 test_check_ignore "-v globalone per-repo globalthree a/globalthree a/per-repo not-ignored globaltwo"
580 ############################################################################
582 # test --stdin
584 cat <<-\EOF >stdin
586 not-ignored
587 a/one
588 a/not-ignored
589 a/b/on
590 a/b/one
591 a/b/one one
592 "a/b/one two"
593 "a/b/one\"three"
594 a/b/not-ignored
595 a/b/two
596 a/b/twooo
597 globaltwo
598 a/globaltwo
599 a/b/globaltwo
600 b/globaltwo
602 cat <<-\EOF >expected-default
604 a/one
605 a/b/twooo
607 cat <<-EOF >expected-verbose
608 .gitignore:1:one one
609 .gitignore:1:one a/one
610 a/b/.gitignore:8:!on* a/b/on
611 a/b/.gitignore:8:!on* a/b/one
612 a/b/.gitignore:8:!on* a/b/one one
613 a/b/.gitignore:8:!on* a/b/one two
614 a/b/.gitignore:8:!on* "a/b/one\\"three"
615 a/b/.gitignore:9:!two a/b/two
616 a/.gitignore:1:two* a/b/twooo
617 $global_excludes:2:!globaltwo globaltwo
618 $global_excludes:2:!globaltwo a/globaltwo
619 $global_excludes:2:!globaltwo a/b/globaltwo
620 $global_excludes:2:!globaltwo b/globaltwo
623 broken_c_unquote stdin >stdin0
625 broken_c_unquote expected-default >expected-default0
627 broken_c_unquote_verbose expected-verbose >expected-verbose0
629 test_expect_success '--stdin' '
630 expect_from_stdin <expected-default &&
631 test_check_ignore "--stdin" <stdin
634 test_expect_success '--stdin -q' '
635 expect "" &&
636 test_check_ignore "-q --stdin" <stdin
639 test_expect_success '--stdin -v' '
640 expect_from_stdin <expected-verbose &&
641 test_check_ignore "-v --stdin" <stdin
644 for opts in '--stdin -z' '-z --stdin'
646 test_expect_success "$opts" "
647 expect_from_stdin <expected-default0 &&
648 test_check_ignore '$opts' <stdin0
651 test_expect_success "$opts -q" "
652 expect "" &&
653 test_check_ignore '-q $opts' <stdin0
656 test_expect_success "$opts -v" "
657 expect_from_stdin <expected-verbose0 &&
658 test_check_ignore '-v $opts' <stdin0
660 done
662 cat <<-\EOF >stdin
663 ../one
664 ../not-ignored
666 not-ignored
667 b/on
668 b/one
669 b/one one
670 "b/one two"
671 "b/one\"three"
672 b/two
673 b/not-ignored
674 b/twooo
675 ../globaltwo
676 globaltwo
677 b/globaltwo
678 ../b/globaltwo
679 c/not-ignored
681 # N.B. we deliberately end STDIN with a non-matching pattern in order
682 # to test that the exit code indicates that one or more of the
683 # provided paths is ignored - in other words, that it represents an
684 # aggregation of all the results, not just the final result.
686 cat <<-EOF >expected-all
687 .gitignore:1:one ../one
688 :: ../not-ignored
689 .gitignore:1:one one
690 :: not-ignored
691 a/b/.gitignore:8:!on* b/on
692 a/b/.gitignore:8:!on* b/one
693 a/b/.gitignore:8:!on* b/one one
694 a/b/.gitignore:8:!on* b/one two
695 a/b/.gitignore:8:!on* "b/one\\"three"
696 a/b/.gitignore:9:!two b/two
697 :: b/not-ignored
698 a/.gitignore:1:two* b/twooo
699 $global_excludes:2:!globaltwo ../globaltwo
700 $global_excludes:2:!globaltwo globaltwo
701 $global_excludes:2:!globaltwo b/globaltwo
702 $global_excludes:2:!globaltwo ../b/globaltwo
703 :: c/not-ignored
705 cat <<-EOF >expected-default
706 ../one
708 b/twooo
710 grep -v '^:: ' expected-all >expected-verbose
712 broken_c_unquote stdin >stdin0
714 broken_c_unquote expected-default >expected-default0
716 broken_c_unquote_verbose expected-verbose >expected-verbose0
718 test_expect_success '--stdin from subdirectory' '
719 expect_from_stdin <expected-default &&
721 cd a &&
722 test_check_ignore "--stdin" <../stdin
726 test_expect_success '--stdin from subdirectory with -v' '
727 expect_from_stdin <expected-verbose &&
729 cd a &&
730 test_check_ignore "--stdin -v" <../stdin
734 test_expect_success '--stdin from subdirectory with -v -n' '
735 expect_from_stdin <expected-all &&
737 cd a &&
738 test_check_ignore "--stdin -v -n" <../stdin
742 for opts in '--stdin -z' '-z --stdin'
744 test_expect_success "$opts from subdirectory" '
745 expect_from_stdin <expected-default0 &&
747 cd a &&
748 test_check_ignore "'"$opts"'" <../stdin0
752 test_expect_success "$opts from subdirectory with -v" '
753 expect_from_stdin <expected-verbose0 &&
755 cd a &&
756 test_check_ignore "'"$opts"' -v" <../stdin0
759 done
761 test_expect_success PIPE 'streaming support for --stdin' '
762 mkfifo in out &&
763 (git check-ignore -n -v --stdin <in >out &) &&
765 # We cannot just "echo >in" because check-ignore would get EOF
766 # after echo exited; instead we open the descriptor in our
767 # shell, and then echo to the fd. We make sure to close it at
768 # the end, so that the subprocess does get EOF and dies
769 # properly.
771 # Similarly, we must keep "out" open so that check-ignore does
772 # not ever get SIGPIPE trying to write to us. Not only would that
773 # produce incorrect results, but then there would be no writer on the
774 # other end of the pipe, and we would potentially block forever trying
775 # to open it.
776 exec 9>in &&
777 exec 8<out &&
778 test_when_finished "exec 9>&-" &&
779 test_when_finished "exec 8<&-" &&
780 echo >&9 one &&
781 read response <&8 &&
782 echo "$response" | grep "^\.gitignore:1:one one" &&
783 echo >&9 two &&
784 read response <&8 &&
785 echo "$response" | grep "^:: two"
788 test_expect_success 'existing file and directory' '
789 test_when_finished "rm one" &&
790 test_when_finished "rmdir top-level-dir" &&
791 >one &&
792 mkdir top-level-dir &&
793 git check-ignore one top-level-dir >actual &&
794 grep one actual &&
795 grep top-level-dir actual
798 test_expect_success 'existing directory and file' '
799 test_when_finished "rm one" &&
800 test_when_finished "rmdir top-level-dir" &&
801 >one &&
802 mkdir top-level-dir &&
803 git check-ignore top-level-dir one >actual &&
804 grep one actual &&
805 grep top-level-dir actual
808 test_expect_success 'exact prefix matching (with root)' '
809 test_when_finished rm -r a &&
810 mkdir -p a/git a/git-foo &&
811 touch a/git/foo a/git-foo/bar &&
812 echo /git/ >a/.gitignore &&
813 git check-ignore a/git a/git/foo a/git-foo a/git-foo/bar >actual &&
814 cat >expect <<-\EOF &&
815 a/git
816 a/git/foo
818 test_cmp expect actual
821 test_expect_success 'exact prefix matching (without root)' '
822 test_when_finished rm -r a &&
823 mkdir -p a/git a/git-foo &&
824 touch a/git/foo a/git-foo/bar &&
825 echo git/ >a/.gitignore &&
826 git check-ignore a/git a/git/foo a/git-foo a/git-foo/bar >actual &&
827 cat >expect <<-\EOF &&
828 a/git
829 a/git/foo
831 test_cmp expect actual
834 test_expect_success 'directories and ** matches' '
835 cat >.gitignore <<-\EOF &&
836 data/**
837 !data/**/
838 !data/**/*.txt
840 git check-ignore file \
841 data/file data/data1/file1 data/data1/file1.txt \
842 data/data2/file2 data/data2/file2.txt >actual &&
843 cat >expect <<-\EOF &&
844 data/file
845 data/data1/file1
846 data/data2/file2
848 test_cmp expect actual
851 ############################################################################
853 # test whitespace handling
855 test_expect_success 'trailing whitespace is ignored' '
856 mkdir whitespace &&
857 >whitespace/trailing &&
858 >whitespace/untracked &&
859 echo "whitespace/trailing " >ignore &&
860 cat >expect <<EOF &&
861 whitespace/untracked
863 git ls-files -o -X ignore whitespace >actual 2>err &&
864 test_cmp expect actual &&
865 test_must_be_empty err
868 test_expect_success !MINGW 'quoting allows trailing whitespace' '
869 rm -rf whitespace &&
870 mkdir whitespace &&
871 >"whitespace/trailing " &&
872 >whitespace/untracked &&
873 echo "whitespace/trailing\\ \\ " >ignore &&
874 echo whitespace/untracked >expect &&
875 git ls-files -o -X ignore whitespace >actual 2>err &&
876 test_cmp expect actual &&
877 test_must_be_empty err
880 test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' '
881 rm -rf whitespace &&
882 mkdir whitespace &&
883 >"whitespace/trailing 1 " &&
884 >"whitespace/trailing 2 \\\\" &&
885 >"whitespace/trailing 3 \\\\" &&
886 >"whitespace/trailing 4 \\ " &&
887 >"whitespace/trailing 5 \\ \\ " &&
888 >"whitespace/trailing 6 \\a\\" &&
889 >whitespace/untracked &&
890 sed -e "s/Z$//" >ignore <<-\EOF &&
891 whitespace/trailing 1 \ Z
892 whitespace/trailing 2 \\\\Z
893 whitespace/trailing 3 \\\\ Z
894 whitespace/trailing 4 \\\ Z
895 whitespace/trailing 5 \\ \\\ Z
896 whitespace/trailing 6 \\a\\Z
898 echo whitespace/untracked >expect &&
899 git ls-files -o -X ignore whitespace >actual 2>err &&
900 test_cmp expect actual &&
901 test_must_be_empty err
904 test_expect_success 'info/exclude trumps core.excludesfile' '
905 echo >>global-excludes usually-ignored &&
906 echo >>.git/info/exclude "!usually-ignored" &&
907 >usually-ignored &&
908 echo "?? usually-ignored" >expect &&
910 git status --porcelain usually-ignored >actual &&
911 test_cmp expect actual
914 test_expect_success SYMLINKS 'set up ignore file for symlink tests' '
915 echo "*" >ignore &&
916 rm -f .gitignore .git/info/exclude
919 test_expect_success SYMLINKS 'symlinks respected in core.excludesFile' '
920 test_when_finished "rm symlink" &&
921 ln -s ignore symlink &&
922 test_config core.excludesFile "$(pwd)/symlink" &&
923 echo file >expect &&
924 git check-ignore file >actual 2>err &&
925 test_cmp expect actual &&
926 test_must_be_empty err
929 test_expect_success SYMLINKS 'symlinks respected in info/exclude' '
930 test_when_finished "rm .git/info/exclude" &&
931 ln -s ../../ignore .git/info/exclude &&
932 echo file >expect &&
933 git check-ignore file >actual 2>err &&
934 test_cmp expect actual &&
935 test_must_be_empty err
938 test_expect_success SYMLINKS 'symlinks not respected in-tree' '
939 test_when_finished "rm .gitignore" &&
940 ln -s ignore .gitignore &&
941 mkdir subdir &&
942 ln -s ignore subdir/.gitignore &&
943 test_must_fail git check-ignore subdir/file >actual 2>err &&
944 test_must_be_empty actual &&
945 test_grep "unable to access.*gitignore" err
948 test_expect_success EXPENSIVE 'large exclude file ignored in tree' '
949 test_when_finished "rm .gitignore" &&
950 dd if=/dev/zero of=.gitignore bs=101M count=1 &&
951 git ls-files -o --exclude-standard 2>err &&
952 echo "warning: ignoring excessively large pattern file: .gitignore" >expect &&
953 test_cmp expect err
956 test_done