3 test_description=gitattributes
8 path="$1" expect="$2" git_opts="$3" &&
10 git $git_opts check-attr test -- "$path" >actual 2>err &&
11 echo "$path: test: $expect" >expect &&
12 test_cmp expect actual &&
13 test_must_be_empty err
17 path="$1" quoted_path="$2" expect="$3" &&
19 git check-attr test -- "$path" >actual &&
20 echo "\"$quoted_path\": test: $expect" >expect &&
21 test_cmp expect actual
25 test_expect_success 'open-quoted pathname' '
26 echo "\"a test=a" >.gitattributes &&
27 attr_check a unspecified
31 test_expect_success 'setup' '
32 mkdir -p a/b/d a/c b &&
34 echo "[attr]notest !test" &&
35 echo "\" d \" test=d" &&
39 echo "a/i test=a/i" &&
40 echo "onoff test -test" &&
41 echo "offon -test test" &&
43 echo "A/e/F test=A/e/F"
48 ) >a/.gitattributes &&
50 echo "h test=a/b/h" &&
51 echo "d/* test=a/b/d/*" &&
53 ) >a/b/.gitattributes &&
55 echo "global test=global"
56 ) >"$HOME"/global-gitattributes &&
57 cat <<-EOF >expect-all
63 b/g: test: unspecified
65 a/b/d/g: test: a/b/d/*
71 a/b/d/no: test: a/b/d/*
72 a/b/d/yes: notest: set
73 a/b/d/yes: test: unspecified
77 test_expect_success 'command line checks' '
78 test_must_fail git check-attr &&
79 test_must_fail git check-attr -- &&
80 test_must_fail git check-attr test &&
81 test_must_fail git check-attr test -- &&
82 test_must_fail git check-attr -- f &&
83 echo "f" | test_must_fail git check-attr --stdin &&
84 echo "f" | test_must_fail git check-attr --stdin -- f &&
85 echo "f" | test_must_fail git check-attr --stdin test -- f &&
86 test_must_fail git check-attr "" -- f
89 test_expect_success 'attribute test' '
93 attr_check_quote e\" e\\\" e &&
99 attr_check a/b/g a/b/g &&
100 attr_check b/g unspecified &&
101 attr_check a/b/h a/b/h &&
102 attr_check a/b/d/g "a/b/d/*" &&
103 attr_check onoff unset &&
104 attr_check offon set &&
105 attr_check no unspecified &&
106 attr_check a/b/d/no "a/b/d/*" &&
107 attr_check a/b/d/yes unspecified
110 test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '
112 attr_check F unspecified "-c core.ignorecase=0" &&
113 attr_check a/F unspecified "-c core.ignorecase=0" &&
114 attr_check a/c/F unspecified "-c core.ignorecase=0" &&
115 attr_check a/G unspecified "-c core.ignorecase=0" &&
116 attr_check a/B/g a/g "-c core.ignorecase=0" &&
117 attr_check a/b/G unspecified "-c core.ignorecase=0" &&
118 attr_check a/b/H unspecified "-c core.ignorecase=0" &&
119 attr_check a/b/D/g a/g "-c core.ignorecase=0" &&
120 attr_check oNoFf unspecified "-c core.ignorecase=0" &&
121 attr_check oFfOn unspecified "-c core.ignorecase=0" &&
122 attr_check NO unspecified "-c core.ignorecase=0" &&
123 attr_check a/b/D/NO unspecified "-c core.ignorecase=0" &&
124 attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" &&
125 attr_check a/E/f f "-c core.ignorecase=0"
129 test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' '
131 attr_check F f "-c core.ignorecase=1" &&
132 attr_check a/F f "-c core.ignorecase=1" &&
133 attr_check a/c/F f "-c core.ignorecase=1" &&
134 attr_check a/G a/g "-c core.ignorecase=1" &&
135 attr_check a/B/g a/b/g "-c core.ignorecase=1" &&
136 attr_check a/b/G a/b/g "-c core.ignorecase=1" &&
137 attr_check a/b/H a/b/h "-c core.ignorecase=1" &&
138 attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" &&
139 attr_check oNoFf unset "-c core.ignorecase=1" &&
140 attr_check oFfOn set "-c core.ignorecase=1" &&
141 attr_check NO unspecified "-c core.ignorecase=1" &&
142 attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" &&
143 attr_check a/b/d/YES unspecified "-c core.ignorecase=1" &&
144 attr_check a/E/f "A/e/F" "-c core.ignorecase=1"
148 test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' '
149 attr_check a/B/D/g a/g "-c core.ignorecase=0" &&
150 attr_check A/B/D/NO unspecified "-c core.ignorecase=0" &&
151 attr_check A/b/h a/b/h "-c core.ignorecase=1" &&
152 attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" &&
153 attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1"
156 test_expect_success 'unnormalized paths' '
158 attr_check ./a/g a/g &&
159 attr_check a/./g a/g &&
160 attr_check a/c/../b/g a/b/g
163 test_expect_success 'relative paths' '
164 (cd a && attr_check ../f f) &&
165 (cd a && attr_check f f) &&
166 (cd a && attr_check i a/i) &&
167 (cd a && attr_check g a/g) &&
168 (cd a && attr_check b/g a/b/g) &&
169 (cd b && attr_check ../a/f f) &&
170 (cd b && attr_check ../a/g a/g) &&
171 (cd b && attr_check ../a/b/g a/b/g)
174 test_expect_success 'prefixes are not confused with leading directories' '
175 attr_check a_plus/g unspecified &&
176 cat >expect <<-\EOF &&
178 a_plus/g: test: unspecified
180 git check-attr test a/g a_plus/g >actual &&
181 test_cmp expect actual
184 test_expect_success 'core.attributesfile' '
185 attr_check global unspecified &&
186 git config core.attributesfile "$HOME/global-gitattributes" &&
187 attr_check global global &&
188 git config core.attributesfile "~/global-gitattributes" &&
189 attr_check global global &&
190 echo "global test=precedence" >>.gitattributes &&
191 attr_check global precedence
194 test_expect_success 'attribute test: read paths from stdin' '
195 grep -v notest <expect-all >expect &&
196 sed -e "s/:.*//" <expect | git check-attr --stdin test >actual &&
197 test_cmp expect actual
200 test_expect_success 'attribute test: --all option' '
201 grep -v unspecified <expect-all | sort >specified-all &&
202 sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
203 git check-attr --stdin --all <stdin-all | sort >actual &&
204 test_cmp specified-all actual
207 test_expect_success 'attribute test: --cached option' '
208 git check-attr --cached --stdin --all <stdin-all | sort >actual &&
209 test_must_be_empty actual &&
210 git add .gitattributes a/.gitattributes a/b/.gitattributes &&
211 git check-attr --cached --stdin --all <stdin-all | sort >actual &&
212 test_cmp specified-all actual
215 test_expect_success 'root subdir attribute test' '
216 attr_check a/i a/i &&
217 attr_check subdir/a/i unspecified
220 test_expect_success 'negative patterns' '
221 echo "!f test=bar" >.gitattributes &&
222 git check-attr test -- '"'"'!f'"'"' 2>errors &&
223 test_i18ngrep "Negative patterns are ignored" errors
226 test_expect_success 'patterns starting with exclamation' '
227 echo "\!f test=foo" >.gitattributes &&
231 test_expect_success '"**" test' '
232 echo "**/f foo=bar" >.gitattributes &&
233 cat <<\EOF >expect &&
239 git check-attr foo -- "f" >actual 2>err &&
240 git check-attr foo -- "a/f" >>actual 2>>err &&
241 git check-attr foo -- "a/b/f" >>actual 2>>err &&
242 git check-attr foo -- "a/b/c/f" >>actual 2>>err &&
243 test_cmp expect actual &&
244 test_must_be_empty err
247 test_expect_success '"**" with no slashes test' '
248 echo "a**f foo=bar" >.gitattributes &&
249 git check-attr foo -- "f" >actual &&
250 cat <<\EOF >expect &&
254 a/f: foo: unspecified
255 a/b/f: foo: unspecified
256 a/b/c/f: foo: unspecified
258 git check-attr foo -- "f" >actual 2>err &&
259 git check-attr foo -- "af" >>actual 2>err &&
260 git check-attr foo -- "axf" >>actual 2>err &&
261 git check-attr foo -- "a/f" >>actual 2>>err &&
262 git check-attr foo -- "a/b/f" >>actual 2>>err &&
263 git check-attr foo -- "a/b/c/f" >>actual 2>>err &&
264 test_cmp expect actual &&
265 test_must_be_empty err
268 test_expect_success 'using --git-dir and --work-tree' '
271 echo "file test=in-real" >real/.gitattributes &&
274 attr_check file in-real "--git-dir ../real/.git --work-tree ../real"
278 test_expect_success 'setup bare' '
279 git clone --bare . bare.git
282 test_expect_success 'bare repository: check that .gitattribute is ignored' '
289 attr_check f unspecified &&
290 attr_check a/f unspecified &&
291 attr_check a/c/f unspecified &&
292 attr_check a/i unspecified &&
293 attr_check subdir/a/i unspecified
297 test_expect_success 'bare repository: check that --cached honors index' '
300 GIT_INDEX_FILE=../.git/index \
301 git check-attr --cached --stdin --all <../stdin-all |
303 test_cmp ../specified-all actual
307 test_expect_success 'bare repository: test info/attributes' '
313 ) >info/attributes &&
316 attr_check a/c/f f &&
317 attr_check a/i a/i &&
318 attr_check subdir/a/i unspecified
322 test_expect_success 'binary macro expanded by -a' '
323 echo "file binary" >.gitattributes &&
324 cat >expect <<-\EOF &&
330 git check-attr -a file >actual &&
331 test_cmp expect actual
335 test_expect_success 'query binary macro directly' '
336 echo "file binary" >.gitattributes &&
337 echo file: binary: set >expect &&
338 git check-attr binary file >actual &&
339 test_cmp expect actual