]>
Commit | Line | Data |
---|---|---|
cf94ccda JH |
1 | #!/bin/sh |
2 | ||
3 | test_description=gitattributes | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | attr_check () { | |
3738439c | 8 | path="$1" expect="$2" git_opts="$3" && |
cf94ccda | 9 | |
3738439c DL |
10 | git $git_opts check-attr test -- "$path" >actual 2>err && |
11 | echo "$path: test: $expect" >expect && | |
fa92f323 | 12 | test_cmp expect actual && |
99c049bc | 13 | test_must_be_empty err |
cf94ccda JH |
14 | } |
15 | ||
860a74d9 | 16 | attr_check_quote () { |
3738439c | 17 | path="$1" quoted_path="$2" expect="$3" && |
860a74d9 NTND |
18 | |
19 | git check-attr test -- "$path" >actual && | |
20 | echo "\"$quoted_path\": test: $expect" >expect && | |
21 | test_cmp expect actual | |
22 | ||
23 | } | |
24 | ||
25 | test_expect_success 'open-quoted pathname' ' | |
26 | echo "\"a test=a" >.gitattributes && | |
f46c243e | 27 | attr_check a unspecified |
860a74d9 NTND |
28 | ' |
29 | ||
30 | ||
cf94ccda | 31 | test_expect_success 'setup' ' |
0216af83 | 32 | mkdir -p a/b/d a/c b && |
cf94ccda | 33 | ( |
75651fd7 ES |
34 | echo "[attr]notest !test" && |
35 | echo "\" d \" test=d" && | |
36 | echo " e test=e" && | |
37 | echo " e\" test=e" && | |
38 | echo "f test=f" && | |
39 | echo "a/i test=a/i" && | |
40 | echo "onoff test -test" && | |
41 | echo "offon -test test" && | |
42 | echo "no notest" && | |
6eba6210 | 43 | echo "A/e/F test=A/e/F" |
cf94ccda JH |
44 | ) >.gitattributes && |
45 | ( | |
46 | echo "g test=a/g" && | |
47 | echo "b/g test=a/b/g" | |
48 | ) >a/.gitattributes && | |
49 | ( | |
50 | echo "h test=a/b/h" && | |
75651fd7 | 51 | echo "d/* test=a/b/d/*" && |
ec775c41 | 52 | echo "d/yes notest" |
dcc04366 | 53 | ) >a/b/.gitattributes && |
6df42ab9 PO |
54 | ( |
55 | echo "global test=global" | |
c9d8f0ac | 56 | ) >"$HOME"/global-gitattributes && |
78cec757 JH |
57 | cat <<-EOF >expect-all |
58 | f: test: f | |
59 | a/f: test: f | |
60 | a/c/f: test: f | |
61 | a/g: test: a/g | |
62 | a/b/g: test: a/b/g | |
63 | b/g: test: unspecified | |
64 | a/b/h: test: a/b/h | |
65 | a/b/d/g: test: a/b/d/* | |
66 | onoff: test: unset | |
67 | offon: test: set | |
68 | no: notest: set | |
69 | no: test: unspecified | |
70 | a/b/d/no: notest: set | |
71 | a/b/d/no: test: a/b/d/* | |
72 | a/b/d/yes: notest: set | |
73 | a/b/d/yes: test: unspecified | |
74 | EOF | |
cf94ccda JH |
75 | ' |
76 | ||
c0b13b21 | 77 | test_expect_success 'command line checks' ' |
09d7dd7a MH |
78 | test_must_fail git check-attr && |
79 | test_must_fail git check-attr -- && | |
fdf6be82 MH |
80 | test_must_fail git check-attr test && |
81 | test_must_fail git check-attr test -- && | |
09d7dd7a MH |
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 && | |
c0b13b21 | 86 | test_must_fail git check-attr "" -- f |
c0b13b21 MH |
87 | ' |
88 | ||
cf94ccda | 89 | test_expect_success 'attribute test' ' |
860a74d9 NTND |
90 | |
91 | attr_check " d " d && | |
92 | attr_check e e && | |
93 | attr_check_quote e\" e\\\" e && | |
94 | ||
cf94ccda JH |
95 | attr_check f f && |
96 | attr_check a/f f && | |
97 | attr_check a/c/f f && | |
98 | attr_check a/g a/g && | |
99 | attr_check a/b/g a/b/g && | |
100 | attr_check b/g unspecified && | |
101 | attr_check a/b/h a/b/h && | |
520ea857 MM |
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/*" && | |
ec775c41 | 107 | attr_check a/b/d/yes unspecified |
cf94ccda JH |
108 | ' |
109 | ||
6eba6210 BC |
110 | test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' ' |
111 | ||
f46c243e DL |
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" && | |
6eba6210 | 122 | attr_check NO unspecified "-c core.ignorecase=0" && |
f46c243e | 123 | attr_check a/b/D/NO unspecified "-c core.ignorecase=0" && |
6eba6210 | 124 | attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" && |
f46c243e | 125 | attr_check a/E/f f "-c core.ignorecase=0" |
6eba6210 BC |
126 | |
127 | ' | |
128 | ||
129 | test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' ' | |
130 | ||
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" | |
145 | ||
146 | ' | |
147 | ||
6eba6210 | 148 | test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' |
f46c243e DL |
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" && | |
6eba6210 BC |
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" | |
154 | ' | |
155 | ||
f5114a40 | 156 | test_expect_success 'unnormalized paths' ' |
d4d4f8df MH |
157 | attr_check ./f f && |
158 | attr_check ./a/g a/g && | |
159 | attr_check a/./g a/g && | |
160 | attr_check a/c/../b/g a/b/g | |
d4d4f8df MH |
161 | ' |
162 | ||
f5114a40 | 163 | test_expect_success 'relative paths' ' |
0216af83 MH |
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) | |
0216af83 MH |
172 | ' |
173 | ||
1afca444 JK |
174 | test_expect_success 'prefixes are not confused with leading directories' ' |
175 | attr_check a_plus/g unspecified && | |
176 | cat >expect <<-\EOF && | |
177 | a/g: test: a/g | |
178 | a_plus/g: test: unspecified | |
179 | EOF | |
180 | git check-attr test a/g a_plus/g >actual && | |
181 | test_cmp expect actual | |
182 | ' | |
183 | ||
6df42ab9 PO |
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 && | |
78cec757 | 190 | echo "global test=precedence" >>.gitattributes && |
6df42ab9 PO |
191 | attr_check global precedence |
192 | ' | |
193 | ||
b4666852 | 194 | test_expect_success 'attribute test: read paths from stdin' ' |
78cec757 JH |
195 | grep -v notest <expect-all >expect && |
196 | sed -e "s/:.*//" <expect | git check-attr --stdin test >actual && | |
b4666852 DP |
197 | test_cmp expect actual |
198 | ' | |
199 | ||
4ca0f188 | 200 | test_expect_success 'attribute test: --all option' ' |
b2b3e9c2 JS |
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 | |
205 | ' | |
206 | ||
207 | test_expect_success 'attribute test: --cached option' ' | |
b2b3e9c2 | 208 | git check-attr --cached --stdin --all <stdin-all | sort >actual && |
1c5e94f4 | 209 | test_must_be_empty actual && |
b2b3e9c2 JS |
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 | |
4ca0f188 MH |
213 | ' |
214 | ||
82881b38 | 215 | test_expect_success 'root subdir attribute test' ' |
82881b38 MO |
216 | attr_check a/i a/i && |
217 | attr_check subdir/a/i unspecified | |
82881b38 MO |
218 | ' |
219 | ||
82dce998 NTND |
220 | test_expect_success 'negative patterns' ' |
221 | echo "!f test=bar" >.gitattributes && | |
8b1bd024 TR |
222 | git check-attr test -- '"'"'!f'"'"' 2>errors && |
223 | test_i18ngrep "Negative patterns are ignored" errors | |
82dce998 NTND |
224 | ' |
225 | ||
226 | test_expect_success 'patterns starting with exclamation' ' | |
227 | echo "\!f test=foo" >.gitattributes && | |
228 | attr_check "!f" foo | |
229 | ' | |
230 | ||
237ec6e4 NTND |
231 | test_expect_success '"**" test' ' |
232 | echo "**/f foo=bar" >.gitattributes && | |
233 | cat <<\EOF >expect && | |
234 | f: foo: bar | |
235 | a/f: foo: bar | |
236 | a/b/f: foo: bar | |
237 | a/b/c/f: foo: bar | |
238 | EOF | |
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 && | |
99c049bc | 244 | test_must_be_empty err |
237ec6e4 NTND |
245 | ' |
246 | ||
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 && | |
251 | f: foo: unspecified | |
252 | af: foo: bar | |
253 | axf: foo: bar | |
254 | a/f: foo: unspecified | |
255 | a/b/f: foo: unspecified | |
256 | a/b/c/f: foo: unspecified | |
257 | EOF | |
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 && | |
99c049bc | 265 | test_must_be_empty err |
237ec6e4 NTND |
266 | ' |
267 | ||
cdbf6232 JH |
268 | test_expect_success 'using --git-dir and --work-tree' ' |
269 | mkdir unreal real && | |
270 | git init real && | |
271 | echo "file test=in-real" >real/.gitattributes && | |
272 | ( | |
273 | cd unreal && | |
274 | attr_check file in-real "--git-dir ../real/.git --work-tree ../real" | |
275 | ) | |
276 | ' | |
277 | ||
2d35d556 | 278 | test_expect_success 'setup bare' ' |
c4a7bce1 | 279 | git clone --bare . bare.git |
2d35d556 RS |
280 | ' |
281 | ||
282 | test_expect_success 'bare repository: check that .gitattribute is ignored' ' | |
2d35d556 | 283 | ( |
c4a7bce1 JH |
284 | cd bare.git && |
285 | ( | |
75651fd7 | 286 | echo "f test=f" && |
c4a7bce1 JH |
287 | echo "a/i test=a/i" |
288 | ) >.gitattributes && | |
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 | |
294 | ) | |
2d35d556 RS |
295 | ' |
296 | ||
b2b3e9c2 | 297 | test_expect_success 'bare repository: check that --cached honors index' ' |
c4a7bce1 JH |
298 | ( |
299 | cd bare.git && | |
300 | GIT_INDEX_FILE=../.git/index \ | |
301 | git check-attr --cached --stdin --all <../stdin-all | | |
302 | sort >actual && | |
303 | test_cmp ../specified-all actual | |
304 | ) | |
b2b3e9c2 JS |
305 | ' |
306 | ||
2d35d556 | 307 | test_expect_success 'bare repository: test info/attributes' ' |
2d35d556 | 308 | ( |
c4a7bce1 JH |
309 | cd bare.git && |
310 | ( | |
75651fd7 | 311 | echo "f test=f" && |
c4a7bce1 JH |
312 | echo "a/i test=a/i" |
313 | ) >info/attributes && | |
314 | attr_check f f && | |
315 | attr_check a/f f && | |
316 | attr_check a/c/f f && | |
317 | attr_check a/i a/i && | |
318 | attr_check subdir/a/i unspecified | |
319 | ) | |
2d35d556 RS |
320 | ' |
321 | ||
7b95849b JK |
322 | test_expect_success 'binary macro expanded by -a' ' |
323 | echo "file binary" >.gitattributes && | |
324 | cat >expect <<-\EOF && | |
325 | file: binary: set | |
326 | file: diff: unset | |
327 | file: merge: unset | |
328 | file: text: unset | |
329 | EOF | |
330 | git check-attr -a file >actual && | |
331 | test_cmp expect actual | |
332 | ' | |
333 | ||
334 | ||
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 | |
340 | ' | |
341 | ||
cf94ccda | 342 | test_done |