@@ -66,11 +66,11 @@ 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 $non_matching_opt $args \
69+ echo git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $no_index_opt $ args \
7070 > " $HOME /cmd" &&
7171 echo " $expect_code " > " $HOME /expected-exit-code" &&
7272 test_expect_code " $expect_code " \
73- git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $args \
73+ git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $no_index_opt $ args \
7474 > " $HOME /stdout" 2> " $HOME /stderr" &&
7575 test_cmp " $HOME /expected-stdout" " $HOME /stdout" &&
7676 stderr_empty_on_success " $expect_code "
@@ -87,26 +87,36 @@ test_check_ignore () {
8787# check-ignore --verbose output is the same as normal output except
8888# for the extra first column.
8989#
90+ # A parameter is used to determine if the tests are run with the
91+ # normal case (using the index), or with the --no-index option.
92+ #
9093# Arguments:
9194# - (optional) prereqs for this test, e.g. 'SYMLINKS'
9295# - test name
9396# - output to expect from the fourth verbosity mode (the output
9497# from the other verbosity modes is automatically inferred
9598# from this value)
9699# - code to run (should invoke test_check_ignore)
97- test_expect_success_multi () {
100+ # - index option: --index or --no-index
101+ test_expect_success_multiple () {
98102 prereq=
99- if test $# -eq 4
103+ if test $# -eq 5
100104 then
101105 prereq=$1
102106 shift
103107 fi
108+ if test " $4 " = " --index"
109+ then
110+ no_index_opt=
111+ else
112+ no_index_opt=$4
113+ fi
104114 testname=" $1 " expect_all=" $2 " code=" $3 "
105115
106116 expect_verbose=$( echo " $expect_all " | grep -v ' ^:: ' )
107117 expect=$( echo " $expect_verbose " | sed -e ' s/.* //' )
108118
109- test_expect_success $prereq " $testname " '
119+ test_expect_success $prereq " $testname ${no_index_opt : + with $no_index_opt } " '
110120 expect "$expect" &&
111121 eval "$code"
112122 '
@@ -116,7 +126,8 @@ test_expect_success_multi () {
116126 then
117127 for quiet_opt in ' -q' ' --quiet'
118128 do
119- test_expect_success $prereq " $testname ${quiet_opt: + with $quiet_opt } " "
129+ opts=" ${no_index_opt: +$no_index_opt } $quiet_opt "
130+ test_expect_success $prereq " $testname ${opts: + with $opts } " "
120131 expect '' &&
121132 $code
122133 "
@@ -126,7 +137,7 @@ test_expect_success_multi () {
126137
127138 for verbose_opt in ' -v' ' --verbose'
128139 do
129- for non_matching_opt in ' ' ' -n' ' --non-matching'
140+ for non_matching_opt in ' ' ' -n' ' --non-matching'
130141 do
131142 if test -n " $non_matching_opt "
132143 then
@@ -139,12 +150,21 @@ test_expect_success_multi () {
139150 expect '$my_expect ' &&
140151 $code
141152 "
142- opts=" $verbose_opt$non_matching_opt "
153+ opts=" ${no_index_opt : + $no_index_opt } $ verbose_opt${ non_matching_opt: + $non_matching_opt } "
143154 test_expect_success $prereq " $testname ${opts: + with $opts } " " $test_code "
144155 done
145156 done
146157 verbose_opt=
147158 non_matching_opt=
159+ no_index_opt=
160+ }
161+
162+ test_expect_success_multi () {
163+ test_expect_success_multiple " $@ " " --index"
164+ }
165+
166+ test_expect_success_no_index_multi () {
167+ test_expect_success_multiple " $@ " " --no-index"
148168}
149169
150170test_expect_success ' setup' '
@@ -288,7 +308,7 @@ test_expect_success_multi 'needs work tree' '' '
288308
289309# First make sure that the presence of a file in the working tree
290310# does not impact results, but that the presence of a file in the
291- # index does.
311+ # index does unless the --no-index option is used .
292312
293313for subdir in ' ' ' a/'
294314do
303323 " :: ${subdir} non-existent" \
304324 " test_check_ignore '${subdir} non-existent' 1"
305325
326+ test_expect_success_no_index_multi " non-existent file $where not ignored" \
327+ " :: ${subdir} non-existent" \
328+ " test_check_ignore '${subdir} non-existent' 1"
329+
306330 test_expect_success_multi " non-existent file $where ignored" \
307331 " .gitignore:1:one ${subdir} one" \
308332 " test_check_ignore '${subdir} one'"
309333
334+ test_expect_success_no_index_multi " non-existent file $where ignored" \
335+ " .gitignore:1:one ${subdir} one" \
336+ " test_check_ignore '${subdir} one'"
337+
310338 test_expect_success_multi " existing untracked file $where not ignored" \
311339 " :: ${subdir} not-ignored" \
312340 " test_check_ignore '${subdir} not-ignored' 1"
313341
342+ test_expect_success_no_index_multi " existing untracked file $where not ignored" \
343+ " :: ${subdir} not-ignored" \
344+ " test_check_ignore '${subdir} not-ignored' 1"
345+
314346 test_expect_success_multi " existing tracked file $where not ignored" \
315347 " :: ${subdir} ignored-but-in-index" \
316348 " test_check_ignore '${subdir} ignored-but-in-index' 1"
317349
350+ test_expect_success_no_index_multi " existing tracked file $where shown as ignored" \
351+ " .gitignore:2:ignored-* ${subdir} ignored-but-in-index" \
352+ " test_check_ignore '${subdir} ignored-but-in-index'"
353+
318354 test_expect_success_multi " existing untracked file $where ignored" \
319355 " .gitignore:2:ignored-* ${subdir} ignored-and-untracked" \
320356 " test_check_ignore '${subdir} ignored-and-untracked'"
321357
358+ test_expect_success_no_index_multi " existing untracked file $where ignored" \
359+ " .gitignore:2:ignored-* ${subdir} ignored-and-untracked" \
360+ " test_check_ignore '${subdir} ignored-and-untracked'"
361+
322362 test_expect_success_multi " mix of file types $where " \
323363" :: ${subdir} non-existent
324364.gitignore:1:one ${subdir} one
325365:: ${subdir} not-ignored
326366:: ${subdir} ignored-but-in-index
367+ .gitignore:2:ignored-* ${subdir} ignored-and-untracked" \
368+ " test_check_ignore '
369+ ${subdir} non-existent
370+ ${subdir} one
371+ ${subdir} not-ignored
372+ ${subdir} ignored-but-in-index
373+ ${subdir} ignored-and-untracked'
374+ "
375+
376+ test_expect_success_no_index_multi " mix of file types $where " \
377+ " :: ${subdir} non-existent
378+ .gitignore:1:one ${subdir} one
379+ :: ${subdir} not-ignored
380+ .gitignore:2:ignored-* ${subdir} ignored-but-in-index
327381.gitignore:2:ignored-* ${subdir} ignored-and-untracked" \
328382 " test_check_ignore '
329383 ${subdir} non-existent
0 commit comments