3 test_description
=gitattributes
5 TEST_PASSES_SANITIZE_LEAK
=true
6 TEST_CREATE_REPO_NO_TEMPLATE
=1
10 path
="$1" expect
="$2" git_opts
="$3" &&
12 git
$git_opts check-attr
test -- "$path" >actual
2>err
&&
13 echo "$path: test: $expect" >expect
&&
14 test_cmp expect actual
18 attr_check_basic
"$@" &&
19 test_must_be_empty err
23 path
="$1" quoted_path
="$2" expect
="$3" &&
25 git check-attr
test -- "$path" >actual
&&
26 echo "\"$quoted_path\": test: $expect" >expect
&&
27 test_cmp expect actual
31 test_expect_success
'open-quoted pathname' '
32 echo "\"a test=a" >.gitattributes &&
33 attr_check a unspecified
37 test_expect_success
'setup' '
38 mkdir -p a/b/d a/c b &&
40 echo "[attr]notest !test" &&
41 echo "\" d \" test=d" &&
45 echo "a/i test=a/i" &&
46 echo "onoff test -test" &&
47 echo "offon -test test" &&
49 echo "A/e/F test=A/e/F"
54 ) >a/.gitattributes &&
56 echo "h test=a/b/h" &&
57 echo "d/* test=a/b/d/*" &&
59 ) >a/b/.gitattributes &&
61 echo "global test=global"
62 ) >"$HOME"/global-gitattributes &&
63 cat <<-EOF >expect-all
69 b/g: test: unspecified
71 a/b/d/g: test: a/b/d/*
77 a/b/d/no: test: a/b/d/*
78 a/b/d/yes: notest: set
79 a/b/d/yes: test: unspecified
83 test_expect_success
'command line checks' '
84 test_must_fail git check-attr &&
85 test_must_fail git check-attr -- &&
86 test_must_fail git check-attr test &&
87 test_must_fail git check-attr test -- &&
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 &&
92 test_must_fail git check-attr "" -- f
95 test_expect_success
'attribute test' '
99 attr_check_quote e\" e\\\" e &&
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 &&
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/*" &&
113 attr_check a/b/d/yes unspecified
116 test_expect_success
'attribute matching is case sensitive when core.ignorecase=0' '
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" &&
128 attr_check NO unspecified "-c core.ignorecase=0" &&
129 attr_check a/b/D/NO unspecified "-c core.ignorecase=0" &&
130 attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" &&
131 attr_check a/E/f f "-c core.ignorecase=0"
135 test_expect_success
'attribute matching is case insensitive when core.ignorecase=1' '
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"
154 test_expect_success CASE_INSENSITIVE_FS
'additional case insensitivity tests' '
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" &&
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"
162 test_expect_success
'unnormalized paths' '
164 attr_check ./a/g a/g &&
165 attr_check a/./g a/g &&
166 attr_check a/c/../b/g a/b/g
169 test_expect_success
'relative paths' '
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)
180 test_expect_success
'prefixes are not confused with leading directories' '
181 attr_check a_plus/g unspecified &&
182 cat >expect <<-\EOF &&
184 a_plus/g: test: unspecified
186 git check-attr test a/g a_plus/g >actual &&
187 test_cmp expect actual
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 &&
196 echo "global test=precedence" >>.gitattributes &&
197 attr_check global precedence
200 test_expect_success
'attribute test: read paths from stdin' '
201 grep -v notest <expect-all >expect &&
202 sed -e "s/:.*//" <expect | git check-attr --stdin test >actual &&
203 test_cmp expect actual
206 test_expect_success
'attribute test: --all option' '
207 grep -v unspecified <expect-all | sort >specified-all &&
208 sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
209 git check-attr --stdin --all <stdin-all >tmp &&
211 test_cmp specified-all actual
214 test_expect_success
'attribute test: --cached option' '
215 git check-attr --cached --stdin --all <stdin-all >tmp &&
217 test_must_be_empty actual &&
218 git add .gitattributes a/.gitattributes a/b/.gitattributes &&
219 git check-attr --cached --stdin --all <stdin-all >tmp &&
221 test_cmp specified-all actual
224 test_expect_success
'root subdir attribute test' '
225 attr_check a/i a/i &&
226 attr_check subdir/a/i unspecified
229 test_expect_success
'negative patterns' '
230 echo "!f test=bar" >.gitattributes &&
231 git check-attr test -- '"'"'!f'"'"' 2>errors &&
232 test_i18ngrep "Negative patterns are ignored" errors
235 test_expect_success
'patterns starting with exclamation' '
236 echo "\!f test=foo" >.gitattributes &&
240 test_expect_success
'"**" test' '
241 echo "**/f foo=bar" >.gitattributes &&
242 cat <<\EOF >expect &&
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 &&
253 test_must_be_empty err
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 &&
263 a/f: foo: unspecified
264 a/b/f: foo: unspecified
265 a/b/c/f: foo: unspecified
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 &&
274 test_must_be_empty err
277 test_expect_success
'using --git-dir and --work-tree' '
280 echo "file test=in-real" >real/.gitattributes &&
283 attr_check file in-real "--git-dir ../real/.git --work-tree ../real"
287 test_expect_success
'setup bare' '
288 git clone --template= --bare . bare.git
291 test_expect_success
'bare repository: check that .gitattribute is ignored' '
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
306 test_expect_success
'bare repository: check that --cached honors index' '
309 GIT_INDEX_FILE=../.git/index \
310 git check-attr --cached --stdin --all <../stdin-all |
312 test_cmp ../specified-all actual
316 test_expect_success
'bare repository: test info/attributes' '
323 ) >info/attributes &&
326 attr_check a/c/f f &&
327 attr_check a/i a/i &&
328 attr_check subdir/a/i unspecified
332 test_expect_success
'binary macro expanded by -a' '
333 echo "file binary" >.gitattributes &&
334 cat >expect <<-\EOF &&
340 git check-attr -a file >actual &&
341 test_cmp expect actual
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
351 test_expect_success SYMLINKS
'set up symlink tests' '
352 echo "* test" >attr &&
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" &&
363 test_expect_success SYMLINKS
'symlinks respected in info/attributes' '
364 test_when_finished "rm .git/info/attributes" &&
366 ln -s ../../attr .git/info/attributes &&
370 test_expect_success SYMLINKS
'symlinks not respected in-tree' '
371 test_when_finished "rm -rf .gitattributes subdir" &&
372 ln -s attr .gitattributes &&
374 ln -s ../attr subdir/.gitattributes &&
375 attr_check_basic subdir/file unspecified &&
376 test_i18ngrep "unable to access.*gitattributes" err
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
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 &&
396 echo "warning: ignoring overly long attributes line 1" >expect &&
397 test_cmp expect err &&
398 test_must_be_empty actual
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 &&
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 &&
416 test_must_be_empty actual
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 &&
424 echo "warning: ignoring overly long attributes line 1" >expect &&
425 test_cmp expect err &&
426 test_must_be_empty actual
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 &&