]>
Commit | Line | Data |
---|---|---|
cf94ccda JH |
1 | #!/bin/sh |
2 | ||
3 | test_description=gitattributes | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | attr_check () { | |
78cec757 | 8 | path="$1" expect="$2" |
cf94ccda | 9 | |
6eba6210 | 10 | git $3 check-attr test -- "$path" >actual 2>err && |
cf94ccda | 11 | echo "$path: test: $2" >expect && |
fa92f323 MH |
12 | test_cmp expect actual && |
13 | test_line_count = 0 err | |
cf94ccda JH |
14 | } |
15 | ||
16 | ||
17 | test_expect_success 'setup' ' | |
0216af83 | 18 | mkdir -p a/b/d a/c b && |
cf94ccda | 19 | ( |
ec775c41 | 20 | echo "[attr]notest !test" |
cf94ccda | 21 | echo "f test=f" |
82881b38 | 22 | echo "a/i test=a/i" |
969f9d73 HG |
23 | echo "onoff test -test" |
24 | echo "offon -test test" | |
ec775c41 | 25 | echo "no notest" |
6eba6210 | 26 | echo "A/e/F test=A/e/F" |
cf94ccda JH |
27 | ) >.gitattributes && |
28 | ( | |
29 | echo "g test=a/g" && | |
30 | echo "b/g test=a/b/g" | |
31 | ) >a/.gitattributes && | |
32 | ( | |
33 | echo "h test=a/b/h" && | |
34 | echo "d/* test=a/b/d/*" | |
ec775c41 | 35 | echo "d/yes notest" |
dcc04366 | 36 | ) >a/b/.gitattributes && |
6df42ab9 PO |
37 | ( |
38 | echo "global test=global" | |
c9d8f0ac | 39 | ) >"$HOME"/global-gitattributes && |
78cec757 JH |
40 | cat <<-EOF >expect-all |
41 | f: test: f | |
42 | a/f: test: f | |
43 | a/c/f: test: f | |
44 | a/g: test: a/g | |
45 | a/b/g: test: a/b/g | |
46 | b/g: test: unspecified | |
47 | a/b/h: test: a/b/h | |
48 | a/b/d/g: test: a/b/d/* | |
49 | onoff: test: unset | |
50 | offon: test: set | |
51 | no: notest: set | |
52 | no: test: unspecified | |
53 | a/b/d/no: notest: set | |
54 | a/b/d/no: test: a/b/d/* | |
55 | a/b/d/yes: notest: set | |
56 | a/b/d/yes: test: unspecified | |
57 | EOF | |
cf94ccda JH |
58 | ' |
59 | ||
c0b13b21 | 60 | test_expect_success 'command line checks' ' |
09d7dd7a MH |
61 | test_must_fail git check-attr && |
62 | test_must_fail git check-attr -- && | |
fdf6be82 MH |
63 | test_must_fail git check-attr test && |
64 | test_must_fail git check-attr test -- && | |
09d7dd7a MH |
65 | test_must_fail git check-attr -- f && |
66 | echo "f" | test_must_fail git check-attr --stdin && | |
67 | echo "f" | test_must_fail git check-attr --stdin -- f && | |
68 | echo "f" | test_must_fail git check-attr --stdin test -- f && | |
c0b13b21 | 69 | test_must_fail git check-attr "" -- f |
c0b13b21 MH |
70 | ' |
71 | ||
cf94ccda | 72 | test_expect_success 'attribute test' ' |
cf94ccda JH |
73 | attr_check f f && |
74 | attr_check a/f f && | |
75 | attr_check a/c/f f && | |
76 | attr_check a/g a/g && | |
77 | attr_check a/b/g a/b/g && | |
78 | attr_check b/g unspecified && | |
79 | attr_check a/b/h a/b/h && | |
520ea857 MM |
80 | attr_check a/b/d/g "a/b/d/*" && |
81 | attr_check onoff unset && | |
82 | attr_check offon set && | |
83 | attr_check no unspecified && | |
84 | attr_check a/b/d/no "a/b/d/*" && | |
ec775c41 | 85 | attr_check a/b/d/yes unspecified |
cf94ccda JH |
86 | ' |
87 | ||
6eba6210 BC |
88 | test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' ' |
89 | ||
90 | test_must_fail attr_check F f "-c core.ignorecase=0" && | |
91 | test_must_fail attr_check a/F f "-c core.ignorecase=0" && | |
92 | test_must_fail attr_check a/c/F f "-c core.ignorecase=0" && | |
93 | test_must_fail attr_check a/G a/g "-c core.ignorecase=0" && | |
94 | test_must_fail attr_check a/B/g a/b/g "-c core.ignorecase=0" && | |
95 | test_must_fail attr_check a/b/G a/b/g "-c core.ignorecase=0" && | |
96 | test_must_fail attr_check a/b/H a/b/h "-c core.ignorecase=0" && | |
97 | test_must_fail attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=0" && | |
98 | test_must_fail attr_check oNoFf unset "-c core.ignorecase=0" && | |
99 | test_must_fail attr_check oFfOn set "-c core.ignorecase=0" && | |
100 | attr_check NO unspecified "-c core.ignorecase=0" && | |
101 | test_must_fail attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=0" && | |
102 | attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" && | |
103 | test_must_fail attr_check a/E/f "A/e/F" "-c core.ignorecase=0" | |
104 | ||
105 | ' | |
106 | ||
107 | test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' ' | |
108 | ||
109 | attr_check F f "-c core.ignorecase=1" && | |
110 | attr_check a/F f "-c core.ignorecase=1" && | |
111 | attr_check a/c/F f "-c core.ignorecase=1" && | |
112 | attr_check a/G a/g "-c core.ignorecase=1" && | |
113 | attr_check a/B/g a/b/g "-c core.ignorecase=1" && | |
114 | attr_check a/b/G a/b/g "-c core.ignorecase=1" && | |
115 | attr_check a/b/H a/b/h "-c core.ignorecase=1" && | |
116 | attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" && | |
117 | attr_check oNoFf unset "-c core.ignorecase=1" && | |
118 | attr_check oFfOn set "-c core.ignorecase=1" && | |
119 | attr_check NO unspecified "-c core.ignorecase=1" && | |
120 | attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" && | |
121 | attr_check a/b/d/YES unspecified "-c core.ignorecase=1" && | |
122 | attr_check a/E/f "A/e/F" "-c core.ignorecase=1" | |
123 | ||
124 | ' | |
125 | ||
6eba6210 BC |
126 | test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' |
127 | test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" && | |
128 | test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" && | |
129 | attr_check A/b/h a/b/h "-c core.ignorecase=1" && | |
130 | attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" && | |
131 | attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1" | |
132 | ' | |
133 | ||
f5114a40 | 134 | test_expect_success 'unnormalized paths' ' |
d4d4f8df MH |
135 | attr_check ./f f && |
136 | attr_check ./a/g a/g && | |
137 | attr_check a/./g a/g && | |
138 | attr_check a/c/../b/g a/b/g | |
d4d4f8df MH |
139 | ' |
140 | ||
f5114a40 | 141 | test_expect_success 'relative paths' ' |
0216af83 MH |
142 | (cd a && attr_check ../f f) && |
143 | (cd a && attr_check f f) && | |
144 | (cd a && attr_check i a/i) && | |
145 | (cd a && attr_check g a/g) && | |
146 | (cd a && attr_check b/g a/b/g) && | |
147 | (cd b && attr_check ../a/f f) && | |
148 | (cd b && attr_check ../a/g a/g) && | |
149 | (cd b && attr_check ../a/b/g a/b/g) | |
0216af83 MH |
150 | ' |
151 | ||
1afca444 JK |
152 | test_expect_success 'prefixes are not confused with leading directories' ' |
153 | attr_check a_plus/g unspecified && | |
154 | cat >expect <<-\EOF && | |
155 | a/g: test: a/g | |
156 | a_plus/g: test: unspecified | |
157 | EOF | |
158 | git check-attr test a/g a_plus/g >actual && | |
159 | test_cmp expect actual | |
160 | ' | |
161 | ||
6df42ab9 PO |
162 | test_expect_success 'core.attributesfile' ' |
163 | attr_check global unspecified && | |
164 | git config core.attributesfile "$HOME/global-gitattributes" && | |
165 | attr_check global global && | |
166 | git config core.attributesfile "~/global-gitattributes" && | |
167 | attr_check global global && | |
78cec757 | 168 | echo "global test=precedence" >>.gitattributes && |
6df42ab9 PO |
169 | attr_check global precedence |
170 | ' | |
171 | ||
b4666852 | 172 | test_expect_success 'attribute test: read paths from stdin' ' |
78cec757 JH |
173 | grep -v notest <expect-all >expect && |
174 | sed -e "s/:.*//" <expect | git check-attr --stdin test >actual && | |
b4666852 DP |
175 | test_cmp expect actual |
176 | ' | |
177 | ||
4ca0f188 | 178 | test_expect_success 'attribute test: --all option' ' |
b2b3e9c2 JS |
179 | grep -v unspecified <expect-all | sort >specified-all && |
180 | sed -e "s/:.*//" <expect-all | uniq >stdin-all && | |
181 | git check-attr --stdin --all <stdin-all | sort >actual && | |
182 | test_cmp specified-all actual | |
183 | ' | |
184 | ||
185 | test_expect_success 'attribute test: --cached option' ' | |
b2b3e9c2 JS |
186 | : >empty && |
187 | git check-attr --cached --stdin --all <stdin-all | sort >actual && | |
188 | test_cmp empty actual && | |
189 | git add .gitattributes a/.gitattributes a/b/.gitattributes && | |
190 | git check-attr --cached --stdin --all <stdin-all | sort >actual && | |
191 | test_cmp specified-all actual | |
4ca0f188 MH |
192 | ' |
193 | ||
82881b38 | 194 | test_expect_success 'root subdir attribute test' ' |
82881b38 MO |
195 | attr_check a/i a/i && |
196 | attr_check subdir/a/i unspecified | |
82881b38 MO |
197 | ' |
198 | ||
82dce998 NTND |
199 | test_expect_success 'negative patterns' ' |
200 | echo "!f test=bar" >.gitattributes && | |
8b1bd024 TR |
201 | git check-attr test -- '"'"'!f'"'"' 2>errors && |
202 | test_i18ngrep "Negative patterns are ignored" errors | |
82dce998 NTND |
203 | ' |
204 | ||
205 | test_expect_success 'patterns starting with exclamation' ' | |
206 | echo "\!f test=foo" >.gitattributes && | |
207 | attr_check "!f" foo | |
208 | ' | |
209 | ||
237ec6e4 NTND |
210 | test_expect_success '"**" test' ' |
211 | echo "**/f foo=bar" >.gitattributes && | |
212 | cat <<\EOF >expect && | |
213 | f: foo: bar | |
214 | a/f: foo: bar | |
215 | a/b/f: foo: bar | |
216 | a/b/c/f: foo: bar | |
217 | EOF | |
218 | git check-attr foo -- "f" >actual 2>err && | |
219 | git check-attr foo -- "a/f" >>actual 2>>err && | |
220 | git check-attr foo -- "a/b/f" >>actual 2>>err && | |
221 | git check-attr foo -- "a/b/c/f" >>actual 2>>err && | |
222 | test_cmp expect actual && | |
223 | test_line_count = 0 err | |
224 | ' | |
225 | ||
226 | test_expect_success '"**" with no slashes test' ' | |
227 | echo "a**f foo=bar" >.gitattributes && | |
228 | git check-attr foo -- "f" >actual && | |
229 | cat <<\EOF >expect && | |
230 | f: foo: unspecified | |
231 | af: foo: bar | |
232 | axf: foo: bar | |
233 | a/f: foo: unspecified | |
234 | a/b/f: foo: unspecified | |
235 | a/b/c/f: foo: unspecified | |
236 | EOF | |
237 | git check-attr foo -- "f" >actual 2>err && | |
238 | git check-attr foo -- "af" >>actual 2>err && | |
239 | git check-attr foo -- "axf" >>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_line_count = 0 err | |
245 | ' | |
246 | ||
2d35d556 | 247 | test_expect_success 'setup bare' ' |
2d35d556 RS |
248 | git clone --bare . bare.git && |
249 | cd bare.git | |
2d35d556 RS |
250 | ' |
251 | ||
252 | test_expect_success 'bare repository: check that .gitattribute is ignored' ' | |
2d35d556 RS |
253 | ( |
254 | echo "f test=f" | |
255 | echo "a/i test=a/i" | |
256 | ) >.gitattributes && | |
257 | attr_check f unspecified && | |
258 | attr_check a/f unspecified && | |
259 | attr_check a/c/f unspecified && | |
260 | attr_check a/i unspecified && | |
261 | attr_check subdir/a/i unspecified | |
2d35d556 RS |
262 | ' |
263 | ||
b2b3e9c2 JS |
264 | test_expect_success 'bare repository: check that --cached honors index' ' |
265 | GIT_INDEX_FILE=../.git/index \ | |
266 | git check-attr --cached --stdin --all <../stdin-all | | |
267 | sort >actual && | |
268 | test_cmp ../specified-all actual | |
269 | ' | |
270 | ||
2d35d556 | 271 | test_expect_success 'bare repository: test info/attributes' ' |
2d35d556 RS |
272 | ( |
273 | echo "f test=f" | |
274 | echo "a/i test=a/i" | |
275 | ) >info/attributes && | |
276 | attr_check f f && | |
277 | attr_check a/f f && | |
278 | attr_check a/c/f f && | |
279 | attr_check a/i a/i && | |
280 | attr_check subdir/a/i unspecified | |
2d35d556 RS |
281 | ' |
282 | ||
cf94ccda | 283 | test_done |