]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6135-pathspec-with-attrs.sh
submodule-config.c: strengthen URL fsck check
[thirdparty/git.git] / t / t6135-pathspec-with-attrs.sh
1 #!/bin/sh
2
3 test_description='test labels in pathspecs'
4 . ./test-lib.sh
5
6 test_expect_success 'setup a tree' '
7 cat <<-\EOF >expect &&
8 fileA
9 fileAB
10 fileAC
11 fileB
12 fileBC
13 fileC
14 fileNoLabel
15 fileSetLabel
16 fileUnsetLabel
17 fileValue
18 fileWrongLabel
19 sub/fileA
20 sub/fileAB
21 sub/fileAC
22 sub/fileB
23 sub/fileBC
24 sub/fileC
25 sub/fileNoLabel
26 sub/fileSetLabel
27 sub/fileUnsetLabel
28 sub/fileValue
29 sub/fileWrongLabel
30 EOF
31 mkdir sub &&
32 while read path
33 do
34 echo content >$path &&
35 git add $path || return 1
36 done <expect &&
37 git commit -m "initial commit" &&
38 git ls-files >actual &&
39 test_cmp expect actual
40 '
41
42 test_expect_success 'pathspec with no attr' '
43 test_must_fail git ls-files ":(attr:)"
44 '
45
46 test_expect_success 'pathspec with labels and non existent .gitattributes' '
47 git ls-files ":(attr:label)" >actual &&
48 test_must_be_empty actual
49 '
50
51 test_expect_success 'pathspec with labels and non existent .gitattributes (2)' '
52 test_must_fail git grep content HEAD -- ":(attr:label)"
53 '
54
55 test_expect_success 'setup .gitattributes' '
56 cat <<-\EOF >.gitattributes &&
57 fileA labelA
58 fileB labelB
59 fileC labelC
60 fileAB labelA labelB
61 fileAC labelA labelC
62 fileBC labelB labelC
63 fileUnsetLabel -label
64 fileSetLabel label
65 fileValue label=foo
66 fileWrongLabel label☺
67 EOF
68 echo fileSetLabel label1 >sub/.gitattributes &&
69 git add .gitattributes sub/.gitattributes &&
70 git commit -m "add attributes"
71 '
72
73 test_expect_success 'check specific set attr' '
74 cat <<-\EOF >expect &&
75 fileSetLabel
76 sub/fileSetLabel
77 EOF
78 git ls-files ":(attr:label)" >actual &&
79 test_cmp expect actual
80 '
81
82 test_expect_success 'check set attr with pathspec pattern' '
83 echo sub/fileSetLabel >expect &&
84
85 git ls-files ":(attr:label)sub" >actual &&
86 test_cmp expect actual &&
87
88 git ls-files ":(attr:label)sub/" >actual &&
89 test_cmp expect actual
90 '
91
92 test_expect_success 'check specific set attr in tree-ish' '
93 cat <<-\EOF >expect &&
94 HEAD:fileSetLabel
95 HEAD:sub/fileSetLabel
96 EOF
97 git grep -l content HEAD ":(attr:label)" >actual &&
98 test_cmp expect actual
99 '
100
101 test_expect_success 'check specific set attr with pathspec pattern in tree-ish' '
102 echo HEAD:sub/fileSetLabel >expect &&
103
104 git grep -l content HEAD ":(attr:label)sub" >actual &&
105 test_cmp expect actual &&
106
107 git grep -l content HEAD ":(attr:label)sub/" >actual &&
108 test_cmp expect actual
109 '
110
111 test_expect_success 'check specific unset attr' '
112 cat <<-\EOF >expect &&
113 fileUnsetLabel
114 sub/fileUnsetLabel
115 EOF
116 git ls-files ":(attr:-label)" >actual &&
117 test_cmp expect actual
118 '
119
120 test_expect_success 'check specific unset attr (2)' '
121 cat <<-\EOF >expect &&
122 HEAD:fileUnsetLabel
123 HEAD:sub/fileUnsetLabel
124 EOF
125 git grep -l content HEAD ":(attr:-label)" >actual &&
126 test_cmp expect actual
127 '
128
129 test_expect_success 'check specific value attr' '
130 cat <<-\EOF >expect &&
131 fileValue
132 sub/fileValue
133 EOF
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
138 '
139
140 test_expect_success 'check specific value attr (2)' '
141 cat <<-\EOF >expect &&
142 HEAD:fileValue
143 HEAD:sub/fileValue
144 EOF
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)"
148 '
149
150 test_expect_success 'check unspecified attr' '
151 cat <<-\EOF >expect &&
152 .gitattributes
153 fileA
154 fileAB
155 fileAC
156 fileB
157 fileBC
158 fileC
159 fileNoLabel
160 fileWrongLabel
161 sub/.gitattributes
162 sub/fileA
163 sub/fileAB
164 sub/fileAC
165 sub/fileB
166 sub/fileBC
167 sub/fileC
168 sub/fileNoLabel
169 sub/fileWrongLabel
170 EOF
171 git ls-files ":(attr:!label)" >actual &&
172 test_cmp expect actual
173 '
174
175 test_expect_success 'check unspecified attr (2)' '
176 cat <<-\EOF >expect &&
177 HEAD:.gitattributes
178 HEAD:fileA
179 HEAD:fileAB
180 HEAD:fileAC
181 HEAD:fileB
182 HEAD:fileBC
183 HEAD:fileC
184 HEAD:fileNoLabel
185 HEAD:fileWrongLabel
186 HEAD:sub/.gitattributes
187 HEAD:sub/fileA
188 HEAD:sub/fileAB
189 HEAD:sub/fileAC
190 HEAD:sub/fileB
191 HEAD:sub/fileBC
192 HEAD:sub/fileC
193 HEAD:sub/fileNoLabel
194 HEAD:sub/fileWrongLabel
195 EOF
196 git grep -l ^ HEAD ":(attr:!label)" >actual &&
197 test_cmp expect actual
198 '
199
200 test_expect_success 'check multiple unspecified attr' '
201 cat <<-\EOF >expect &&
202 .gitattributes
203 fileC
204 fileNoLabel
205 fileWrongLabel
206 sub/.gitattributes
207 sub/fileC
208 sub/fileNoLabel
209 sub/fileWrongLabel
210 EOF
211 git ls-files ":(attr:!labelB !labelA !label)" >actual &&
212 test_cmp expect actual
213 '
214
215 test_expect_success 'check label with more labels but excluded path' '
216 cat <<-\EOF >expect &&
217 fileAB
218 fileB
219 fileBC
220 EOF
221 git ls-files ":(attr:labelB)" ":(exclude)sub/" >actual &&
222 test_cmp expect actual
223 '
224
225 test_expect_success 'check label excluding other labels' '
226 cat <<-\EOF >expect &&
227 fileAB
228 fileB
229 fileBC
230 sub/fileAB
231 sub/fileB
232 EOF
233 git ls-files ":(attr:labelB)" ":(exclude,attr:labelC)sub/" >actual &&
234 test_cmp expect actual
235 '
236
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
240 '
241
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
247 # parsing.
248 test_must_fail git add ":(attr:labelB)" 2>actual &&
249 test_grep "magic not supported" actual
250 '
251
252 test_expect_success 'abort on giving invalid label on the command line' '
253 test_must_fail git ls-files . ":(attr:☺)"
254 '
255
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)"
259 '
260
261 test_expect_success 'check attribute list' '
262 cat <<-EOF >>.gitattributes &&
263 * whitespace=indent,trail,space
264 EOF
265 git ls-files ":(attr:whitespace=indent\,trail\,space)" >actual &&
266 git ls-files >expect &&
267 test_cmp expect actual
268 '
269
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
273 '
274
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
278 '
279
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
284 '
285
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
290 '
291
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
296 '
297
298 test_done