@@ -66,24 +66,33 @@ test_check_ignore () {
66
66
67
67
init_vars &&
68
68
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 \
70
70
> " $HOME /cmd" &&
71
+ echo " $expect_code " > " $HOME /expected-exit-code" &&
71
72
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 \
73
74
> " $HOME /stdout" 2> " $HOME /stderr" &&
74
75
test_cmp " $HOME /expected-stdout" " $HOME /stdout" &&
75
76
stderr_empty_on_success " $expect_code "
76
77
}
77
78
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
+ #
79
86
# expecting success each time. Takes advantage of the fact that
80
87
# check-ignore --verbose output is the same as normal output except
81
88
# for the extra first column.
82
89
#
83
90
# Arguments:
84
91
# - (optional) prereqs for this test, e.g. 'SYMLINKS'
85
92
# - 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)
87
96
# - code to run (should invoke test_check_ignore)
88
97
test_expect_success_multi () {
89
98
prereq=
@@ -92,32 +101,50 @@ test_expect_success_multi () {
92
101
prereq=$1
93
102
shift
94
103
fi
95
- testname=" $1 " expect_verbose =" $2 " code=" $3 "
104
+ testname=" $1 " expect_all =" $2 " code=" $3 "
96
105
106
+ expect_verbose=$( echo " $expect_all " | grep -v ' ^:: ' )
97
107
expect=$( echo " $expect_verbose " | sed -e ' s/.* //' )
98
108
99
109
test_expect_success $prereq " $testname " '
100
110
expect "$expect" &&
101
111
eval "$code"
102
112
'
103
113
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 } " "
107
120
expect '' &&
108
121
$code
109
122
"
110
- done
111
- quiet_opt=
123
+ done
124
+ quiet_opt=
125
+ fi
112
126
113
127
for verbose_opt in ' -v' ' --verbose'
114
128
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
119
145
done
120
146
verbose_opt=
147
+ non_matching_opt=
121
148
}
122
149
123
150
test_expect_success ' setup' '
@@ -178,7 +205,7 @@ test_expect_success 'setup' '
178
205
#
179
206
# test invalid inputs
180
207
181
- test_expect_success_multi ' . corner-case' ' ' '
208
+ test_expect_success_multi ' . corner-case' ' :: . ' '
182
209
test_check_ignore . 1
183
210
'
184
211
276
303
where=" in subdir $subdir "
277
304
fi
278
305
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 "
282
309
283
310
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'"
287
313
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 "
291
317
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 "
295
321
296
322
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
+ "
300
339
done
301
340
302
341
# 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' '
391
430
#
392
431
# test handling of symlinks
393
432
394
- test_expect_success_multi SYMLINKS ' symlink' ' ' '
433
+ test_expect_success_multi SYMLINKS ' symlink' ' :: a/symlink ' '
395
434
test_check_ignore "a/symlink" 1
396
435
'
397
436
@@ -574,22 +613,33 @@ cat <<-\EOF >stdin
574
613
globaltwo
575
614
b/globaltwo
576
615
../b/globaltwo
616
+ c/not-ignored
577
617
EOF
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
579
624
.gitignore:1:one ../one
625
+ :: ../not-ignored
580
626
.gitignore:1:one one
627
+ :: not-ignored
581
628
a/b/.gitignore:8:!on* b/on
582
629
a/b/.gitignore:8:!on* b/one
583
630
a/b/.gitignore:8:!on* b/one one
584
631
a/b/.gitignore:8:!on* b/one two
585
632
a/b/.gitignore:8:!on* "b/one\"three"
586
633
a/b/.gitignore:9:!two b/two
634
+ :: b/not-ignored
587
635
a/.gitignore:1:two* b/twooo
588
636
$global_excludes :2:!globaltwo ../globaltwo
589
637
$global_excludes :2:!globaltwo globaltwo
590
638
$global_excludes :2:!globaltwo b/globaltwo
591
639
$global_excludes :2:!globaltwo ../b/globaltwo
640
+ :: c/not-ignored
592
641
EOF
642
+ grep -v ' ^:: ' expected-all > expected-verbose
593
643
sed -e ' s/.* //' expected-verbose > expected-default
594
644
595
645
sed -e ' s/^"//' -e ' s/\\//' -e ' s/"$//' stdin | \
@@ -615,6 +665,14 @@ test_expect_success '--stdin from subdirectory with -v' '
615
665
)
616
666
'
617
667
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
+
618
676
for opts in ' --stdin -z' ' -z --stdin'
619
677
do
620
678
test_expect_success " $opts from subdirectory" '
0 commit comments