]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6135-pathspec-with-attrs.sh
Merge branch 'jc/bisect-doc' into maint-2.43
[thirdparty/git.git] / t / t6135-pathspec-with-attrs.sh
CommitLineData
b0db7046
BW
1#!/bin/sh
2
3test_description='test labels in pathspecs'
4. ./test-lib.sh
5
6test_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
5a0b97b3 34 echo content >$path &&
b0db7046
BW
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
42test_expect_success 'pathspec with no attr' '
43 test_must_fail git ls-files ":(attr:)"
44'
45
46test_expect_success 'pathspec with labels and non existent .gitattributes' '
47 git ls-files ":(attr:label)" >actual &&
48 test_must_be_empty actual
49'
50
5a0b97b3
NTND
51test_expect_success 'pathspec with labels and non existent .gitattributes (2)' '
52 test_must_fail git grep content HEAD -- ":(attr:label)"
53'
54
b0db7046
BW
55test_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
f4a8fde0
JH
68 echo fileSetLabel label1 >sub/.gitattributes &&
69 git add .gitattributes sub/.gitattributes &&
b0db7046
BW
70 git commit -m "add attributes"
71'
72
73test_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
7e360bc6
JH
82test_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
92test_expect_success 'check specific set attr in tree-ish' '
5a0b97b3
NTND
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
7e360bc6
JH
101test_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
b0db7046
BW
111test_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
5a0b97b3
NTND
120test_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
b0db7046
BW
129test_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
5a0b97b3
NTND
140test_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
b0db7046
BW
150test_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
f4a8fde0 161 sub/.gitattributes
b0db7046
BW
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
5a0b97b3
NTND
175test_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
f4a8fde0 186 HEAD:sub/.gitattributes
5a0b97b3
NTND
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
b0db7046
BW
200test_expect_success 'check multiple unspecified attr' '
201 cat <<-\EOF >expect &&
202 .gitattributes
203 fileC
204 fileNoLabel
205 fileWrongLabel
f4a8fde0 206 sub/.gitattributes
b0db7046
BW
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
215test_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
225test_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
237test_expect_success 'fail on multiple attr specifiers in one pathspec item' '
238 test_must_fail git ls-files . ":(attr:labelB,attr:labelC)" 2>actual &&
6789275d 239 test_grep "Only one" actual
b0db7046
BW
240'
241
242test_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 &&
6789275d 249 test_grep "magic not supported" actual
b0db7046
BW
250'
251
252test_expect_success 'abort on giving invalid label on the command line' '
253 test_must_fail git ls-files . ":(attr:☺)"
254'
255
256test_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
c5af19f9
BW
261test_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
270test_expect_success 'backslash cannot be the last character' '
271 test_must_fail git ls-files ":(attr:label=foo\\ labelA=bar)" 2>actual &&
6789275d 272 test_grep "not allowed as last character in attr value" actual
c5af19f9
BW
273'
274
275test_expect_success 'backslash cannot be used as a value' '
276 test_must_fail git ls-files ":(attr:label=f\\\oo)" 2>actual &&
6789275d 277 test_grep "for value matching" actual
c5af19f9
BW
278'
279
f4a8fde0
JH
280test_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
286test_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
292test_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
b0db7046 298test_done