3 test_description
='test labels in pathspecs'
6 test_expect_success
'setup a tree' '
34 echo content >$path &&
35 git add $path || return 1
37 git commit -m "initial commit" &&
38 git ls-files >actual &&
39 test_cmp expect actual
42 test_expect_success
'pathspec with no attr' '
43 test_must_fail git ls-files ":(attr:)"
46 test_expect_success
'pathspec with labels and non existent .gitattributes' '
47 git ls-files ":(attr:label)" >actual &&
48 test_must_be_empty actual
51 test_expect_success
'pathspec with labels and non existent .gitattributes (2)' '
52 test_must_fail git grep content HEAD -- ":(attr:label)"
55 test_expect_success
'setup .gitattributes' '
56 cat <<-\EOF >.gitattributes &&
70 echo fileSetLabel label1 >sub/.gitattributes &&
71 git add .gitattributes sub/.gitattributes &&
72 git commit -m "add attributes"
75 test_expect_success
'setup .gitignore' '
76 cat <<-\EOF >.gitignore &&
82 git commit -m "add gitignore"
85 test_expect_success
'check specific set attr' '
86 cat <<-\EOF >expect &&
90 git ls-files ":(attr:label)" >actual &&
91 test_cmp expect actual
94 test_expect_success
'check set attr with pathspec pattern' '
95 echo sub/fileSetLabel >expect &&
97 git ls-files ":(attr:label)sub" >actual &&
98 test_cmp expect actual &&
100 git ls-files ":(attr:label)sub/" >actual &&
101 test_cmp expect actual
104 test_expect_success
'check specific set attr in tree-ish' '
105 cat <<-\EOF >expect &&
107 HEAD:sub/fileSetLabel
109 git grep -l content HEAD ":(attr:label)" >actual &&
110 test_cmp expect actual
113 test_expect_success
'check specific set attr with pathspec pattern in tree-ish' '
114 echo HEAD:sub/fileSetLabel >expect &&
116 git grep -l content HEAD ":(attr:label)sub" >actual &&
117 test_cmp expect actual &&
119 git grep -l content HEAD ":(attr:label)sub/" >actual &&
120 test_cmp expect actual
123 test_expect_success
'check specific unset attr' '
124 cat <<-\EOF >expect &&
128 git ls-files ":(attr:-label)" >actual &&
129 test_cmp expect actual
132 test_expect_success
'check specific unset attr (2)' '
133 cat <<-\EOF >expect &&
135 HEAD:sub/fileUnsetLabel
137 git grep -l content HEAD ":(attr:-label)" >actual &&
138 test_cmp expect actual
141 test_expect_success
'check specific value attr' '
142 cat <<-\EOF >expect &&
146 git ls-files ":(attr:label=foo)" >actual &&
147 test_cmp expect actual &&
148 git ls-files ":(attr:label=bar)" >actual &&
149 test_must_be_empty actual
152 test_expect_success
'check specific value attr (2)' '
153 cat <<-\EOF >expect &&
157 git grep -l content HEAD ":(attr:label=foo)" >actual &&
158 test_cmp expect actual &&
159 test_must_fail git grep -l content HEAD ":(attr:label=bar)"
162 test_expect_success
'check unspecified attr' '
163 cat <<-\EOF >expect &&
184 git ls-files ":(attr:!label)" >actual &&
185 test_cmp expect actual
188 test_expect_success
'check unspecified attr (2)' '
189 cat <<-\EOF >expect &&
200 HEAD:sub/.gitattributes
208 HEAD:sub/fileWrongLabel
210 git grep -l ^ HEAD ":(attr:!label)" >actual &&
211 test_cmp expect actual
214 test_expect_success
'check multiple unspecified attr' '
215 cat <<-\EOF >expect &&
226 git ls-files ":(attr:!labelB !labelA !label)" >actual &&
227 test_cmp expect actual
230 test_expect_success
'check label with more labels but excluded path' '
231 cat <<-\EOF >expect &&
236 git ls-files ":(attr:labelB)" ":(exclude)sub/" >actual &&
237 test_cmp expect actual
240 test_expect_success
'check label excluding other labels' '
241 cat <<-\EOF >expect &&
248 git ls-files ":(attr:labelB)" ":(exclude,attr:labelC)sub/" >actual &&
249 test_cmp expect actual
252 test_expect_success
'fail on multiple attr specifiers in one pathspec item' '
253 test_must_fail git ls-files . ":(attr:labelB,attr:labelC)" 2>actual &&
254 test_grep "Only one" actual
257 test_expect_success
'fail if attr magic is used in places not implemented' '
258 # The main purpose of this test is to check that we actually fail
259 # when you attempt to use attr magic in commands that do not implement
260 # attr magic. This test does not advocate check-ignore to stay that way.
261 # When you teach the command to grok the pathspec, you need to find
262 # another command to replace it for the test.
263 test_must_fail git check-ignore ":(attr:labelB)" 2>actual &&
264 test_grep "magic not supported" actual
267 test_expect_success
'check that attr magic works for git stash push' '
268 cat <<-\EOF >expect &&
273 git stash push --include-untracked -- ":(exclude,attr:labelB)" &&
274 git stash show --include-untracked --name-status >actual &&
275 test_cmp expect actual
278 test_expect_success
'check that attr magic works for git add --all' '
279 cat <<-\EOF >expect &&
284 git add --all ":(exclude,attr:labelB)" &&
285 git diff --name-only --cached >actual &&
286 git restore -W -S . &&
287 test_cmp expect actual
290 test_expect_success
'check that attr magic works for git add -u' '
291 cat <<-\EOF >expect &&
298 git add -u ":(exclude,attr:labelB)" &&
299 git diff --name-only --cached >actual &&
300 git restore -S -W . && rm sub/new* &&
301 test_cmp expect actual
304 test_expect_success
'check that attr magic works for git add <path>' '
305 cat <<-\EOF >expect &&
314 git add ":(exclude,attr:labelB)sub/*" &&
315 git diff --name-only --cached >actual &&
316 git restore -S -W . &&
317 test_cmp expect actual
320 test_expect_success
'check that attr magic works for git -add .' '
321 cat <<-\EOF >expect &&
329 git add . ":(exclude,attr:labelB)" &&
331 git diff --name-only --cached >actual &&
332 git restore -S -W . &&
333 test_cmp expect actual
336 test_expect_success
'check that attr magic works for git add --pathspec-from-file' '
337 cat <<-\EOF >pathspec_file &&
338 :(exclude,attr:labelB)
340 cat <<-\EOF >expect &&
345 git add --all --pathspec-from-file=pathspec_file &&
346 git diff --name-only --cached >actual &&
347 test_cmp expect actual
350 test_expect_success
'abort on giving invalid label on the command line' '
351 test_must_fail git ls-files . ":(attr:☺)"
354 test_expect_success
'abort on asking for wrong magic' '
355 test_must_fail git ls-files . ":(attr:-label=foo)" &&
356 test_must_fail git ls-files . ":(attr:!label=foo)"
359 test_expect_success
'check attribute list' '
360 cat <<-EOF >>.gitattributes &&
361 * whitespace=indent,trail,space
363 git ls-files ":(attr:whitespace=indent\,trail\,space)" >actual &&
364 git ls-files >expect &&
365 test_cmp expect actual
368 test_expect_success
'backslash cannot be the last character' '
369 test_must_fail git ls-files ":(attr:label=foo\\ labelA=bar)" 2>actual &&
370 test_grep "not allowed as last character in attr value" actual
373 test_expect_success
'backslash cannot be used as a value' '
374 test_must_fail git ls-files ":(attr:label=f\\\oo)" 2>actual &&
375 test_grep "for value matching" actual
378 test_expect_success
'reading from .gitattributes in a subdirectory (1)' '
379 git ls-files ":(attr:label1)" >actual &&
380 test_write_lines "sub/fileSetLabel" >expect &&
381 test_cmp expect actual
384 test_expect_success
'reading from .gitattributes in a subdirectory (2)' '
385 git ls-files ":(attr:label1)sub" >actual &&
386 test_write_lines "sub/fileSetLabel" >expect &&
387 test_cmp expect actual
390 test_expect_success
'reading from .gitattributes in a subdirectory (3)' '
391 git ls-files ":(attr:label1)sub/" >actual &&
392 test_write_lines "sub/fileSetLabel" >expect &&
393 test_cmp expect actual
396 test_expect_success POSIXPERM
'pathspec with builtin_objectmode attr can be used' '
399 git status -s ":(attr:builtin_objectmode=100644)mode_exec_*" >actual &&
400 echo ?? mode_exec_file_1 >expect &&
401 test_cmp expect actual &&
403 git add mode_exec_file_1 &&
404 chmod +x mode_exec_file_1 &&
405 git status -s ":(attr:builtin_objectmode=100755)mode_exec_*" >actual &&
406 echo AM mode_exec_file_1 >expect &&
407 test_cmp expect actual
410 test_expect_success POSIXPERM
'builtin_objectmode attr can be excluded' '
413 chmod +x mode_1_exec &&
414 git status -s ":(exclude,attr:builtin_objectmode=100644)" "mode_1_*" >actual &&
415 echo ?? mode_1_exec >expect &&
416 test_cmp expect actual &&
418 git status -s ":(exclude,attr:builtin_objectmode=100755)" "mode_1_*" >actual &&
419 echo ?? mode_1_regular >expect &&
420 test_cmp expect actual