Add more default aliases
[git] / t / t1305-config-include.sh
1 #!/bin/sh
2
3 test_description='test config file include directives'
4 . ./test-lib.sh
5
6 test_expect_success 'include file by absolute path' '
7         echo "[test]one = 1" >one &&
8         echo "[include]path = \"$(pwd)/one\"" >.gitconfig &&
9         echo 1 >expect &&
10         git config test.one >actual &&
11         test_cmp expect actual
12 '
13
14 test_expect_success 'include file by relative path' '
15         echo "[test]one = 1" >one &&
16         echo "[include]path = one" >.gitconfig &&
17         echo 1 >expect &&
18         git config test.one >actual &&
19         test_cmp expect actual
20 '
21
22 test_expect_success 'chained relative paths' '
23         mkdir subdir &&
24         echo "[test]three = 3" >subdir/three &&
25         echo "[include]path = three" >subdir/two &&
26         echo "[include]path = subdir/two" >.gitconfig &&
27         echo 3 >expect &&
28         git config test.three >actual &&
29         test_cmp expect actual
30 '
31
32 test_expect_success 'include paths get tilde-expansion' '
33         echo "[test]one = 1" >one &&
34         echo "[include]path = ~/one" >.gitconfig &&
35         echo 1 >expect &&
36         git config test.one >actual &&
37         test_cmp expect actual
38 '
39
40 test_expect_success 'include options can still be examined' '
41         echo "[test]one = 1" >one &&
42         echo "[include]path = one" >.gitconfig &&
43         echo one >expect &&
44         git config include.path >actual &&
45         test_cmp expect actual
46 '
47
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 &&
52         alias.ci=commit
53         alias.co=checkout
54         alias.rb=rebase
55         alias.st=status
56         alias.br=branch
57         alias.pi=cherry-pick
58         alias.mt=mergetool
59         include.path=one
60         test.one=1
61         EOF
62         git config --list >actual.full &&
63         grep -v ^core actual.full >actual &&
64         test_cmp expect actual
65 '
66
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 &&
72         echo 1 >expect &&
73         git config --includes -f .gitconfig test.one >actual &&
74         test_cmp expect actual
75 '
76
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
83 '
84
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 &&
89         echo 2 >expect &&
90         git config --no-includes test.two >actual &&
91         test_cmp expect actual &&
92         test_must_fail git config --no-includes test.one
93 '
94
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 &&
99         echo 1 >expect &&
100         git config -f one test.one >actual &&
101         test_cmp expect actual &&
102         cat >expect <<-\EOF &&
103         1
104         2
105         EOF
106         git config --get-all test.one >actual &&
107         test_cmp expect actual
108 '
109
110 test_expect_success 'missing include files are ignored' '
111         cat >.gitconfig <<-\EOF &&
112         [include]path = foo
113         [test]value = yes
114         EOF
115         echo yes >expect &&
116         git config test.value >actual &&
117         test_cmp expect actual
118 '
119
120 test_expect_success 'absolute includes from command line work' '
121         echo "[test]one = 1" >one &&
122         echo 1 >expect &&
123         git -c include.path="$(pwd)/one" config test.one >actual &&
124         test_cmp expect actual
125 '
126
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
130 '
131
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) &&
136         echo 1 >expect &&
137         git config --blob=$blob test.one >actual &&
138         test_cmp expect actual
139 '
140
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
146 '
147
148 test_expect_success 'absolute includes from stdin work' '
149         echo "[test]one = 1" >one &&
150         echo 1 >expect &&
151         echo "[include]path=\"$(pwd)/one\"" |
152         git config --file - test.one >actual &&
153         test_cmp expect actual
154 '
155
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
160 '
161
162 test_expect_success 'include cycles are detected' '
163         cat >.gitconfig <<-\EOF &&
164         [test]value = gitconfig
165         [include]path = cycle
166         EOF
167         cat >cycle <<-\EOF &&
168         [test]value = cycle
169         [include]path = .gitconfig
170         EOF
171         cat >expect <<-\EOF &&
172         gitconfig
173         cycle
174         EOF
175         test_must_fail git config --get-all test.value 2>stderr &&
176         grep "exceeded maximum include depth" stderr
177 '
178
179 test_done