]>
Commit | Line | Data |
---|---|---|
cf94ccda JH |
1 | #!/bin/sh |
2 | ||
3 | test_description=gitattributes | |
4 | ||
c150064d | 5 | TEST_PASSES_SANITIZE_LEAK=true |
8da0b02d | 6 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
cf94ccda JH |
7 | . ./test-lib.sh |
8 | ||
2ef579e2 | 9 | attr_check_basic () { |
3738439c | 10 | path="$1" expect="$2" git_opts="$3" && |
cf94ccda | 11 | |
3738439c DL |
12 | git $git_opts check-attr test -- "$path" >actual 2>err && |
13 | echo "$path: test: $expect" >expect && | |
2ef579e2 JK |
14 | test_cmp expect actual |
15 | } | |
16 | ||
17 | attr_check () { | |
18 | attr_check_basic "$@" && | |
99c049bc | 19 | test_must_be_empty err |
cf94ccda JH |
20 | } |
21 | ||
860a74d9 | 22 | attr_check_quote () { |
3738439c | 23 | path="$1" quoted_path="$2" expect="$3" && |
860a74d9 NTND |
24 | |
25 | git check-attr test -- "$path" >actual && | |
26 | echo "\"$quoted_path\": test: $expect" >expect && | |
27 | test_cmp expect actual | |
28 | ||
29 | } | |
30 | ||
31 | test_expect_success 'open-quoted pathname' ' | |
32 | echo "\"a test=a" >.gitattributes && | |
f46c243e | 33 | attr_check a unspecified |
860a74d9 NTND |
34 | ' |
35 | ||
36 | ||
cf94ccda | 37 | test_expect_success 'setup' ' |
0216af83 | 38 | mkdir -p a/b/d a/c b && |
cf94ccda | 39 | ( |
75651fd7 ES |
40 | echo "[attr]notest !test" && |
41 | echo "\" d \" test=d" && | |
42 | echo " e test=e" && | |
43 | echo " e\" test=e" && | |
44 | echo "f test=f" && | |
45 | echo "a/i test=a/i" && | |
46 | echo "onoff test -test" && | |
47 | echo "offon -test test" && | |
48 | echo "no notest" && | |
6eba6210 | 49 | echo "A/e/F test=A/e/F" |
cf94ccda JH |
50 | ) >.gitattributes && |
51 | ( | |
52 | echo "g test=a/g" && | |
53 | echo "b/g test=a/b/g" | |
54 | ) >a/.gitattributes && | |
55 | ( | |
56 | echo "h test=a/b/h" && | |
75651fd7 | 57 | echo "d/* test=a/b/d/*" && |
ec775c41 | 58 | echo "d/yes notest" |
dcc04366 | 59 | ) >a/b/.gitattributes && |
6df42ab9 PO |
60 | ( |
61 | echo "global test=global" | |
c9d8f0ac | 62 | ) >"$HOME"/global-gitattributes && |
78cec757 JH |
63 | cat <<-EOF >expect-all |
64 | f: test: f | |
65 | a/f: test: f | |
66 | a/c/f: test: f | |
67 | a/g: test: a/g | |
68 | a/b/g: test: a/b/g | |
69 | b/g: test: unspecified | |
70 | a/b/h: test: a/b/h | |
71 | a/b/d/g: test: a/b/d/* | |
72 | onoff: test: unset | |
73 | offon: test: set | |
74 | no: notest: set | |
75 | no: test: unspecified | |
76 | a/b/d/no: notest: set | |
77 | a/b/d/no: test: a/b/d/* | |
78 | a/b/d/yes: notest: set | |
79 | a/b/d/yes: test: unspecified | |
80 | EOF | |
cf94ccda JH |
81 | ' |
82 | ||
c0b13b21 | 83 | test_expect_success 'command line checks' ' |
09d7dd7a MH |
84 | test_must_fail git check-attr && |
85 | test_must_fail git check-attr -- && | |
fdf6be82 MH |
86 | test_must_fail git check-attr test && |
87 | test_must_fail git check-attr test -- && | |
09d7dd7a MH |
88 | test_must_fail git check-attr -- f && |
89 | echo "f" | test_must_fail git check-attr --stdin && | |
90 | echo "f" | test_must_fail git check-attr --stdin -- f && | |
91 | echo "f" | test_must_fail git check-attr --stdin test -- f && | |
c0b13b21 | 92 | test_must_fail git check-attr "" -- f |
c0b13b21 MH |
93 | ' |
94 | ||
cf94ccda | 95 | test_expect_success 'attribute test' ' |
860a74d9 NTND |
96 | |
97 | attr_check " d " d && | |
98 | attr_check e e && | |
99 | attr_check_quote e\" e\\\" e && | |
100 | ||
cf94ccda JH |
101 | attr_check f f && |
102 | attr_check a/f f && | |
103 | attr_check a/c/f f && | |
104 | attr_check a/g a/g && | |
105 | attr_check a/b/g a/b/g && | |
106 | attr_check b/g unspecified && | |
107 | attr_check a/b/h a/b/h && | |
520ea857 MM |
108 | attr_check a/b/d/g "a/b/d/*" && |
109 | attr_check onoff unset && | |
110 | attr_check offon set && | |
111 | attr_check no unspecified && | |
112 | attr_check a/b/d/no "a/b/d/*" && | |
ec775c41 | 113 | attr_check a/b/d/yes unspecified |
cf94ccda JH |
114 | ' |
115 | ||
6eba6210 BC |
116 | test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' ' |
117 | ||
f46c243e DL |
118 | attr_check F unspecified "-c core.ignorecase=0" && |
119 | attr_check a/F unspecified "-c core.ignorecase=0" && | |
120 | attr_check a/c/F unspecified "-c core.ignorecase=0" && | |
121 | attr_check a/G unspecified "-c core.ignorecase=0" && | |
122 | attr_check a/B/g a/g "-c core.ignorecase=0" && | |
123 | attr_check a/b/G unspecified "-c core.ignorecase=0" && | |
124 | attr_check a/b/H unspecified "-c core.ignorecase=0" && | |
125 | attr_check a/b/D/g a/g "-c core.ignorecase=0" && | |
126 | attr_check oNoFf unspecified "-c core.ignorecase=0" && | |
127 | attr_check oFfOn unspecified "-c core.ignorecase=0" && | |
6eba6210 | 128 | attr_check NO unspecified "-c core.ignorecase=0" && |
f46c243e | 129 | attr_check a/b/D/NO unspecified "-c core.ignorecase=0" && |
6eba6210 | 130 | attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" && |
f46c243e | 131 | attr_check a/E/f f "-c core.ignorecase=0" |
6eba6210 BC |
132 | |
133 | ' | |
134 | ||
135 | test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' ' | |
136 | ||
137 | attr_check F f "-c core.ignorecase=1" && | |
138 | attr_check a/F f "-c core.ignorecase=1" && | |
139 | attr_check a/c/F f "-c core.ignorecase=1" && | |
140 | attr_check a/G a/g "-c core.ignorecase=1" && | |
141 | attr_check a/B/g a/b/g "-c core.ignorecase=1" && | |
142 | attr_check a/b/G a/b/g "-c core.ignorecase=1" && | |
143 | attr_check a/b/H a/b/h "-c core.ignorecase=1" && | |
144 | attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" && | |
145 | attr_check oNoFf unset "-c core.ignorecase=1" && | |
146 | attr_check oFfOn set "-c core.ignorecase=1" && | |
147 | attr_check NO unspecified "-c core.ignorecase=1" && | |
148 | attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" && | |
149 | attr_check a/b/d/YES unspecified "-c core.ignorecase=1" && | |
150 | attr_check a/E/f "A/e/F" "-c core.ignorecase=1" | |
151 | ||
152 | ' | |
153 | ||
6eba6210 | 154 | test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' |
f46c243e DL |
155 | attr_check a/B/D/g a/g "-c core.ignorecase=0" && |
156 | attr_check A/B/D/NO unspecified "-c core.ignorecase=0" && | |
6eba6210 BC |
157 | attr_check A/b/h a/b/h "-c core.ignorecase=1" && |
158 | attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" && | |
159 | attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1" | |
160 | ' | |
161 | ||
f5114a40 | 162 | test_expect_success 'unnormalized paths' ' |
d4d4f8df MH |
163 | attr_check ./f f && |
164 | attr_check ./a/g a/g && | |
165 | attr_check a/./g a/g && | |
166 | attr_check a/c/../b/g a/b/g | |
d4d4f8df MH |
167 | ' |
168 | ||
f5114a40 | 169 | test_expect_success 'relative paths' ' |
0216af83 MH |
170 | (cd a && attr_check ../f f) && |
171 | (cd a && attr_check f f) && | |
172 | (cd a && attr_check i a/i) && | |
173 | (cd a && attr_check g a/g) && | |
174 | (cd a && attr_check b/g a/b/g) && | |
175 | (cd b && attr_check ../a/f f) && | |
176 | (cd b && attr_check ../a/g a/g) && | |
177 | (cd b && attr_check ../a/b/g a/b/g) | |
0216af83 MH |
178 | ' |
179 | ||
1afca444 JK |
180 | test_expect_success 'prefixes are not confused with leading directories' ' |
181 | attr_check a_plus/g unspecified && | |
182 | cat >expect <<-\EOF && | |
183 | a/g: test: a/g | |
184 | a_plus/g: test: unspecified | |
185 | EOF | |
186 | git check-attr test a/g a_plus/g >actual && | |
187 | test_cmp expect actual | |
188 | ' | |
189 | ||
6df42ab9 PO |
190 | test_expect_success 'core.attributesfile' ' |
191 | attr_check global unspecified && | |
192 | git config core.attributesfile "$HOME/global-gitattributes" && | |
193 | attr_check global global && | |
194 | git config core.attributesfile "~/global-gitattributes" && | |
195 | attr_check global global && | |
78cec757 | 196 | echo "global test=precedence" >>.gitattributes && |
6df42ab9 PO |
197 | attr_check global precedence |
198 | ' | |
199 | ||
b4666852 | 200 | test_expect_success 'attribute test: read paths from stdin' ' |
78cec757 JH |
201 | grep -v notest <expect-all >expect && |
202 | sed -e "s/:.*//" <expect | git check-attr --stdin test >actual && | |
b4666852 DP |
203 | test_cmp expect actual |
204 | ' | |
205 | ||
4ca0f188 | 206 | test_expect_success 'attribute test: --all option' ' |
b2b3e9c2 JS |
207 | grep -v unspecified <expect-all | sort >specified-all && |
208 | sed -e "s/:.*//" <expect-all | uniq >stdin-all && | |
ae5d569b SM |
209 | git check-attr --stdin --all <stdin-all >tmp && |
210 | sort tmp >actual && | |
b2b3e9c2 JS |
211 | test_cmp specified-all actual |
212 | ' | |
213 | ||
214 | test_expect_success 'attribute test: --cached option' ' | |
ae5d569b SM |
215 | git check-attr --cached --stdin --all <stdin-all >tmp && |
216 | sort tmp >actual && | |
1c5e94f4 | 217 | test_must_be_empty actual && |
b2b3e9c2 | 218 | git add .gitattributes a/.gitattributes a/b/.gitattributes && |
ae5d569b SM |
219 | git check-attr --cached --stdin --all <stdin-all >tmp && |
220 | sort tmp >actual && | |
b2b3e9c2 | 221 | test_cmp specified-all actual |
4ca0f188 MH |
222 | ' |
223 | ||
82881b38 | 224 | test_expect_success 'root subdir attribute test' ' |
82881b38 MO |
225 | attr_check a/i a/i && |
226 | attr_check subdir/a/i unspecified | |
82881b38 MO |
227 | ' |
228 | ||
82dce998 NTND |
229 | test_expect_success 'negative patterns' ' |
230 | echo "!f test=bar" >.gitattributes && | |
8b1bd024 TR |
231 | git check-attr test -- '"'"'!f'"'"' 2>errors && |
232 | test_i18ngrep "Negative patterns are ignored" errors | |
82dce998 NTND |
233 | ' |
234 | ||
235 | test_expect_success 'patterns starting with exclamation' ' | |
236 | echo "\!f test=foo" >.gitattributes && | |
237 | attr_check "!f" foo | |
238 | ' | |
239 | ||
237ec6e4 NTND |
240 | test_expect_success '"**" test' ' |
241 | echo "**/f foo=bar" >.gitattributes && | |
242 | cat <<\EOF >expect && | |
243 | f: foo: bar | |
244 | a/f: foo: bar | |
245 | a/b/f: foo: bar | |
246 | a/b/c/f: foo: bar | |
247 | EOF | |
248 | git check-attr foo -- "f" >actual 2>err && | |
249 | git check-attr foo -- "a/f" >>actual 2>>err && | |
250 | git check-attr foo -- "a/b/f" >>actual 2>>err && | |
251 | git check-attr foo -- "a/b/c/f" >>actual 2>>err && | |
252 | test_cmp expect actual && | |
99c049bc | 253 | test_must_be_empty err |
237ec6e4 NTND |
254 | ' |
255 | ||
256 | test_expect_success '"**" with no slashes test' ' | |
257 | echo "a**f foo=bar" >.gitattributes && | |
258 | git check-attr foo -- "f" >actual && | |
259 | cat <<\EOF >expect && | |
260 | f: foo: unspecified | |
261 | af: foo: bar | |
262 | axf: foo: bar | |
263 | a/f: foo: unspecified | |
264 | a/b/f: foo: unspecified | |
265 | a/b/c/f: foo: unspecified | |
266 | EOF | |
267 | git check-attr foo -- "f" >actual 2>err && | |
268 | git check-attr foo -- "af" >>actual 2>err && | |
269 | git check-attr foo -- "axf" >>actual 2>err && | |
270 | git check-attr foo -- "a/f" >>actual 2>>err && | |
271 | git check-attr foo -- "a/b/f" >>actual 2>>err && | |
272 | git check-attr foo -- "a/b/c/f" >>actual 2>>err && | |
273 | test_cmp expect actual && | |
99c049bc | 274 | test_must_be_empty err |
237ec6e4 NTND |
275 | ' |
276 | ||
cdbf6232 JH |
277 | test_expect_success 'using --git-dir and --work-tree' ' |
278 | mkdir unreal real && | |
279 | git init real && | |
280 | echo "file test=in-real" >real/.gitattributes && | |
281 | ( | |
282 | cd unreal && | |
283 | attr_check file in-real "--git-dir ../real/.git --work-tree ../real" | |
284 | ) | |
285 | ' | |
286 | ||
2d35d556 | 287 | test_expect_success 'setup bare' ' |
8da0b02d | 288 | git clone --template= --bare . bare.git |
2d35d556 RS |
289 | ' |
290 | ||
291 | test_expect_success 'bare repository: check that .gitattribute is ignored' ' | |
2d35d556 | 292 | ( |
c4a7bce1 JH |
293 | cd bare.git && |
294 | ( | |
75651fd7 | 295 | echo "f test=f" && |
c4a7bce1 JH |
296 | echo "a/i test=a/i" |
297 | ) >.gitattributes && | |
298 | attr_check f unspecified && | |
299 | attr_check a/f unspecified && | |
300 | attr_check a/c/f unspecified && | |
301 | attr_check a/i unspecified && | |
302 | attr_check subdir/a/i unspecified | |
303 | ) | |
2d35d556 RS |
304 | ' |
305 | ||
b2b3e9c2 | 306 | test_expect_success 'bare repository: check that --cached honors index' ' |
c4a7bce1 JH |
307 | ( |
308 | cd bare.git && | |
309 | GIT_INDEX_FILE=../.git/index \ | |
310 | git check-attr --cached --stdin --all <../stdin-all | | |
311 | sort >actual && | |
312 | test_cmp ../specified-all actual | |
313 | ) | |
b2b3e9c2 JS |
314 | ' |
315 | ||
2d35d556 | 316 | test_expect_success 'bare repository: test info/attributes' ' |
2d35d556 | 317 | ( |
c4a7bce1 | 318 | cd bare.git && |
8da0b02d | 319 | mkdir info && |
c4a7bce1 | 320 | ( |
75651fd7 | 321 | echo "f test=f" && |
c4a7bce1 JH |
322 | echo "a/i test=a/i" |
323 | ) >info/attributes && | |
324 | attr_check f f && | |
325 | attr_check a/f f && | |
326 | attr_check a/c/f f && | |
327 | attr_check a/i a/i && | |
328 | attr_check subdir/a/i unspecified | |
329 | ) | |
2d35d556 RS |
330 | ' |
331 | ||
7b95849b JK |
332 | test_expect_success 'binary macro expanded by -a' ' |
333 | echo "file binary" >.gitattributes && | |
334 | cat >expect <<-\EOF && | |
335 | file: binary: set | |
336 | file: diff: unset | |
337 | file: merge: unset | |
338 | file: text: unset | |
339 | EOF | |
340 | git check-attr -a file >actual && | |
341 | test_cmp expect actual | |
342 | ' | |
343 | ||
7b95849b JK |
344 | test_expect_success 'query binary macro directly' ' |
345 | echo "file binary" >.gitattributes && | |
346 | echo file: binary: set >expect && | |
347 | git check-attr binary file >actual && | |
348 | test_cmp expect actual | |
349 | ' | |
350 | ||
2ef579e2 JK |
351 | test_expect_success SYMLINKS 'set up symlink tests' ' |
352 | echo "* test" >attr && | |
353 | rm -f .gitattributes | |
354 | ' | |
355 | ||
356 | test_expect_success SYMLINKS 'symlinks respected in core.attributesFile' ' | |
357 | test_when_finished "rm symlink" && | |
358 | ln -s attr symlink && | |
359 | test_config core.attributesFile "$(pwd)/symlink" && | |
360 | attr_check file set | |
361 | ' | |
362 | ||
363 | test_expect_success SYMLINKS 'symlinks respected in info/attributes' ' | |
364 | test_when_finished "rm .git/info/attributes" && | |
8da0b02d | 365 | mkdir .git/info && |
2ef579e2 JK |
366 | ln -s ../../attr .git/info/attributes && |
367 | attr_check file set | |
368 | ' | |
369 | ||
370 | test_expect_success SYMLINKS 'symlinks not respected in-tree' ' | |
371 | test_when_finished "rm -rf .gitattributes subdir" && | |
372 | ln -s attr .gitattributes && | |
373 | mkdir subdir && | |
374 | ln -s ../attr subdir/.gitattributes && | |
375 | attr_check_basic subdir/file unspecified && | |
376 | test_i18ngrep "unable to access.*gitattributes" err | |
377 | ' | |
378 | ||
dfa6b32b PS |
379 | test_expect_success 'large attributes line ignored in tree' ' |
380 | test_when_finished "rm .gitattributes" && | |
381 | printf "path %02043d" 1 >.gitattributes && | |
382 | git check-attr --all path >actual 2>err && | |
383 | echo "warning: ignoring overly long attributes line 1" >expect && | |
384 | test_cmp expect err && | |
385 | test_must_be_empty actual | |
386 | ' | |
387 | ||
d74b1fd5 PS |
388 | test_expect_success 'large attributes line ignores trailing content in tree' ' |
389 | test_when_finished "rm .gitattributes" && | |
390 | # older versions of Git broke lines at 2048 bytes; the 2045 bytes | |
391 | # of 0-padding here is accounting for the three bytes of "a 1", which | |
392 | # would knock "trailing" to the "next" line, where it would be | |
393 | # erroneously parsed. | |
394 | printf "a %02045dtrailing attribute\n" 1 >.gitattributes && | |
395 | git check-attr --all trailing >actual 2>err && | |
dfa6b32b PS |
396 | echo "warning: ignoring overly long attributes line 1" >expect && |
397 | test_cmp expect err && | |
398 | test_must_be_empty actual | |
399 | ' | |
400 | ||
3c50032f PS |
401 | test_expect_success EXPENSIVE 'large attributes file ignored in tree' ' |
402 | test_when_finished "rm .gitattributes" && | |
403 | dd if=/dev/zero of=.gitattributes bs=101M count=1 2>/dev/null && | |
404 | git check-attr --all path >/dev/null 2>err && | |
405 | echo "warning: ignoring overly large gitattributes file ${SQ}.gitattributes${SQ}" >expect && | |
406 | test_cmp expect err | |
407 | ' | |
408 | ||
dfa6b32b PS |
409 | test_expect_success 'large attributes line ignored in index' ' |
410 | test_when_finished "git update-index --remove .gitattributes" && | |
411 | blob=$(printf "path %02043d" 1 | git hash-object -w --stdin) && | |
412 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && | |
413 | git check-attr --cached --all path >actual 2>err && | |
414 | echo "warning: ignoring overly long attributes line 1" >expect && | |
415 | test_cmp expect err && | |
d74b1fd5 PS |
416 | test_must_be_empty actual |
417 | ' | |
418 | ||
419 | test_expect_success 'large attributes line ignores trailing content in index' ' | |
420 | test_when_finished "git update-index --remove .gitattributes" && | |
421 | blob=$(printf "a %02045dtrailing attribute\n" 1 | git hash-object -w --stdin) && | |
422 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && | |
423 | git check-attr --cached --all trailing >actual 2>err && | |
dfa6b32b PS |
424 | echo "warning: ignoring overly long attributes line 1" >expect && |
425 | test_cmp expect err && | |
d74b1fd5 PS |
426 | test_must_be_empty actual |
427 | ' | |
428 | ||
3c50032f PS |
429 | test_expect_success EXPENSIVE 'large attributes file ignored in index' ' |
430 | test_when_finished "git update-index --remove .gitattributes" && | |
431 | blob=$(dd if=/dev/zero bs=101M count=1 2>/dev/null | git hash-object -w --stdin) && | |
432 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && | |
433 | git check-attr --cached --all path >/dev/null 2>err && | |
434 | echo "warning: ignoring overly large gitattributes blob ${SQ}.gitattributes${SQ}" >expect && | |
435 | test_cmp expect err | |
436 | ' | |
437 | ||
cf94ccda | 438 | test_done |