unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t1305-config-include.sh
blob5cde79ef8c4fa34b61eba75f98e827f05e2a27ab
1 #!/bin/sh
3 test_description='test config file include directives'
4 TEST_PASSES_SANITIZE_LEAK=true
5 . ./test-lib.sh
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
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
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
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
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
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
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 &&
67 grep -v -e ^core -e ^extensions actual.full >actual &&
68 test_cmp expect actual
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
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
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
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 &&
110 git config --get-all test.one >actual &&
111 test_cmp expect actual
114 test_expect_success 'missing include files are ignored' '
115 cat >.gitconfig <<-\EOF &&
116 [include]path = non-existent
117 [test]value = yes
119 echo yes >expect &&
120 git config test.value >actual &&
121 test_cmp expect actual
124 test_expect_success 'absolute includes from command line work' '
125 echo "[test]one = 1" >one &&
126 echo 1 >expect &&
127 git -c include.path="$(pwd)/one" config test.one >actual &&
128 test_cmp expect actual
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
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
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
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
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
166 test_expect_success 'conditional include, both unanchored' '
167 git init foo &&
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
178 test_expect_success 'conditional include, $HOME expansion' '
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
189 test_expect_success 'conditional include, full pattern' '
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
200 test_expect_success 'conditional include, relative path' '
201 echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >>.gitconfig &&
202 echo "[test]four=4" >bar4 &&
204 cd foo &&
205 echo 4 >expect &&
206 git config test.four >actual &&
207 test_cmp expect actual
211 test_expect_success 'conditional include, both unanchored, icase' '
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
222 test_expect_success 'conditional include, early config reading' '
224 cd foo &&
225 echo "[includeIf \"gitdir:foo/\"]path=bar6" >>.git/config &&
226 echo "[test]six=6" >.git/bar6 &&
227 echo 6 >expect &&
228 test-tool config read_early_config test.six >actual &&
229 test_cmp expect actual
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
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
246 test_expect_success SYMLINKS 'conditional include, set up symlinked $HOME' '
247 mkdir real-home &&
248 ln -s real-home home &&
250 HOME="$TRASH_DIRECTORY/home" &&
251 export HOME &&
252 cd "$HOME" &&
254 git init foo &&
255 cd foo &&
256 mkdir sub
260 test_expect_success SYMLINKS 'conditional include, $HOME expansion with symlinks' '
262 HOME="$TRASH_DIRECTORY/home" &&
263 export HOME &&
264 cd "$HOME"/foo &&
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
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 &&
279 HOME="$TRASH_DIRECTORY/home" &&
280 export HOME &&
281 cd "$HOME"/foo &&
283 echo 4 >expect &&
284 force_setup_explicit_git_dir &&
285 git -C sub config test.four >actual &&
286 test_cmp expect actual
290 test_expect_success SYMLINKS 'conditional include, gitdir matching symlink' '
291 ln -s foo bar &&
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
302 test_expect_success SYMLINKS 'conditional include, gitdir matching symlink, icase' '
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
313 test_expect_success 'conditional include, onbranch' '
314 echo "[includeIf \"onbranch:foo-branch\"]path=bar9" >>.git/config &&
315 echo "[test]nine=9" >.git/bar9 &&
316 git checkout -b main &&
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
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 &&
330 echo 10 >expect &&
331 git checkout -b foo-branch/a/b/c &&
332 git config test.ten >actual &&
333 test_cmp expect actual &&
335 git checkout -b moo-bar/a &&
336 git config test.ten >actual &&
337 test_cmp expect actual
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 &&
346 echo 11 >expect &&
347 git checkout -b foo-dir/a/b/c &&
348 git config test.eleven >actual &&
349 test_cmp expect actual
352 test_expect_success 'include cycles are detected' '
353 git init --bare cycle &&
354 git -C cycle config include.path cycle &&
355 git config -f cycle/cycle include.path config &&
356 test_must_fail git -C cycle config --get-all test.value 2>stderr &&
357 grep "exceeded maximum include depth" stderr
360 test_done