]>
Commit | Line | Data |
---|---|---|
9b25a0b5 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='test config file include directives' | |
25ad7221 | 4 | TEST_PASSES_SANITIZE_LEAK=true |
9b25a0b5 JK |
5 | . ./test-lib.sh |
6 | ||
86f95157 NTND |
7 | # Force setup_explicit_git_dir() to run until the end. This is needed |
8 | # by some tests to make sure real_path() is called on $GIT_DIR. The | |
9 | # caller needs to make sure git commands are run from a subdirectory | |
10 | # though or real_path() will not be called. | |
11 | force_setup_explicit_git_dir() { | |
12 | GIT_DIR="$(pwd)/.git" | |
13 | GIT_WORK_TREE="$(pwd)" | |
14 | export GIT_DIR GIT_WORK_TREE | |
15 | } | |
16 | ||
9b25a0b5 JK |
17 | test_expect_success 'include file by absolute path' ' |
18 | echo "[test]one = 1" >one && | |
19 | echo "[include]path = \"$(pwd)/one\"" >.gitconfig && | |
20 | echo 1 >expect && | |
21 | git config test.one >actual && | |
22 | test_cmp expect actual | |
23 | ' | |
24 | ||
25 | test_expect_success 'include file by relative path' ' | |
26 | echo "[test]one = 1" >one && | |
27 | echo "[include]path = one" >.gitconfig && | |
28 | echo 1 >expect && | |
29 | git config test.one >actual && | |
30 | test_cmp expect actual | |
31 | ' | |
32 | ||
33 | test_expect_success 'chained relative paths' ' | |
34 | mkdir subdir && | |
35 | echo "[test]three = 3" >subdir/three && | |
36 | echo "[include]path = three" >subdir/two && | |
37 | echo "[include]path = subdir/two" >.gitconfig && | |
38 | echo 3 >expect && | |
39 | git config test.three >actual && | |
40 | test_cmp expect actual | |
41 | ' | |
42 | ||
4c0a89fc JK |
43 | test_expect_success 'include paths get tilde-expansion' ' |
44 | echo "[test]one = 1" >one && | |
45 | echo "[include]path = ~/one" >.gitconfig && | |
46 | echo 1 >expect && | |
47 | git config test.one >actual && | |
48 | test_cmp expect actual | |
49 | ' | |
50 | ||
9b25a0b5 JK |
51 | test_expect_success 'include options can still be examined' ' |
52 | echo "[test]one = 1" >one && | |
53 | echo "[include]path = one" >.gitconfig && | |
54 | echo one >expect && | |
55 | git config include.path >actual && | |
56 | test_cmp expect actual | |
57 | ' | |
58 | ||
59 | test_expect_success 'listing includes option and expansion' ' | |
60 | echo "[test]one = 1" >one && | |
61 | echo "[include]path = one" >.gitconfig && | |
62 | cat >expect <<-\EOF && | |
63 | include.path=one | |
64 | test.one=1 | |
65 | EOF | |
66 | git config --list >actual.full && | |
0b408ca2 | 67 | grep -v -e ^core -e ^extensions actual.full >actual && |
9b25a0b5 JK |
68 | test_cmp expect actual |
69 | ' | |
70 | ||
71 | test_expect_success 'single file lookup does not expand includes by default' ' | |
72 | echo "[test]one = 1" >one && | |
73 | echo "[include]path = one" >.gitconfig && | |
74 | test_must_fail git config -f .gitconfig test.one && | |
75 | test_must_fail git config --global test.one && | |
76 | echo 1 >expect && | |
77 | git config --includes -f .gitconfig test.one >actual && | |
78 | test_cmp expect actual | |
79 | ' | |
80 | ||
81 | test_expect_success 'single file list does not expand includes by default' ' | |
82 | echo "[test]one = 1" >one && | |
83 | echo "[include]path = one" >.gitconfig && | |
84 | echo "include.path=one" >expect && | |
85 | git config -f .gitconfig --list >actual && | |
86 | test_cmp expect actual | |
87 | ' | |
88 | ||
89 | test_expect_success 'writing config file does not expand includes' ' | |
90 | echo "[test]one = 1" >one && | |
91 | echo "[include]path = one" >.gitconfig && | |
92 | git config test.two 2 && | |
93 | echo 2 >expect && | |
94 | git config --no-includes test.two >actual && | |
95 | test_cmp expect actual && | |
96 | test_must_fail git config --no-includes test.one | |
97 | ' | |
98 | ||
99 | test_expect_success 'config modification does not affect includes' ' | |
100 | echo "[test]one = 1" >one && | |
101 | echo "[include]path = one" >.gitconfig && | |
102 | git config test.one 2 && | |
103 | echo 1 >expect && | |
104 | git config -f one test.one >actual && | |
105 | test_cmp expect actual && | |
106 | cat >expect <<-\EOF && | |
107 | 1 | |
108 | 2 | |
109 | EOF | |
110 | git config --get-all test.one >actual && | |
111 | test_cmp expect actual | |
112 | ' | |
113 | ||
114 | test_expect_success 'missing include files are ignored' ' | |
115 | cat >.gitconfig <<-\EOF && | |
3efd0bed | 116 | [include]path = non-existent |
9b25a0b5 JK |
117 | [test]value = yes |
118 | EOF | |
119 | echo yes >expect && | |
120 | git config test.value >actual && | |
121 | test_cmp expect actual | |
122 | ' | |
123 | ||
124 | test_expect_success 'absolute includes from command line work' ' | |
125 | echo "[test]one = 1" >one && | |
126 | echo 1 >expect && | |
3caec73b | 127 | git -c include.path="$(pwd)/one" config test.one >actual && |
9b25a0b5 JK |
128 | test_cmp expect actual |
129 | ' | |
130 | ||
131 | test_expect_success 'relative includes from command line fail' ' | |
132 | echo "[test]one = 1" >one && | |
133 | test_must_fail git -c include.path=one config test.one | |
134 | ' | |
135 | ||
d14d4244 JK |
136 | test_expect_success 'absolute includes from blobs work' ' |
137 | echo "[test]one = 1" >one && | |
138 | echo "[include]path=$(pwd)/one" >blob && | |
139 | blob=$(git hash-object -w blob) && | |
140 | echo 1 >expect && | |
141 | git config --blob=$blob test.one >actual && | |
142 | test_cmp expect actual | |
143 | ' | |
144 | ||
145 | test_expect_success 'relative includes from blobs fail' ' | |
146 | echo "[test]one = 1" >one && | |
147 | echo "[include]path=one" >blob && | |
148 | blob=$(git hash-object -w blob) && | |
149 | test_must_fail git config --blob=$blob test.one | |
150 | ' | |
151 | ||
3caec73b KS |
152 | test_expect_success 'absolute includes from stdin work' ' |
153 | echo "[test]one = 1" >one && | |
154 | echo 1 >expect && | |
155 | echo "[include]path=\"$(pwd)/one\"" | | |
156 | git config --file - test.one >actual && | |
157 | test_cmp expect actual | |
158 | ' | |
159 | ||
160 | test_expect_success 'relative includes from stdin line fail' ' | |
161 | echo "[test]one = 1" >one && | |
162 | echo "[include]path=one" | | |
163 | test_must_fail git config --file - test.one | |
164 | ' | |
165 | ||
3efd0bed NTND |
166 | test_expect_success 'conditional include, both unanchored' ' |
167 | git init foo && | |
168 | ( | |
169 | cd foo && | |
170 | echo "[includeIf \"gitdir:foo/\"]path=bar" >>.git/config && | |
171 | echo "[test]one=1" >.git/bar && | |
172 | echo 1 >expect && | |
173 | git config test.one >actual && | |
174 | test_cmp expect actual | |
175 | ) | |
176 | ' | |
177 | ||
178 | test_expect_success 'conditional include, $HOME expansion' ' | |
179 | ( | |
180 | cd foo && | |
181 | echo "[includeIf \"gitdir:~/foo/\"]path=bar2" >>.git/config && | |
182 | echo "[test]two=2" >.git/bar2 && | |
183 | echo 2 >expect && | |
184 | git config test.two >actual && | |
185 | test_cmp expect actual | |
186 | ) | |
187 | ' | |
188 | ||
189 | test_expect_success 'conditional include, full pattern' ' | |
190 | ( | |
191 | cd foo && | |
192 | echo "[includeIf \"gitdir:**/foo/**\"]path=bar3" >>.git/config && | |
193 | echo "[test]three=3" >.git/bar3 && | |
194 | echo 3 >expect && | |
195 | git config test.three >actual && | |
196 | test_cmp expect actual | |
197 | ) | |
198 | ' | |
199 | ||
200 | test_expect_success 'conditional include, relative path' ' | |
201 | echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >>.gitconfig && | |
202 | echo "[test]four=4" >bar4 && | |
203 | ( | |
204 | cd foo && | |
205 | echo 4 >expect && | |
206 | git config test.four >actual && | |
207 | test_cmp expect actual | |
208 | ) | |
209 | ' | |
210 | ||
211 | test_expect_success 'conditional include, both unanchored, icase' ' | |
212 | ( | |
213 | cd foo && | |
214 | echo "[includeIf \"gitdir/i:FOO/\"]path=bar5" >>.git/config && | |
215 | echo "[test]five=5" >.git/bar5 && | |
216 | echo 5 >expect && | |
217 | git config test.five >actual && | |
218 | test_cmp expect actual | |
219 | ) | |
220 | ' | |
221 | ||
2185fde5 NTND |
222 | test_expect_success 'conditional include, early config reading' ' |
223 | ( | |
224 | cd foo && | |
225 | echo "[includeIf \"gitdir:foo/\"]path=bar6" >>.git/config && | |
226 | echo "[test]six=6" >.git/bar6 && | |
227 | echo 6 >expect && | |
0e2678af | 228 | test-tool config read_early_config test.six >actual && |
2185fde5 NTND |
229 | test_cmp expect actual |
230 | ) | |
231 | ' | |
232 | ||
19e7fdaa NTND |
233 | test_expect_success 'conditional include with /**/' ' |
234 | REPO=foo/bar/repo && | |
235 | git init $REPO && | |
236 | cat >>$REPO/.git/config <<-\EOF && | |
237 | [includeIf "gitdir:**/foo/**/bar/**"] | |
238 | path=bar7 | |
239 | EOF | |
240 | echo "[test]seven=7" >$REPO/.git/bar7 && | |
241 | echo 7 >expect && | |
242 | git -C $REPO config test.seven >actual && | |
243 | test_cmp expect actual | |
244 | ' | |
245 | ||
86f95157 NTND |
246 | test_expect_success SYMLINKS 'conditional include, set up symlinked $HOME' ' |
247 | mkdir real-home && | |
248 | ln -s real-home home && | |
249 | ( | |
250 | HOME="$TRASH_DIRECTORY/home" && | |
251 | export HOME && | |
252 | cd "$HOME" && | |
253 | ||
254 | git init foo && | |
255 | cd foo && | |
256 | mkdir sub | |
257 | ) | |
258 | ' | |
259 | ||
260 | test_expect_success SYMLINKS 'conditional include, $HOME expansion with symlinks' ' | |
261 | ( | |
262 | HOME="$TRASH_DIRECTORY/home" && | |
263 | export HOME && | |
264 | cd "$HOME"/foo && | |
265 | ||
266 | echo "[includeIf \"gitdir:~/foo/\"]path=bar2" >>.git/config && | |
267 | echo "[test]two=2" >.git/bar2 && | |
268 | echo 2 >expect && | |
269 | force_setup_explicit_git_dir && | |
270 | git -C sub config test.two >actual && | |
271 | test_cmp expect actual | |
272 | ) | |
273 | ' | |
274 | ||
275 | test_expect_success SYMLINKS 'conditional include, relative path with symlinks' ' | |
276 | echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >home/.gitconfig && | |
277 | echo "[test]four=4" >home/bar4 && | |
278 | ( | |
279 | HOME="$TRASH_DIRECTORY/home" && | |
280 | export HOME && | |
281 | cd "$HOME"/foo && | |
282 | ||
283 | echo 4 >expect && | |
284 | force_setup_explicit_git_dir && | |
285 | git -C sub config test.four >actual && | |
286 | test_cmp expect actual | |
287 | ) | |
288 | ' | |
289 | ||
0624c63c ÆAB |
290 | test_expect_success SYMLINKS 'conditional include, gitdir matching symlink' ' |
291 | ln -s foo bar && | |
292 | ( | |
293 | cd bar && | |
294 | echo "[includeIf \"gitdir:bar/\"]path=bar7" >>.git/config && | |
295 | echo "[test]seven=7" >.git/bar7 && | |
296 | echo 7 >expect && | |
297 | git config test.seven >actual && | |
298 | test_cmp expect actual | |
299 | ) | |
300 | ' | |
301 | ||
302 | test_expect_success SYMLINKS 'conditional include, gitdir matching symlink, icase' ' | |
303 | ( | |
304 | cd bar && | |
305 | echo "[includeIf \"gitdir/i:BAR/\"]path=bar8" >>.git/config && | |
306 | echo "[test]eight=8" >.git/bar8 && | |
307 | echo 8 >expect && | |
308 | git config test.eight >actual && | |
309 | test_cmp expect actual | |
310 | ) | |
311 | ' | |
312 | ||
07b2c0ea DL |
313 | test_expect_success 'conditional include, onbranch' ' |
314 | echo "[includeIf \"onbranch:foo-branch\"]path=bar9" >>.git/config && | |
315 | echo "[test]nine=9" >.git/bar9 && | |
06d53148 | 316 | git checkout -b main && |
07b2c0ea DL |
317 | test_must_fail git config test.nine && |
318 | git checkout -b foo-branch && | |
319 | echo 9 >expect && | |
320 | git config test.nine >actual && | |
321 | test_cmp expect actual | |
322 | ' | |
323 | ||
324 | test_expect_success 'conditional include, onbranch, wildcard' ' | |
325 | echo "[includeIf \"onbranch:?oo-*/**\"]path=bar10" >>.git/config && | |
326 | echo "[test]ten=10" >.git/bar10 && | |
327 | git checkout -b not-foo-branch/a && | |
328 | test_must_fail git config test.ten && | |
329 | ||
330 | echo 10 >expect && | |
331 | git checkout -b foo-branch/a/b/c && | |
332 | git config test.ten >actual && | |
333 | test_cmp expect actual && | |
334 | ||
335 | git checkout -b moo-bar/a && | |
336 | git config test.ten >actual && | |
337 | test_cmp expect actual | |
338 | ' | |
339 | ||
340 | test_expect_success 'conditional include, onbranch, implicit /** for /' ' | |
341 | echo "[includeIf \"onbranch:foo-dir/\"]path=bar11" >>.git/config && | |
342 | echo "[test]eleven=11" >.git/bar11 && | |
343 | git checkout -b not-foo-dir/a && | |
344 | test_must_fail git config test.eleven && | |
345 | ||
346 | echo 11 >expect && | |
347 | git checkout -b foo-dir/a/b/c && | |
348 | git config test.eleven >actual && | |
349 | test_cmp expect actual | |
350 | ' | |
351 | ||
9b25a0b5 | 352 | test_expect_success 'include cycles are detected' ' |
84230835 ÆAB |
353 | git init --bare cycle && |
354 | git -C cycle config include.path cycle && | |
355 | git config -f cycle/cycle include.path config && | |
73c01d25 | 356 | test_must_fail git -C cycle config --get-all test.value 2>stderr && |
84230835 | 357 | grep "exceeded maximum include depth" stderr |
9b25a0b5 JK |
358 | ' |
359 | ||
360 | test_done |