3 test_description
='test case exclude pathspec'
7 test_expect_success
'setup' '
8 for p in file sub/file sub/sub/file sub/file2 sub/sub/sub/file sub2/file; do
9 if echo $p | grep /; then
10 mkdir -p $(dirname $p)
14 git commit -m $p || return 1
16 git log --oneline --format=%s >actual &&
25 test_cmp expect actual
28 test_expect_success
'exclude only pathspec uses default implicit pathspec' '
29 git log --oneline --format=%s -- . ":(exclude)sub" >expect &&
30 git log --oneline --format=%s -- ":(exclude)sub" >actual &&
31 test_cmp expect actual
34 test_expect_success
't_e_i() exclude sub' '
35 git log --oneline --format=%s -- . ":(exclude)sub" >actual &&
40 test_cmp expect actual
43 test_expect_success
't_e_i() exclude sub/sub/file' '
44 git log --oneline --format=%s -- . ":(exclude)sub/sub/file" >actual &&
52 test_cmp expect actual
55 test_expect_success
't_e_i() exclude sub using mnemonic' '
56 git log --oneline --format=%s -- . ":!sub" >actual &&
61 test_cmp expect actual
64 test_expect_success
't_e_i() exclude :(icase)SUB' '
65 git log --oneline --format=%s -- . ":(exclude,icase)SUB" >actual &&
70 test_cmp expect actual
73 test_expect_success
't_e_i() exclude sub2 from sub' '
76 git log --oneline --format=%s -- :/ ":/!sub2" >actual &&
84 test_cmp expect actual
88 test_expect_success
't_e_i() exclude sub/*file' '
89 git log --oneline --format=%s -- . ":(exclude)sub/*file" >actual &&
95 test_cmp expect actual
98 test_expect_success
't_e_i() exclude :(glob)sub/*/file' '
99 git log --oneline --format=%s -- . ":(exclude,glob)sub/*/file" >actual &&
107 test_cmp expect actual
110 test_expect_success
'm_p_d() exclude sub' '
111 git ls-files -- . ":(exclude)sub" >actual &&
116 test_cmp expect actual
119 test_expect_success
'm_p_d() exclude sub/sub/file' '
120 git ls-files -- . ":(exclude)sub/sub/file" >actual &&
128 test_cmp expect actual
131 test_expect_success
'm_p_d() exclude sub using mnemonic' '
132 git ls-files -- . ":!sub" >actual &&
137 test_cmp expect actual
140 test_expect_success
'm_p_d() exclude :(icase)SUB' '
141 git ls-files -- . ":(exclude,icase)SUB" >actual &&
146 test_cmp expect actual
149 test_expect_success
'm_p_d() exclude sub2 from sub' '
152 git ls-files -- :/ ":/!sub2" >actual &&
160 test_cmp expect actual
164 test_expect_success
'm_p_d() exclude sub/*file' '
165 git ls-files -- . ":(exclude)sub/*file" >actual &&
171 test_cmp expect actual
174 test_expect_success
'm_p_d() exclude :(glob)sub/*/file' '
175 git ls-files -- . ":(exclude,glob)sub/*/file" >actual &&
183 test_cmp expect actual
186 test_expect_success
'multiple exclusions' '
187 git ls-files -- ":^*/file2" ":^sub2" >actual &&
188 cat <<-\EOF >expect &&
194 test_cmp expect actual
197 test_expect_success
't_e_i() exclude case #8' '
198 test_when_finished "rm -fr case8" &&
204 git add file1 file2 &&
205 git commit -m twofiles &&
206 git grep -l file HEAD :^file2 >actual &&
207 echo HEAD:file1 >expected &&
208 test_cmp expected actual &&
209 git grep -l file HEAD :^file1 >actual &&
210 echo HEAD:file2 >expected &&
211 test_cmp expected actual
215 test_expect_success
'grep --untracked PATTERN' '
216 # This test is not an actual test of exclude patterns, rather it
217 # is here solely to ensure that if any tests are inserted, deleted, or
218 # changed above, that we still have untracked files with the expected
219 # contents for the NEXT two tests.
220 cat <<-\EOF >expect-grep &&
226 git grep -l --untracked file -- >actual-grep &&
227 test_cmp expect-grep actual-grep
230 test_expect_success
'grep --untracked PATTERN :(exclude)DIR' '
231 cat <<-\EOF >expect-grep &&
235 git grep -l --untracked file -- ":(exclude)sub" >actual-grep &&
236 test_cmp expect-grep actual-grep
239 test_expect_success
'grep --untracked PATTERN :(exclude)*FILE' '
240 cat <<-\EOF >expect-grep &&
244 git grep -l --untracked file -- ":(exclude)*expect" >actual-grep &&
245 test_cmp expect-grep actual-grep
248 # Depending on the command, all negative pathspec needs to subtract
249 # either from the full tree, or from the current directory.
251 # The sample tree checked out at this point has:
259 # but there may also be some cruft that interferes with "git clean"
260 # and "git add" tests.
262 test_expect_success
'archive with all negative' '
265 git -C sub archive --format=tar HEAD -- ":!sub/" >archive &&
266 "$TAR" tf archive >actual &&
267 cat >expect <<-\EOF &&
271 test_cmp expect actual
274 test_expect_success
'add with all negative' '
275 H=$(git rev-parse HEAD) &&
276 git reset --hard $H &&
278 test_when_finished "git reset --hard $H" &&
279 for path in file sub/file sub/sub/file sub2/file
281 echo smudge >>"$path" || return 1
283 git -C sub add -- ":!sub/" &&
284 git diff --name-only --no-renames --cached >actual &&
285 cat >expect <<-\EOF &&
290 test_cmp expect actual &&
291 git diff --name-only --no-renames >actual &&
292 echo sub/sub/file >expect &&
293 test_cmp expect actual
296 test_expect_success
'add -p with all negative' '
297 H=$(git rev-parse HEAD) &&
298 git reset --hard $H &&
300 test_when_finished "git reset --hard $H" &&
301 for path in file sub/file sub/sub/file sub2/file
303 echo smudge >>"$path" || return 1
305 yes | git -C sub add -p -- ":!sub/" &&
306 git diff --name-only --no-renames --cached >actual &&
307 cat >expect <<-\EOF &&
312 test_cmp expect actual &&
313 git diff --name-only --no-renames >actual &&
314 echo sub/sub/file >expect &&
315 test_cmp expect actual
318 test_expect_success
'clean with all negative' '
319 H=$(git rev-parse HEAD) &&
320 git reset --hard $H &&
321 test_when_finished "git reset --hard $H && git clean -f" &&
323 for path in file9 sub/file9 sub/sub/file9 sub2/file9
325 echo cruft >"$path" || return 1
327 git -C sub clean -f -- ":!sub" &&
328 test_path_is_file file9 &&
329 test_path_is_missing sub/file9 &&
330 test_path_is_file sub/sub/file9 &&
331 test_path_is_file sub2/file9
334 test_expect_success
'commit with all negative' '
335 H=$(git rev-parse HEAD) &&
336 git reset --hard $H &&
337 test_when_finished "git reset --hard $H" &&
338 for path in file sub/file sub/sub/file sub2/file
340 echo smudge >>"$path" || return 1
342 git -C sub commit -m sample -- ":!sub/" &&
343 git diff --name-only --no-renames HEAD^ HEAD >actual &&
344 cat >expect <<-\EOF &&
349 test_cmp expect actual &&
350 git diff --name-only --no-renames HEAD >actual &&
351 echo sub/sub/file >expect &&
352 test_cmp expect actual
355 test_expect_success
'reset with all negative' '
356 H=$(git rev-parse HEAD) &&
357 git reset --hard $H &&
358 test_when_finished "git reset --hard $H" &&
359 for path in file sub/file sub/sub/file sub2/file
361 echo smudge >>"$path" &&
362 git add "$path" || return 1
364 git -C sub reset --quiet -- ":!sub/" &&
365 git diff --name-only --no-renames --cached >actual &&
366 echo sub/sub/file >expect &&
367 test_cmp expect actual
370 test_expect_success
'grep with all negative' '
371 H=$(git rev-parse HEAD) &&
372 git reset --hard $H &&
373 test_when_finished "git reset --hard $H" &&
374 for path in file sub/file sub/sub/file sub2/file
376 echo "needle $path" >>"$path" || return 1
378 git -C sub grep -h needle -- ":!sub/" >actual &&
379 cat >expect <<-\EOF &&
382 test_cmp expect actual
385 test_expect_success
'ls-files with all negative' '
387 git -C sub ls-files -- ":!sub/" >actual &&
388 cat >expect <<-\EOF &&
392 test_cmp expect actual
395 test_expect_success
'rm with all negative' '
397 test_when_finished "git reset --hard" &&
398 git -C sub rm -r --cached -- ":!sub/" >actual &&
399 git diff --name-only --no-renames --diff-filter=D --cached >actual &&
400 cat >expect <<-\EOF &&
404 test_cmp expect actual
407 test_expect_success
'stash with all negative' '
408 H=$(git rev-parse HEAD) &&
409 git reset --hard $H &&
410 test_when_finished "git reset --hard $H" &&
411 for path in file sub/file sub/sub/file sub2/file
413 echo smudge >>"$path" || return 1
415 git -C sub stash push -m sample -- ":!sub/" &&
416 git diff --name-only --no-renames HEAD >actual &&
417 echo sub/sub/file >expect &&
418 test_cmp expect actual &&
419 git stash show --name-only >actual &&
420 cat >expect <<-\EOF &&
425 test_cmp expect actual