]>
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 | ||
2232a88a JW |
22 | attr_check_object_mode_basic () { |
23 | path="$1" && | |
24 | expect="$2" && | |
25 | check_opts="$3" && | |
26 | git check-attr $check_opts builtin_objectmode -- "$path" >actual 2>err && | |
27 | echo "$path: builtin_objectmode: $expect" >expect && | |
28 | test_cmp expect actual | |
29 | } | |
30 | ||
31 | attr_check_object_mode () { | |
32 | attr_check_object_mode_basic "$@" && | |
33 | test_must_be_empty err | |
34 | } | |
35 | ||
860a74d9 | 36 | attr_check_quote () { |
3738439c | 37 | path="$1" quoted_path="$2" expect="$3" && |
860a74d9 NTND |
38 | |
39 | git check-attr test -- "$path" >actual && | |
40 | echo "\"$quoted_path\": test: $expect" >expect && | |
41 | test_cmp expect actual | |
47cfc9bd KN |
42 | } |
43 | ||
44 | attr_check_source () { | |
45 | path="$1" expect="$2" source="$3" git_opts="$4" && | |
860a74d9 | 46 | |
47cfc9bd | 47 | echo "$path: test: $expect" >expect && |
44451a2e JC |
48 | |
49 | git $git_opts check-attr --source $source test -- "$path" >actual 2>err && | |
50 | test_cmp expect actual && | |
51 | test_must_be_empty err && | |
52 | ||
53 | git $git_opts --attr-source="$source" check-attr test -- "$path" >actual 2>err && | |
54 | test_cmp expect actual && | |
55 | test_must_be_empty err | |
56 | ||
9f9c40cf JC |
57 | git $git_opts -c "attr.tree=$source" check-attr test -- "$path" >actual 2>err && |
58 | test_cmp expect actual && | |
59 | test_must_be_empty err | |
60 | ||
44451a2e | 61 | GIT_ATTR_SOURCE="$source" git $git_opts check-attr test -- "$path" >actual 2>err && |
47cfc9bd KN |
62 | test_cmp expect actual && |
63 | test_must_be_empty err | |
860a74d9 NTND |
64 | } |
65 | ||
66 | test_expect_success 'open-quoted pathname' ' | |
67 | echo "\"a test=a" >.gitattributes && | |
f46c243e | 68 | attr_check a unspecified |
860a74d9 NTND |
69 | ' |
70 | ||
cf94ccda | 71 | test_expect_success 'setup' ' |
0216af83 | 72 | mkdir -p a/b/d a/c b && |
cf94ccda | 73 | ( |
75651fd7 ES |
74 | echo "[attr]notest !test" && |
75 | echo "\" d \" test=d" && | |
76 | echo " e test=e" && | |
77 | echo " e\" test=e" && | |
78 | echo "f test=f" && | |
79 | echo "a/i test=a/i" && | |
80 | echo "onoff test -test" && | |
81 | echo "offon -test test" && | |
82 | echo "no notest" && | |
6eba6210 | 83 | echo "A/e/F test=A/e/F" |
cf94ccda JH |
84 | ) >.gitattributes && |
85 | ( | |
86 | echo "g test=a/g" && | |
87 | echo "b/g test=a/b/g" | |
88 | ) >a/.gitattributes && | |
89 | ( | |
90 | echo "h test=a/b/h" && | |
75651fd7 | 91 | echo "d/* test=a/b/d/*" && |
ec775c41 | 92 | echo "d/yes notest" |
dcc04366 | 93 | ) >a/b/.gitattributes && |
6df42ab9 PO |
94 | ( |
95 | echo "global test=global" | |
c9d8f0ac | 96 | ) >"$HOME"/global-gitattributes && |
78cec757 JH |
97 | cat <<-EOF >expect-all |
98 | f: test: f | |
99 | a/f: test: f | |
100 | a/c/f: test: f | |
101 | a/g: test: a/g | |
102 | a/b/g: test: a/b/g | |
103 | b/g: test: unspecified | |
104 | a/b/h: test: a/b/h | |
105 | a/b/d/g: test: a/b/d/* | |
106 | onoff: test: unset | |
107 | offon: test: set | |
108 | no: notest: set | |
109 | no: test: unspecified | |
110 | a/b/d/no: notest: set | |
111 | a/b/d/no: test: a/b/d/* | |
112 | a/b/d/yes: notest: set | |
113 | a/b/d/yes: test: unspecified | |
114 | EOF | |
cf94ccda JH |
115 | ' |
116 | ||
47cfc9bd KN |
117 | test_expect_success 'setup branches' ' |
118 | mkdir -p foo/bar && | |
119 | test_commit --printf "add .gitattributes" foo/bar/.gitattributes \ | |
120 | "f test=f\na/i test=n\n" tag-1 && | |
121 | test_commit --printf "add .gitattributes" foo/bar/.gitattributes \ | |
122 | "g test=g\na/i test=m\n" tag-2 && | |
123 | rm foo/bar/.gitattributes | |
124 | ' | |
125 | ||
c0b13b21 | 126 | test_expect_success 'command line checks' ' |
09d7dd7a MH |
127 | test_must_fail git check-attr && |
128 | test_must_fail git check-attr -- && | |
fdf6be82 MH |
129 | test_must_fail git check-attr test && |
130 | test_must_fail git check-attr test -- && | |
09d7dd7a | 131 | test_must_fail git check-attr -- f && |
47cfc9bd KN |
132 | test_must_fail git check-attr --source && |
133 | test_must_fail git check-attr --source not-a-valid-ref && | |
09d7dd7a MH |
134 | echo "f" | test_must_fail git check-attr --stdin && |
135 | echo "f" | test_must_fail git check-attr --stdin -- f && | |
136 | echo "f" | test_must_fail git check-attr --stdin test -- f && | |
c0b13b21 | 137 | test_must_fail git check-attr "" -- f |
c0b13b21 MH |
138 | ' |
139 | ||
cf94ccda | 140 | test_expect_success 'attribute test' ' |
860a74d9 NTND |
141 | |
142 | attr_check " d " d && | |
143 | attr_check e e && | |
144 | attr_check_quote e\" e\\\" e && | |
145 | ||
cf94ccda JH |
146 | attr_check f f && |
147 | attr_check a/f f && | |
148 | attr_check a/c/f f && | |
149 | attr_check a/g a/g && | |
150 | attr_check a/b/g a/b/g && | |
151 | attr_check b/g unspecified && | |
152 | attr_check a/b/h a/b/h && | |
520ea857 MM |
153 | attr_check a/b/d/g "a/b/d/*" && |
154 | attr_check onoff unset && | |
155 | attr_check offon set && | |
156 | attr_check no unspecified && | |
157 | attr_check a/b/d/no "a/b/d/*" && | |
ec775c41 | 158 | attr_check a/b/d/yes unspecified |
cf94ccda JH |
159 | ' |
160 | ||
6eba6210 BC |
161 | test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' ' |
162 | ||
f46c243e DL |
163 | attr_check F unspecified "-c core.ignorecase=0" && |
164 | attr_check a/F unspecified "-c core.ignorecase=0" && | |
165 | attr_check a/c/F unspecified "-c core.ignorecase=0" && | |
166 | attr_check a/G unspecified "-c core.ignorecase=0" && | |
167 | attr_check a/B/g a/g "-c core.ignorecase=0" && | |
168 | attr_check a/b/G unspecified "-c core.ignorecase=0" && | |
169 | attr_check a/b/H unspecified "-c core.ignorecase=0" && | |
170 | attr_check a/b/D/g a/g "-c core.ignorecase=0" && | |
171 | attr_check oNoFf unspecified "-c core.ignorecase=0" && | |
172 | attr_check oFfOn unspecified "-c core.ignorecase=0" && | |
6eba6210 | 173 | attr_check NO unspecified "-c core.ignorecase=0" && |
f46c243e | 174 | attr_check a/b/D/NO unspecified "-c core.ignorecase=0" && |
6eba6210 | 175 | attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" && |
f46c243e | 176 | attr_check a/E/f f "-c core.ignorecase=0" |
6eba6210 BC |
177 | |
178 | ' | |
179 | ||
180 | test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' ' | |
181 | ||
182 | attr_check F f "-c core.ignorecase=1" && | |
183 | attr_check a/F f "-c core.ignorecase=1" && | |
184 | attr_check a/c/F f "-c core.ignorecase=1" && | |
185 | attr_check a/G a/g "-c core.ignorecase=1" && | |
186 | attr_check a/B/g a/b/g "-c core.ignorecase=1" && | |
187 | attr_check a/b/G a/b/g "-c core.ignorecase=1" && | |
188 | attr_check a/b/H a/b/h "-c core.ignorecase=1" && | |
189 | attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" && | |
190 | attr_check oNoFf unset "-c core.ignorecase=1" && | |
191 | attr_check oFfOn set "-c core.ignorecase=1" && | |
192 | attr_check NO unspecified "-c core.ignorecase=1" && | |
193 | attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" && | |
194 | attr_check a/b/d/YES unspecified "-c core.ignorecase=1" && | |
195 | attr_check a/E/f "A/e/F" "-c core.ignorecase=1" | |
196 | ||
197 | ' | |
198 | ||
6eba6210 | 199 | test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' |
f46c243e DL |
200 | attr_check a/B/D/g a/g "-c core.ignorecase=0" && |
201 | attr_check A/B/D/NO unspecified "-c core.ignorecase=0" && | |
6eba6210 BC |
202 | attr_check A/b/h a/b/h "-c core.ignorecase=1" && |
203 | attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" && | |
204 | attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1" | |
205 | ' | |
206 | ||
f5114a40 | 207 | test_expect_success 'unnormalized paths' ' |
d4d4f8df MH |
208 | attr_check ./f f && |
209 | attr_check ./a/g a/g && | |
210 | attr_check a/./g a/g && | |
211 | attr_check a/c/../b/g a/b/g | |
d4d4f8df MH |
212 | ' |
213 | ||
f5114a40 | 214 | test_expect_success 'relative paths' ' |
0216af83 MH |
215 | (cd a && attr_check ../f f) && |
216 | (cd a && attr_check f f) && | |
217 | (cd a && attr_check i a/i) && | |
218 | (cd a && attr_check g a/g) && | |
219 | (cd a && attr_check b/g a/b/g) && | |
220 | (cd b && attr_check ../a/f f) && | |
221 | (cd b && attr_check ../a/g a/g) && | |
222 | (cd b && attr_check ../a/b/g a/b/g) | |
0216af83 MH |
223 | ' |
224 | ||
1afca444 JK |
225 | test_expect_success 'prefixes are not confused with leading directories' ' |
226 | attr_check a_plus/g unspecified && | |
227 | cat >expect <<-\EOF && | |
228 | a/g: test: a/g | |
229 | a_plus/g: test: unspecified | |
230 | EOF | |
231 | git check-attr test a/g a_plus/g >actual && | |
232 | test_cmp expect actual | |
233 | ' | |
234 | ||
6df42ab9 PO |
235 | test_expect_success 'core.attributesfile' ' |
236 | attr_check global unspecified && | |
237 | git config core.attributesfile "$HOME/global-gitattributes" && | |
238 | attr_check global global && | |
239 | git config core.attributesfile "~/global-gitattributes" && | |
240 | attr_check global global && | |
78cec757 | 241 | echo "global test=precedence" >>.gitattributes && |
6df42ab9 PO |
242 | attr_check global precedence |
243 | ' | |
244 | ||
b4666852 | 245 | test_expect_success 'attribute test: read paths from stdin' ' |
78cec757 JH |
246 | grep -v notest <expect-all >expect && |
247 | sed -e "s/:.*//" <expect | git check-attr --stdin test >actual && | |
b4666852 DP |
248 | test_cmp expect actual |
249 | ' | |
250 | ||
c847e8c2 | 251 | test_expect_success 'setup --all option' ' |
b2b3e9c2 | 252 | grep -v unspecified <expect-all | sort >specified-all && |
c847e8c2 KN |
253 | sed -e "s/:.*//" <expect-all | uniq >stdin-all |
254 | ' | |
255 | ||
256 | test_expect_success 'attribute test: --all option' ' | |
ae5d569b SM |
257 | git check-attr --stdin --all <stdin-all >tmp && |
258 | sort tmp >actual && | |
b2b3e9c2 JS |
259 | test_cmp specified-all actual |
260 | ' | |
261 | ||
262 | test_expect_success 'attribute test: --cached option' ' | |
ae5d569b SM |
263 | git check-attr --cached --stdin --all <stdin-all >tmp && |
264 | sort tmp >actual && | |
1c5e94f4 | 265 | test_must_be_empty actual && |
b2b3e9c2 | 266 | git add .gitattributes a/.gitattributes a/b/.gitattributes && |
ae5d569b SM |
267 | git check-attr --cached --stdin --all <stdin-all >tmp && |
268 | sort tmp >actual && | |
b2b3e9c2 | 269 | test_cmp specified-all actual |
4ca0f188 MH |
270 | ' |
271 | ||
82881b38 | 272 | test_expect_success 'root subdir attribute test' ' |
82881b38 MO |
273 | attr_check a/i a/i && |
274 | attr_check subdir/a/i unspecified | |
82881b38 MO |
275 | ' |
276 | ||
82dce998 NTND |
277 | test_expect_success 'negative patterns' ' |
278 | echo "!f test=bar" >.gitattributes && | |
8b1bd024 | 279 | git check-attr test -- '"'"'!f'"'"' 2>errors && |
6789275d | 280 | test_grep "Negative patterns are ignored" errors |
82dce998 NTND |
281 | ' |
282 | ||
283 | test_expect_success 'patterns starting with exclamation' ' | |
284 | echo "\!f test=foo" >.gitattributes && | |
285 | attr_check "!f" foo | |
286 | ' | |
287 | ||
237ec6e4 NTND |
288 | test_expect_success '"**" test' ' |
289 | echo "**/f foo=bar" >.gitattributes && | |
290 | cat <<\EOF >expect && | |
291 | f: foo: bar | |
292 | a/f: foo: bar | |
293 | a/b/f: foo: bar | |
294 | a/b/c/f: foo: bar | |
295 | EOF | |
296 | git check-attr foo -- "f" >actual 2>err && | |
297 | git check-attr foo -- "a/f" >>actual 2>>err && | |
298 | git check-attr foo -- "a/b/f" >>actual 2>>err && | |
299 | git check-attr foo -- "a/b/c/f" >>actual 2>>err && | |
300 | test_cmp expect actual && | |
99c049bc | 301 | test_must_be_empty err |
237ec6e4 NTND |
302 | ' |
303 | ||
304 | test_expect_success '"**" with no slashes test' ' | |
305 | echo "a**f foo=bar" >.gitattributes && | |
306 | git check-attr foo -- "f" >actual && | |
307 | cat <<\EOF >expect && | |
308 | f: foo: unspecified | |
309 | af: foo: bar | |
310 | axf: foo: bar | |
311 | a/f: foo: unspecified | |
312 | a/b/f: foo: unspecified | |
313 | a/b/c/f: foo: unspecified | |
314 | EOF | |
315 | git check-attr foo -- "f" >actual 2>err && | |
316 | git check-attr foo -- "af" >>actual 2>err && | |
317 | git check-attr foo -- "axf" >>actual 2>err && | |
318 | git check-attr foo -- "a/f" >>actual 2>>err && | |
319 | git check-attr foo -- "a/b/f" >>actual 2>>err && | |
320 | git check-attr foo -- "a/b/c/f" >>actual 2>>err && | |
321 | test_cmp expect actual && | |
99c049bc | 322 | test_must_be_empty err |
237ec6e4 NTND |
323 | ' |
324 | ||
cdbf6232 JH |
325 | test_expect_success 'using --git-dir and --work-tree' ' |
326 | mkdir unreal real && | |
327 | git init real && | |
328 | echo "file test=in-real" >real/.gitattributes && | |
329 | ( | |
330 | cd unreal && | |
331 | attr_check file in-real "--git-dir ../real/.git --work-tree ../real" | |
332 | ) | |
333 | ' | |
334 | ||
47cfc9bd KN |
335 | test_expect_success 'using --source' ' |
336 | attr_check_source foo/bar/f f tag-1 && | |
337 | attr_check_source foo/bar/a/i n tag-1 && | |
338 | attr_check_source foo/bar/f unspecified tag-2 && | |
339 | attr_check_source foo/bar/a/i m tag-2 && | |
340 | attr_check_source foo/bar/g g tag-2 && | |
341 | attr_check_source foo/bar/g unspecified tag-1 | |
342 | ' | |
343 | ||
2d35d556 | 344 | test_expect_success 'setup bare' ' |
8da0b02d | 345 | git clone --template= --bare . bare.git |
2d35d556 RS |
346 | ' |
347 | ||
348 | test_expect_success 'bare repository: check that .gitattribute is ignored' ' | |
2d35d556 | 349 | ( |
c4a7bce1 JH |
350 | cd bare.git && |
351 | ( | |
75651fd7 | 352 | echo "f test=f" && |
c4a7bce1 JH |
353 | echo "a/i test=a/i" |
354 | ) >.gitattributes && | |
355 | attr_check f unspecified && | |
356 | attr_check a/f unspecified && | |
357 | attr_check a/c/f unspecified && | |
358 | attr_check a/i unspecified && | |
359 | attr_check subdir/a/i unspecified | |
360 | ) | |
2d35d556 RS |
361 | ' |
362 | ||
9f9c40cf JC |
363 | bad_attr_source_err="fatal: bad --attr-source or GIT_ATTR_SOURCE" |
364 | ||
365 | test_expect_success '--attr-source is bad' ' | |
366 | test_when_finished rm -rf empty && | |
367 | git init empty && | |
368 | ( | |
369 | cd empty && | |
370 | echo "$bad_attr_source_err" >expect_err && | |
371 | test_must_fail git --attr-source=HEAD check-attr test -- f/path 2>err && | |
372 | test_cmp expect_err err | |
373 | ) | |
374 | ' | |
375 | ||
376 | test_expect_success 'attr.tree when HEAD is unborn' ' | |
377 | test_when_finished rm -rf empty && | |
378 | git init empty && | |
379 | ( | |
380 | cd empty && | |
381 | echo "f/path: test: unspecified" >expect && | |
382 | git -c attr.tree=HEAD check-attr test -- f/path >actual 2>err && | |
383 | test_must_be_empty err && | |
384 | test_cmp expect actual | |
385 | ) | |
386 | ' | |
387 | ||
388 | test_expect_success 'bad attr source defaults to reading .gitattributes file' ' | |
389 | test_when_finished rm -rf empty && | |
390 | git init empty && | |
391 | ( | |
392 | cd empty && | |
393 | echo "f/path test=val" >.gitattributes && | |
394 | echo "f/path: test: val" >expect && | |
395 | git -c attr.tree=HEAD check-attr test -- f/path >actual 2>err && | |
396 | test_must_be_empty err && | |
397 | test_cmp expect actual | |
398 | ) | |
399 | ' | |
23865355 | 400 | |
51441e64 | 401 | test_expect_success 'bare repo no longer defaults to reading .gitattributes from HEAD' ' |
23865355 JC |
402 | test_when_finished rm -rf test bare_with_gitattribute && |
403 | git init test && | |
404 | test_commit -C test gitattributes .gitattributes "f/path test=val" && | |
405 | git clone --bare test bare_with_gitattribute && | |
51441e64 JH |
406 | |
407 | echo "f/path: test: unspecified" >expect && | |
23865355 | 408 | git -C bare_with_gitattribute check-attr test -- f/path >actual && |
51441e64 JH |
409 | test_cmp expect actual && |
410 | ||
411 | echo "f/path: test: val" >expect && | |
412 | git -C bare_with_gitattribute -c attr.tree=HEAD \ | |
413 | check-attr test -- f/path >actual && | |
23865355 JC |
414 | test_cmp expect actual |
415 | ' | |
416 | ||
9f9c40cf JC |
417 | test_expect_success 'precedence of --attr-source, GIT_ATTR_SOURCE, then attr.tree' ' |
418 | test_when_finished rm -rf empty && | |
419 | git init empty && | |
420 | ( | |
421 | cd empty && | |
422 | git checkout -b attr-source && | |
423 | test_commit "val1" .gitattributes "f/path test=val1" && | |
424 | git checkout -b attr-tree && | |
425 | test_commit "val2" .gitattributes "f/path test=val2" && | |
426 | git checkout attr-source && | |
427 | echo "f/path: test: val1" >expect && | |
428 | GIT_ATTR_SOURCE=attr-source git -c attr.tree=attr-tree --attr-source=attr-source \ | |
429 | check-attr test -- f/path >actual && | |
430 | test_cmp expect actual && | |
431 | GIT_ATTR_SOURCE=attr-source git -c attr.tree=attr-tree \ | |
432 | check-attr test -- f/path >actual && | |
433 | test_cmp expect actual | |
434 | ) | |
435 | ' | |
436 | ||
47cfc9bd KN |
437 | test_expect_success 'bare repository: with --source' ' |
438 | ( | |
439 | cd bare.git && | |
440 | attr_check_source foo/bar/f f tag-1 && | |
441 | attr_check_source foo/bar/a/i n tag-1 && | |
442 | attr_check_source foo/bar/f unspecified tag-2 && | |
443 | attr_check_source foo/bar/a/i m tag-2 && | |
444 | attr_check_source foo/bar/g g tag-2 && | |
445 | attr_check_source foo/bar/g unspecified tag-1 | |
446 | ) | |
447 | ' | |
448 | ||
b2b3e9c2 | 449 | test_expect_success 'bare repository: check that --cached honors index' ' |
c4a7bce1 JH |
450 | ( |
451 | cd bare.git && | |
452 | GIT_INDEX_FILE=../.git/index \ | |
453 | git check-attr --cached --stdin --all <../stdin-all | | |
454 | sort >actual && | |
455 | test_cmp ../specified-all actual | |
456 | ) | |
b2b3e9c2 JS |
457 | ' |
458 | ||
2d35d556 | 459 | test_expect_success 'bare repository: test info/attributes' ' |
2d35d556 | 460 | ( |
c4a7bce1 | 461 | cd bare.git && |
8da0b02d | 462 | mkdir info && |
c4a7bce1 | 463 | ( |
75651fd7 | 464 | echo "f test=f" && |
c4a7bce1 JH |
465 | echo "a/i test=a/i" |
466 | ) >info/attributes && | |
467 | attr_check f f && | |
468 | attr_check a/f f && | |
469 | attr_check a/c/f f && | |
470 | attr_check a/i a/i && | |
471 | attr_check subdir/a/i unspecified | |
472 | ) | |
2d35d556 RS |
473 | ' |
474 | ||
7b95849b JK |
475 | test_expect_success 'binary macro expanded by -a' ' |
476 | echo "file binary" >.gitattributes && | |
477 | cat >expect <<-\EOF && | |
478 | file: binary: set | |
479 | file: diff: unset | |
480 | file: merge: unset | |
481 | file: text: unset | |
482 | EOF | |
483 | git check-attr -a file >actual && | |
484 | test_cmp expect actual | |
485 | ' | |
486 | ||
7b95849b JK |
487 | test_expect_success 'query binary macro directly' ' |
488 | echo "file binary" >.gitattributes && | |
489 | echo file: binary: set >expect && | |
490 | git check-attr binary file >actual && | |
491 | test_cmp expect actual | |
492 | ' | |
493 | ||
2ef579e2 JK |
494 | test_expect_success SYMLINKS 'set up symlink tests' ' |
495 | echo "* test" >attr && | |
496 | rm -f .gitattributes | |
497 | ' | |
498 | ||
499 | test_expect_success SYMLINKS 'symlinks respected in core.attributesFile' ' | |
500 | test_when_finished "rm symlink" && | |
501 | ln -s attr symlink && | |
502 | test_config core.attributesFile "$(pwd)/symlink" && | |
503 | attr_check file set | |
504 | ' | |
505 | ||
506 | test_expect_success SYMLINKS 'symlinks respected in info/attributes' ' | |
507 | test_when_finished "rm .git/info/attributes" && | |
8da0b02d | 508 | mkdir .git/info && |
2ef579e2 JK |
509 | ln -s ../../attr .git/info/attributes && |
510 | attr_check file set | |
511 | ' | |
512 | ||
513 | test_expect_success SYMLINKS 'symlinks not respected in-tree' ' | |
514 | test_when_finished "rm -rf .gitattributes subdir" && | |
515 | ln -s attr .gitattributes && | |
516 | mkdir subdir && | |
517 | ln -s ../attr subdir/.gitattributes && | |
518 | attr_check_basic subdir/file unspecified && | |
6789275d | 519 | test_grep "unable to access.*gitattributes" err |
2ef579e2 JK |
520 | ' |
521 | ||
dfa6b32b PS |
522 | test_expect_success 'large attributes line ignored in tree' ' |
523 | test_when_finished "rm .gitattributes" && | |
524 | printf "path %02043d" 1 >.gitattributes && | |
525 | git check-attr --all path >actual 2>err && | |
526 | echo "warning: ignoring overly long attributes line 1" >expect && | |
527 | test_cmp expect err && | |
528 | test_must_be_empty actual | |
529 | ' | |
530 | ||
d74b1fd5 PS |
531 | test_expect_success 'large attributes line ignores trailing content in tree' ' |
532 | test_when_finished "rm .gitattributes" && | |
533 | # older versions of Git broke lines at 2048 bytes; the 2045 bytes | |
534 | # of 0-padding here is accounting for the three bytes of "a 1", which | |
535 | # would knock "trailing" to the "next" line, where it would be | |
536 | # erroneously parsed. | |
537 | printf "a %02045dtrailing attribute\n" 1 >.gitattributes && | |
538 | git check-attr --all trailing >actual 2>err && | |
dfa6b32b PS |
539 | echo "warning: ignoring overly long attributes line 1" >expect && |
540 | test_cmp expect err && | |
541 | test_must_be_empty actual | |
542 | ' | |
543 | ||
3c50032f PS |
544 | test_expect_success EXPENSIVE 'large attributes file ignored in tree' ' |
545 | test_when_finished "rm .gitattributes" && | |
5458ba0a | 546 | dd if=/dev/zero of=.gitattributes bs=1048576 count=101 2>/dev/null && |
3c50032f PS |
547 | git check-attr --all path >/dev/null 2>err && |
548 | echo "warning: ignoring overly large gitattributes file ${SQ}.gitattributes${SQ}" >expect && | |
549 | test_cmp expect err | |
550 | ' | |
551 | ||
dfa6b32b PS |
552 | test_expect_success 'large attributes line ignored in index' ' |
553 | test_when_finished "git update-index --remove .gitattributes" && | |
554 | blob=$(printf "path %02043d" 1 | git hash-object -w --stdin) && | |
555 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && | |
556 | git check-attr --cached --all path >actual 2>err && | |
557 | echo "warning: ignoring overly long attributes line 1" >expect && | |
558 | test_cmp expect err && | |
d74b1fd5 PS |
559 | test_must_be_empty actual |
560 | ' | |
561 | ||
562 | test_expect_success 'large attributes line ignores trailing content in index' ' | |
563 | test_when_finished "git update-index --remove .gitattributes" && | |
564 | blob=$(printf "a %02045dtrailing attribute\n" 1 | git hash-object -w --stdin) && | |
565 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && | |
566 | git check-attr --cached --all trailing >actual 2>err && | |
dfa6b32b PS |
567 | echo "warning: ignoring overly long attributes line 1" >expect && |
568 | test_cmp expect err && | |
d74b1fd5 PS |
569 | test_must_be_empty actual |
570 | ' | |
571 | ||
3c50032f PS |
572 | test_expect_success EXPENSIVE 'large attributes file ignored in index' ' |
573 | test_when_finished "git update-index --remove .gitattributes" && | |
5458ba0a | 574 | blob=$(dd if=/dev/zero bs=1048576 count=101 2>/dev/null | git hash-object -w --stdin) && |
3c50032f PS |
575 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && |
576 | git check-attr --cached --all path >/dev/null 2>err && | |
577 | echo "warning: ignoring overly large gitattributes blob ${SQ}.gitattributes${SQ}" >expect && | |
578 | test_cmp expect err | |
579 | ' | |
580 | ||
c793f9cb TB |
581 | test_expect_success EXPENSIVE 'large attributes blob ignored' ' |
582 | test_when_finished "git update-index --remove .gitattributes" && | |
583 | blob=$(dd if=/dev/zero bs=1048576 count=101 2>/dev/null | git hash-object -w --stdin) && | |
584 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && | |
585 | tree="$(git write-tree)" && | |
586 | git check-attr --cached --all --source="$tree" path >/dev/null 2>err && | |
587 | echo "warning: ignoring overly large gitattributes blob ${SQ}.gitattributes${SQ}" >expect && | |
588 | test_cmp expect err | |
589 | ' | |
590 | ||
2232a88a JW |
591 | test_expect_success 'builtin object mode attributes work (dir and regular paths)' ' |
592 | >normal && | |
593 | attr_check_object_mode normal 100644 && | |
594 | mkdir dir && | |
595 | attr_check_object_mode dir 040000 | |
596 | ' | |
597 | ||
598 | test_expect_success POSIXPERM 'builtin object mode attributes work (executable)' ' | |
599 | >exec && | |
600 | chmod +x exec && | |
601 | attr_check_object_mode exec 100755 | |
602 | ' | |
603 | ||
604 | test_expect_success SYMLINKS 'builtin object mode attributes work (symlinks)' ' | |
605 | ln -s to_sym sym && | |
606 | attr_check_object_mode sym 120000 | |
607 | ' | |
608 | ||
609 | test_expect_success 'native object mode attributes work with --cached' ' | |
610 | >normal && | |
611 | git add normal && | |
612 | empty_blob=$(git rev-parse :normal) && | |
613 | git update-index --index-info <<-EOF && | |
614 | 100755 $empty_blob 0 exec | |
615 | 120000 $empty_blob 0 symlink | |
616 | EOF | |
617 | attr_check_object_mode normal 100644 --cached && | |
618 | attr_check_object_mode exec 100755 --cached && | |
619 | attr_check_object_mode symlink 120000 --cached | |
620 | ' | |
621 | ||
622 | test_expect_success 'check object mode attributes work for submodules' ' | |
623 | mkdir sub && | |
624 | ( | |
625 | cd sub && | |
626 | git init && | |
627 | mv .git .real && | |
628 | echo "gitdir: .real" >.git && | |
629 | test_commit first | |
630 | ) && | |
631 | attr_check_object_mode sub 160000 && | |
632 | attr_check_object_mode sub unspecified --cached && | |
633 | git add sub && | |
634 | attr_check_object_mode sub 160000 --cached | |
635 | ' | |
636 | ||
637 | test_expect_success 'we do not allow user defined builtin_* attributes' ' | |
638 | echo "foo* builtin_foo" >.gitattributes && | |
639 | git add .gitattributes 2>actual && | |
640 | echo "builtin_foo is not a valid attribute name: .gitattributes:1" >expect && | |
641 | test_cmp expect actual | |
642 | ' | |
643 | ||
644 | test_expect_success 'user defined builtin_objectmode values are ignored' ' | |
645 | echo "foo* builtin_objectmode=12345" >.gitattributes && | |
646 | git add .gitattributes && | |
647 | >foo_1 && | |
648 | attr_check_object_mode_basic foo_1 100644 && | |
649 | echo "builtin_objectmode is not a valid attribute name: .gitattributes:1" >expect && | |
650 | test_cmp expect err | |
651 | ' | |
652 | ||
cf94ccda | 653 | test_done |