Sync with 2.38.5
[git.git] / t / t6132-pathspec-exclude.sh
blobcada952f9aee35fe795af5cd99af222f1a8b599f
1 #!/bin/sh
3 test_description='test case exclude pathspec'
5 . ./test-lib.sh
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)
11 fi &&
12 : >$p &&
13 git add $p &&
14 git commit -m $p || return 1
15 done &&
16 git log --oneline --format=%s >actual &&
17 cat <<EOF >expect &&
18 sub2/file
19 sub/sub/sub/file
20 sub/file2
21 sub/sub/file
22 sub/file
23 file
24 EOF
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 &&
36 cat <<EOF >expect &&
37 sub2/file
38 file
39 EOF
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 &&
45 cat <<EOF >expect &&
46 sub2/file
47 sub/sub/sub/file
48 sub/file2
49 sub/file
50 file
51 EOF
52 test_cmp expect actual
55 test_expect_success 't_e_i() exclude sub using mnemonic' '
56 git log --oneline --format=%s -- . ":!sub" >actual &&
57 cat <<EOF >expect &&
58 sub2/file
59 file
60 EOF
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 &&
66 cat <<EOF >expect &&
67 sub2/file
68 file
69 EOF
70 test_cmp expect actual
73 test_expect_success 't_e_i() exclude sub2 from sub' '
75 cd sub &&
76 git log --oneline --format=%s -- :/ ":/!sub2" >actual &&
77 cat <<EOF >expect &&
78 sub/sub/sub/file
79 sub/file2
80 sub/sub/file
81 sub/file
82 file
83 EOF
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 &&
90 cat <<EOF >expect &&
91 sub2/file
92 sub/file2
93 file
94 EOF
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 &&
100 cat <<EOF >expect &&
101 sub2/file
102 sub/sub/sub/file
103 sub/file2
104 sub/file
105 file
107 test_cmp expect actual
110 test_expect_success 'm_p_d() exclude sub' '
111 git ls-files -- . ":(exclude)sub" >actual &&
112 cat <<EOF >expect &&
113 file
114 sub2/file
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 &&
121 cat <<EOF >expect &&
122 file
123 sub/file
124 sub/file2
125 sub/sub/sub/file
126 sub2/file
128 test_cmp expect actual
131 test_expect_success 'm_p_d() exclude sub using mnemonic' '
132 git ls-files -- . ":!sub" >actual &&
133 cat <<EOF >expect &&
134 file
135 sub2/file
137 test_cmp expect actual
140 test_expect_success 'm_p_d() exclude :(icase)SUB' '
141 git ls-files -- . ":(exclude,icase)SUB" >actual &&
142 cat <<EOF >expect &&
143 file
144 sub2/file
146 test_cmp expect actual
149 test_expect_success 'm_p_d() exclude sub2 from sub' '
151 cd sub &&
152 git ls-files -- :/ ":/!sub2" >actual &&
153 cat <<EOF >expect &&
154 ../file
155 file
156 file2
157 sub/file
158 sub/sub/file
160 test_cmp expect actual
164 test_expect_success 'm_p_d() exclude sub/*file' '
165 git ls-files -- . ":(exclude)sub/*file" >actual &&
166 cat <<EOF >expect &&
167 file
168 sub/file2
169 sub2/file
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 &&
176 cat <<EOF >expect &&
177 file
178 sub/file
179 sub/file2
180 sub/sub/sub/file
181 sub2/file
183 test_cmp expect actual
186 test_expect_success 'multiple exclusions' '
187 git ls-files -- ":^*/file2" ":^sub2" >actual &&
188 cat <<-\EOF >expect &&
189 file
190 sub/file
191 sub/sub/file
192 sub/sub/sub/file
194 test_cmp expect actual
197 test_expect_success 't_e_i() exclude case #8' '
198 test_when_finished "rm -fr case8" &&
199 git init case8 &&
201 cd case8 &&
202 echo file >file1 &&
203 echo file >file2 &&
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 &&
221 actual
222 expect
223 sub/actual
224 sub/expect
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 &&
232 actual
233 expect
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 &&
241 actual
242 sub/actual
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:
252 # file
253 # sub/file
254 # sub/file2
255 # sub/sub/file
256 # sub/sub/sub/file
257 # sub2/file
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' '
263 git reset --hard &&
264 git clean -f &&
265 git -C sub archive --format=tar HEAD -- ":!sub/" >archive &&
266 "$TAR" tf archive >actual &&
267 cat >expect <<-\EOF &&
268 file
269 file2
271 test_cmp expect actual
274 test_expect_success 'add with all negative' '
275 H=$(git rev-parse HEAD) &&
276 git reset --hard $H &&
277 git clean -f &&
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
282 done &&
283 git -C sub add -- ":!sub/" &&
284 git diff --name-only --no-renames --cached >actual &&
285 cat >expect <<-\EOF &&
286 file
287 sub/file
288 sub2/file
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_lazy_prereq ADD_I_USE_BUILTIN_OR_PERL '
297 test_have_prereq ADD_I_USE_BUILTIN || test_have_prereq PERL
300 test_expect_success ADD_I_USE_BUILTIN_OR_PERL 'add -p with all negative' '
301 H=$(git rev-parse HEAD) &&
302 git reset --hard $H &&
303 git clean -f &&
304 test_when_finished "git reset --hard $H" &&
305 for path in file sub/file sub/sub/file sub2/file
307 echo smudge >>"$path" || return 1
308 done &&
309 yes | git -C sub add -p -- ":!sub/" &&
310 git diff --name-only --no-renames --cached >actual &&
311 cat >expect <<-\EOF &&
312 file
313 sub/file
314 sub2/file
316 test_cmp expect actual &&
317 git diff --name-only --no-renames >actual &&
318 echo sub/sub/file >expect &&
319 test_cmp expect actual
322 test_expect_success 'clean with all negative' '
323 H=$(git rev-parse HEAD) &&
324 git reset --hard $H &&
325 test_when_finished "git reset --hard $H && git clean -f" &&
326 git clean -f &&
327 for path in file9 sub/file9 sub/sub/file9 sub2/file9
329 echo cruft >"$path" || return 1
330 done &&
331 git -C sub clean -f -- ":!sub" &&
332 test_path_is_file file9 &&
333 test_path_is_missing sub/file9 &&
334 test_path_is_file sub/sub/file9 &&
335 test_path_is_file sub2/file9
338 test_expect_success 'commit with all negative' '
339 H=$(git rev-parse HEAD) &&
340 git reset --hard $H &&
341 test_when_finished "git reset --hard $H" &&
342 for path in file sub/file sub/sub/file sub2/file
344 echo smudge >>"$path" || return 1
345 done &&
346 git -C sub commit -m sample -- ":!sub/" &&
347 git diff --name-only --no-renames HEAD^ HEAD >actual &&
348 cat >expect <<-\EOF &&
349 file
350 sub/file
351 sub2/file
353 test_cmp expect actual &&
354 git diff --name-only --no-renames HEAD >actual &&
355 echo sub/sub/file >expect &&
356 test_cmp expect actual
359 test_expect_success 'reset with all negative' '
360 H=$(git rev-parse HEAD) &&
361 git reset --hard $H &&
362 test_when_finished "git reset --hard $H" &&
363 for path in file sub/file sub/sub/file sub2/file
365 echo smudge >>"$path" &&
366 git add "$path" || return 1
367 done &&
368 git -C sub reset --quiet -- ":!sub/" &&
369 git diff --name-only --no-renames --cached >actual &&
370 echo sub/sub/file >expect &&
371 test_cmp expect actual
374 test_expect_success 'grep with all negative' '
375 H=$(git rev-parse HEAD) &&
376 git reset --hard $H &&
377 test_when_finished "git reset --hard $H" &&
378 for path in file sub/file sub/sub/file sub2/file
380 echo "needle $path" >>"$path" || return 1
381 done &&
382 git -C sub grep -h needle -- ":!sub/" >actual &&
383 cat >expect <<-\EOF &&
384 needle sub/file
386 test_cmp expect actual
389 test_expect_success 'ls-files with all negative' '
390 git reset --hard &&
391 git -C sub ls-files -- ":!sub/" >actual &&
392 cat >expect <<-\EOF &&
393 file
394 file2
396 test_cmp expect actual
399 test_expect_success 'rm with all negative' '
400 git reset --hard &&
401 test_when_finished "git reset --hard" &&
402 git -C sub rm -r --cached -- ":!sub/" >actual &&
403 git diff --name-only --no-renames --diff-filter=D --cached >actual &&
404 cat >expect <<-\EOF &&
405 sub/file
406 sub/file2
408 test_cmp expect actual
411 test_expect_success 'stash with all negative' '
412 H=$(git rev-parse HEAD) &&
413 git reset --hard $H &&
414 test_when_finished "git reset --hard $H" &&
415 for path in file sub/file sub/sub/file sub2/file
417 echo smudge >>"$path" || return 1
418 done &&
419 git -C sub stash push -m sample -- ":!sub/" &&
420 git diff --name-only --no-renames HEAD >actual &&
421 echo sub/sub/file >expect &&
422 test_cmp expect actual &&
423 git stash show --name-only >actual &&
424 cat >expect <<-\EOF &&
425 file
426 sub/file
427 sub2/file
429 test_cmp expect actual
432 test_done