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 &&
68 echo fileSetLabel label1 >sub/.gitattributes &&
69 git add .gitattributes sub/.gitattributes &&
70 git commit -m "add attributes"
73 test_expect_success
'check specific set attr' '
74 cat <<-\EOF >expect &&
78 git ls-files ":(attr:label)" >actual &&
79 test_cmp expect actual
82 test_expect_success
'check set attr with pathspec pattern' '
83 echo sub/fileSetLabel >expect &&
85 git ls-files ":(attr:label)sub" >actual &&
86 test_cmp expect actual &&
88 git ls-files ":(attr:label)sub/" >actual &&
89 test_cmp expect actual
92 test_expect_success
'check specific set attr in tree-ish' '
93 cat <<-\EOF >expect &&
97 git grep -l content HEAD ":(attr:label)" >actual &&
98 test_cmp expect actual
101 test_expect_success
'check specific set attr with pathspec pattern in tree-ish' '
102 echo HEAD:sub/fileSetLabel >expect &&
104 git grep -l content HEAD ":(attr:label)sub" >actual &&
105 test_cmp expect actual &&
107 git grep -l content HEAD ":(attr:label)sub/" >actual &&
108 test_cmp expect actual
111 test_expect_success
'check specific unset attr' '
112 cat <<-\EOF >expect &&
116 git ls-files ":(attr:-label)" >actual &&
117 test_cmp expect actual
120 test_expect_success
'check specific unset attr (2)' '
121 cat <<-\EOF >expect &&
123 HEAD:sub/fileUnsetLabel
125 git grep -l content HEAD ":(attr:-label)" >actual &&
126 test_cmp expect actual
129 test_expect_success
'check specific value attr' '
130 cat <<-\EOF >expect &&
134 git ls-files ":(attr:label=foo)" >actual &&
135 test_cmp expect actual &&
136 git ls-files ":(attr:label=bar)" >actual &&
137 test_must_be_empty actual
140 test_expect_success
'check specific value attr (2)' '
141 cat <<-\EOF >expect &&
145 git grep -l content HEAD ":(attr:label=foo)" >actual &&
146 test_cmp expect actual &&
147 test_must_fail git grep -l content HEAD ":(attr:label=bar)"
150 test_expect_success
'check unspecified attr' '
151 cat <<-\EOF >expect &&
171 git ls-files ":(attr:!label)" >actual &&
172 test_cmp expect actual
175 test_expect_success
'check unspecified attr (2)' '
176 cat <<-\EOF >expect &&
186 HEAD:sub/.gitattributes
194 HEAD:sub/fileWrongLabel
196 git grep -l ^ HEAD ":(attr:!label)" >actual &&
197 test_cmp expect actual
200 test_expect_success
'check multiple unspecified attr' '
201 cat <<-\EOF >expect &&
211 git ls-files ":(attr:!labelB !labelA !label)" >actual &&
212 test_cmp expect actual
215 test_expect_success
'check label with more labels but excluded path' '
216 cat <<-\EOF >expect &&
221 git ls-files ":(attr:labelB)" ":(exclude)sub/" >actual &&
222 test_cmp expect actual
225 test_expect_success
'check label excluding other labels' '
226 cat <<-\EOF >expect &&
233 git ls-files ":(attr:labelB)" ":(exclude,attr:labelC)sub/" >actual &&
234 test_cmp expect actual
237 test_expect_success
'fail on multiple attr specifiers in one pathspec item' '
238 test_must_fail git ls-files . ":(attr:labelB,attr:labelC)" 2>actual &&
239 test_grep "Only one" actual
242 test_expect_success
'fail if attr magic is used places not implemented' '
243 # The main purpose of this test is to check that we actually fail
244 # when you attempt to use attr magic in commands that do not implement
245 # attr magic. This test does not advocate git-add to stay that way,
246 # though, but git-add is convenient as it has its own internal pathspec
248 test_must_fail git add ":(attr:labelB)" 2>actual &&
249 test_grep "magic not supported" actual
252 test_expect_success
'abort on giving invalid label on the command line' '
253 test_must_fail git ls-files . ":(attr:☺)"
256 test_expect_success
'abort on asking for wrong magic' '
257 test_must_fail git ls-files . ":(attr:-label=foo)" &&
258 test_must_fail git ls-files . ":(attr:!label=foo)"
261 test_expect_success
'check attribute list' '
262 cat <<-EOF >>.gitattributes &&
263 * whitespace=indent,trail,space
265 git ls-files ":(attr:whitespace=indent\,trail\,space)" >actual &&
266 git ls-files >expect &&
267 test_cmp expect actual
270 test_expect_success
'backslash cannot be the last character' '
271 test_must_fail git ls-files ":(attr:label=foo\\ labelA=bar)" 2>actual &&
272 test_grep "not allowed as last character in attr value" actual
275 test_expect_success
'backslash cannot be used as a value' '
276 test_must_fail git ls-files ":(attr:label=f\\\oo)" 2>actual &&
277 test_grep "for value matching" actual
280 test_expect_success
'reading from .gitattributes in a subdirectory (1)' '
281 git ls-files ":(attr:label1)" >actual &&
282 test_write_lines "sub/fileSetLabel" >expect &&
283 test_cmp expect actual
286 test_expect_success
'reading from .gitattributes in a subdirectory (2)' '
287 git ls-files ":(attr:label1)sub" >actual &&
288 test_write_lines "sub/fileSetLabel" >expect &&
289 test_cmp expect actual
292 test_expect_success
'reading from .gitattributes in a subdirectory (3)' '
293 git ls-files ":(attr:label1)sub/" >actual &&
294 test_write_lines "sub/fileSetLabel" >expect &&
295 test_cmp expect actual