3 test_description='test config file include directives'
6 test_expect_success 'include file by absolute path' '
7 echo "[test]one = 1" >one &&
8 echo "[include]path = \"$(pwd)/one\"" >.gitconfig &&
10 git config test.one >actual &&
11 test_cmp expect actual
14 test_expect_success 'include file by relative path' '
15 echo "[test]one = 1" >one &&
16 echo "[include]path = one" >.gitconfig &&
18 git config test.one >actual &&
19 test_cmp expect actual
22 test_expect_success 'chained relative paths' '
24 echo "[test]three = 3" >subdir/three &&
25 echo "[include]path = three" >subdir/two &&
26 echo "[include]path = subdir/two" >.gitconfig &&
28 git config test.three >actual &&
29 test_cmp expect actual
32 test_expect_success 'include paths get tilde-expansion' '
33 echo "[test]one = 1" >one &&
34 echo "[include]path = ~/one" >.gitconfig &&
36 git config test.one >actual &&
37 test_cmp expect actual
40 test_expect_success 'include options can still be examined' '
41 echo "[test]one = 1" >one &&
42 echo "[include]path = one" >.gitconfig &&
44 git config include.path >actual &&
45 test_cmp expect actual
48 test_expect_success 'listing includes option and expansion' '
49 echo "[test]one = 1" >one &&
50 echo "[include]path = one" >.gitconfig &&
51 cat >expect <<-\EOF &&
62 git config --list >actual.full &&
63 grep -v ^core actual.full >actual &&
64 test_cmp expect actual
67 test_expect_success 'single file lookup does not expand includes by default' '
68 echo "[test]one = 1" >one &&
69 echo "[include]path = one" >.gitconfig &&
70 test_must_fail git config -f .gitconfig test.one &&
71 test_must_fail git config --global test.one &&
73 git config --includes -f .gitconfig test.one >actual &&
74 test_cmp expect actual
77 test_expect_success 'single file list does not expand includes by default' '
78 echo "[test]one = 1" >one &&
79 echo "[include]path = one" >.gitconfig &&
80 echo "include.path=one" >expect &&
81 git config -f .gitconfig --list >actual &&
82 test_cmp expect actual
85 test_expect_success 'writing config file does not expand includes' '
86 echo "[test]one = 1" >one &&
87 echo "[include]path = one" >.gitconfig &&
88 git config test.two 2 &&
90 git config --no-includes test.two >actual &&
91 test_cmp expect actual &&
92 test_must_fail git config --no-includes test.one
95 test_expect_success 'config modification does not affect includes' '
96 echo "[test]one = 1" >one &&
97 echo "[include]path = one" >.gitconfig &&
98 git config test.one 2 &&
100 git config -f one test.one >actual &&
101 test_cmp expect actual &&
102 cat >expect <<-\EOF &&
106 git config --get-all test.one >actual &&
107 test_cmp expect actual
110 test_expect_success 'missing include files are ignored' '
111 cat >.gitconfig <<-\EOF &&
116 git config test.value >actual &&
117 test_cmp expect actual
120 test_expect_success 'absolute includes from command line work' '
121 echo "[test]one = 1" >one &&
123 git -c include.path="$(pwd)/one" config test.one >actual &&
124 test_cmp expect actual
127 test_expect_success 'relative includes from command line fail' '
128 echo "[test]one = 1" >one &&
129 test_must_fail git -c include.path=one config test.one
132 test_expect_success 'absolute includes from blobs work' '
133 echo "[test]one = 1" >one &&
134 echo "[include]path=$(pwd)/one" >blob &&
135 blob=$(git hash-object -w blob) &&
137 git config --blob=$blob test.one >actual &&
138 test_cmp expect actual
141 test_expect_success 'relative includes from blobs fail' '
142 echo "[test]one = 1" >one &&
143 echo "[include]path=one" >blob &&
144 blob=$(git hash-object -w blob) &&
145 test_must_fail git config --blob=$blob test.one
148 test_expect_success 'absolute includes from stdin work' '
149 echo "[test]one = 1" >one &&
151 echo "[include]path=\"$(pwd)/one\"" |
152 git config --file - test.one >actual &&
153 test_cmp expect actual
156 test_expect_success 'relative includes from stdin line fail' '
157 echo "[test]one = 1" >one &&
158 echo "[include]path=one" |
159 test_must_fail git config --file - test.one
162 test_expect_success 'include cycles are detected' '
163 cat >.gitconfig <<-\EOF &&
164 [test]value = gitconfig
165 [include]path = cycle
167 cat >cycle <<-\EOF &&
169 [include]path = .gitconfig
171 cat >expect <<-\EOF &&
175 test_must_fail git config --get-all test.value 2>stderr &&
176 grep "exceeded maximum include depth" stderr