Merge branch 'fc/master' into travis-ci
[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         include.path=one
57         test.one=1
58         EOF
59         git config --list >actual.full &&
60         grep -v ^core actual.full >actual &&
61         test_cmp expect actual
62 '
63
64 test_expect_success 'single file lookup does not expand includes by default' '
65         echo "[test]one = 1" >one &&
66         echo "[include]path = one" >.gitconfig &&
67         test_must_fail git config -f .gitconfig test.one &&
68         test_must_fail git config --global test.one &&
69         echo 1 >expect &&
70         git config --includes -f .gitconfig test.one >actual &&
71         test_cmp expect actual
72 '
73
74 test_expect_success 'single file list does not expand includes by default' '
75         echo "[test]one = 1" >one &&
76         echo "[include]path = one" >.gitconfig &&
77         echo "include.path=one" >expect &&
78         git config -f .gitconfig --list >actual &&
79         test_cmp expect actual
80 '
81
82 test_expect_success 'writing config file does not expand includes' '
83         echo "[test]one = 1" >one &&
84         echo "[include]path = one" >.gitconfig &&
85         git config test.two 2 &&
86         echo 2 >expect &&
87         git config --no-includes test.two >actual &&
88         test_cmp expect actual &&
89         test_must_fail git config --no-includes test.one
90 '
91
92 test_expect_success 'config modification does not affect includes' '
93         echo "[test]one = 1" >one &&
94         echo "[include]path = one" >.gitconfig &&
95         git config test.one 2 &&
96         echo 1 >expect &&
97         git config -f one test.one >actual &&
98         test_cmp expect actual &&
99         cat >expect <<-\EOF &&
100         1
101         2
102         EOF
103         git config --get-all test.one >actual &&
104         test_cmp expect actual
105 '
106
107 test_expect_success 'missing include files are ignored' '
108         cat >.gitconfig <<-\EOF &&
109         [include]path = foo
110         [test]value = yes
111         EOF
112         echo yes >expect &&
113         git config test.value >actual &&
114         test_cmp expect actual
115 '
116
117 test_expect_success 'absolute includes from command line work' '
118         echo "[test]one = 1" >one &&
119         echo 1 >expect &&
120         git -c include.path="$PWD/one" config test.one >actual &&
121         test_cmp expect actual
122 '
123
124 test_expect_success 'relative includes from command line fail' '
125         echo "[test]one = 1" >one &&
126         test_must_fail git -c include.path=one config test.one
127 '
128
129 test_expect_success 'include cycles are detected' '
130         cat >.gitconfig <<-\EOF &&
131         [test]value = gitconfig
132         [include]path = cycle
133         EOF
134         cat >cycle <<-\EOF &&
135         [test]value = cycle
136         [include]path = .gitconfig
137         EOF
138         cat >expect <<-\EOF &&
139         gitconfig
140         cycle
141         EOF
142         test_must_fail git config --get-all test.value 2>stderr &&
143         grep "exceeded maximum include depth" stderr
144 '
145
146 test_done