@@ -66,24 +66,33 @@ test_check_ignore () {
6666
6767 init_vars &&
6868 rm -f " $HOME /stdout" " $HOME /stderr" " $HOME /cmd" &&
69- echo git $global_args check-ignore $quiet_opt $verbose_opt $args \
69+ echo git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $ args \
7070 > " $HOME /cmd" &&
71+ echo " $expect_code " > " $HOME /expected-exit-code" &&
7172 test_expect_code " $expect_code " \
72- git $global_args check-ignore $quiet_opt $verbose_opt $args \
73+ git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $ args \
7374 > " $HOME /stdout" 2> " $HOME /stderr" &&
7475 test_cmp " $HOME /expected-stdout" " $HOME /stdout" &&
7576 stderr_empty_on_success " $expect_code "
7677}
7778
78- # Runs the same code with 3 different levels of output verbosity,
79+ # Runs the same code with 4 different levels of output verbosity:
80+ #
81+ # 1. with -q / --quiet
82+ # 2. with default verbosity
83+ # 3. with -v / --verbose
84+ # 4. with -v / --verbose, *and* -n / --non-matching
85+ #
7986# expecting success each time. Takes advantage of the fact that
8087# check-ignore --verbose output is the same as normal output except
8188# for the extra first column.
8289#
8390# Arguments:
8491# - (optional) prereqs for this test, e.g. 'SYMLINKS'
8592# - test name
86- # - output to expect from -v / --verbose mode
93+ # - output to expect from the fourth verbosity mode (the output
94+ # from the other verbosity modes is automatically inferred
95+ # from this value)
8796# - code to run (should invoke test_check_ignore)
8897test_expect_success_multi () {
8998 prereq=
@@ -92,32 +101,50 @@ test_expect_success_multi () {
92101 prereq=$1
93102 shift
94103 fi
95- testname=" $1 " expect_verbose =" $2 " code=" $3 "
104+ testname=" $1 " expect_all =" $2 " code=" $3 "
96105
106+ expect_verbose=$( echo " $expect_all " | grep -v ' ^:: ' )
97107 expect=$( echo " $expect_verbose " | sed -e ' s/.* //' )
98108
99109 test_expect_success $prereq " $testname " '
100110 expect "$expect" &&
101111 eval "$code"
102112 '
103113
104- for quiet_opt in ' -q' ' --quiet'
105- do
106- test_expect_success $prereq " $testname ${quiet_opt: + with $quiet_opt } " "
114+ # --quiet is only valid when a single pattern is passed
115+ if test $( echo " $expect_all " | wc -l ) = 1
116+ then
117+ for quiet_opt in ' -q' ' --quiet'
118+ do
119+ test_expect_success $prereq " $testname ${quiet_opt: + with $quiet_opt } " "
107120 expect '' &&
108121 $code
109122 "
110- done
111- quiet_opt=
123+ done
124+ quiet_opt=
125+ fi
112126
113127 for verbose_opt in ' -v' ' --verbose'
114128 do
115- test_expect_success $prereq " $testname ${verbose_opt: + with $verbose_opt } " "
116- expect '$expect_verbose ' &&
117- $code
118- "
129+ for non_matching_opt in ' ' ' -n' ' --non-matching'
130+ do
131+ if test -n " $non_matching_opt "
132+ then
133+ my_expect=" $expect_all "
134+ else
135+ my_expect=" $expect_verbose "
136+ fi
137+
138+ test_code="
139+ expect '$my_expect ' &&
140+ $code
141+ "
142+ opts=" $verbose_opt$non_matching_opt "
143+ test_expect_success $prereq " $testname ${opts: + with $opts } " " $test_code "
144+ done
119145 done
120146 verbose_opt=
147+ non_matching_opt=
121148}
122149
123150test_expect_success ' setup' '
@@ -178,7 +205,7 @@ test_expect_success 'setup' '
178205#
179206# test invalid inputs
180207
181- test_expect_success_multi ' . corner-case' ' ' '
208+ test_expect_success_multi ' . corner-case' ' :: . ' '
182209 test_check_ignore . 1
183210'
184211
276303 where=" in subdir $subdir "
277304 fi
278305
279- test_expect_success_multi " non-existent file $where not ignored" ' ' "
280- test_check_ignore ' ${subdir} non-existent' 1
281- "
306+ test_expect_success_multi " non-existent file $where not ignored" \
307+ " :: ${subdir} non-existent" \
308+ " test_check_ignore ' ${subdir} non-existent' 1 "
282309
283310 test_expect_success_multi " non-existent file $where ignored" \
284- " .gitignore:1:one ${subdir} one" "
285- test_check_ignore '${subdir} one'
286- "
311+ " .gitignore:1:one ${subdir} one" \
312+ " test_check_ignore '${subdir} one'"
287313
288- test_expect_success_multi " existing untracked file $where not ignored" ' ' "
289- test_check_ignore ' ${subdir} not-ignored' 1
290- "
314+ test_expect_success_multi " existing untracked file $where not ignored" \
315+ " :: ${subdir} not-ignored" \
316+ " test_check_ignore ' ${subdir} not-ignored' 1 "
291317
292- test_expect_success_multi " existing tracked file $where not ignored" ' ' "
293- test_check_ignore ' ${subdir} ignored-but-in-index' 1
294- "
318+ test_expect_success_multi " existing tracked file $where not ignored" \
319+ " :: ${subdir} ignored-but-in-index" \
320+ " test_check_ignore ' ${subdir} ignored-but-in-index' 1 "
295321
296322 test_expect_success_multi " existing untracked file $where ignored" \
297- " .gitignore:2:ignored-* ${subdir} ignored-and-untracked" "
298- test_check_ignore '${subdir} ignored-and-untracked'
299- "
323+ " .gitignore:2:ignored-* ${subdir} ignored-and-untracked" \
324+ " test_check_ignore '${subdir} ignored-and-untracked'"
325+
326+ test_expect_success_multi " mix of file types $where " \
327+ " :: ${subdir} non-existent
328+ .gitignore:1:one ${subdir} one
329+ :: ${subdir} not-ignored
330+ :: ${subdir} ignored-but-in-index
331+ .gitignore:2:ignored-* ${subdir} ignored-and-untracked" \
332+ " test_check_ignore '
333+ ${subdir} non-existent
334+ ${subdir} one
335+ ${subdir} not-ignored
336+ ${subdir} ignored-but-in-index
337+ ${subdir} ignored-and-untracked'
338+ "
300339done
301340
302341# Having established the above, from now on we mostly test against
@@ -391,7 +430,7 @@ test_expect_success 'cd to ignored sub-directory with -v' '
391430#
392431# test handling of symlinks
393432
394- test_expect_success_multi SYMLINKS ' symlink' ' ' '
433+ test_expect_success_multi SYMLINKS ' symlink' ' :: a/symlink ' '
395434 test_check_ignore "a/symlink" 1
396435'
397436
@@ -574,22 +613,33 @@ cat <<-\EOF >stdin
574613 globaltwo
575614 b/globaltwo
576615 ../b/globaltwo
616+ c/not-ignored
577617EOF
578- cat << -EOF >expected-verbose
618+ # N.B. we deliberately end STDIN with a non-matching pattern in order
619+ # to test that the exit code indicates that one or more of the
620+ # provided paths is ignored - in other words, that it represents an
621+ # aggregation of all the results, not just the final result.
622+
623+ cat << -EOF >expected-all
579624 .gitignore:1:one ../one
625+ :: ../not-ignored
580626 .gitignore:1:one one
627+ :: not-ignored
581628 a/b/.gitignore:8:!on* b/on
582629 a/b/.gitignore:8:!on* b/one
583630 a/b/.gitignore:8:!on* b/one one
584631 a/b/.gitignore:8:!on* b/one two
585632 a/b/.gitignore:8:!on* "b/one\"three"
586633 a/b/.gitignore:9:!two b/two
634+ :: b/not-ignored
587635 a/.gitignore:1:two* b/twooo
588636 $global_excludes :2:!globaltwo ../globaltwo
589637 $global_excludes :2:!globaltwo globaltwo
590638 $global_excludes :2:!globaltwo b/globaltwo
591639 $global_excludes :2:!globaltwo ../b/globaltwo
640+ :: c/not-ignored
592641EOF
642+ grep -v ' ^:: ' expected-all > expected-verbose
593643sed -e ' s/.* //' expected-verbose > expected-default
594644
595645sed -e ' s/^"//' -e ' s/\\//' -e ' s/"$//' stdin | \
@@ -615,6 +665,14 @@ test_expect_success '--stdin from subdirectory with -v' '
615665 )
616666'
617667
668+ test_expect_success ' --stdin from subdirectory with -v -n' '
669+ expect_from_stdin <expected-all &&
670+ (
671+ cd a &&
672+ test_check_ignore "--stdin -v -n" <../stdin
673+ )
674+ '
675+
618676for opts in ' --stdin -z' ' -z --stdin'
619677do
620678 test_expect_success " $opts from subdirectory" '
0 commit comments