717bf4de79518a647d5610e4f5c52d01d29b229a
[git.git] / t / t1300-config-set.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
5
6 test_description='Test git-config-set in different settings'
7
8 . ./test-lib.sh
9
10 test -f .git/config && rm .git/config
11
12 git-config-set core.penguin "little blue"
13
14 cat > expect << EOF
15 #
16 # This is the config file
17 #
18
19 [core]
20         penguin = little blue
21 EOF
22
23 test_expect_success 'initial' 'cmp .git/config expect'
24
25 git-config-set Core.Movie BadPhysics
26
27 cat > expect << EOF
28 #
29 # This is the config file
30 #
31
32 [core]
33         penguin = little blue
34         Movie = BadPhysics
35 EOF
36
37 test_expect_success 'mixed case' 'cmp .git/config expect'
38
39 git-config-set Cores.WhatEver Second
40
41 cat > expect << EOF
42 #
43 # This is the config file
44 #
45
46 [core]
47         penguin = little blue
48         Movie = BadPhysics
49 [Cores]
50         WhatEver = Second
51 EOF
52
53 test_expect_success 'similar section' 'cmp .git/config expect'
54
55 git-config-set CORE.UPPERCASE true
56
57 cat > expect << EOF
58 #
59 # This is the config file
60 #
61
62 [core]
63         penguin = little blue
64         Movie = BadPhysics
65         UPPERCASE = true
66 [Cores]
67         WhatEver = Second
68 EOF
69
70 test_expect_success 'similar section' 'cmp .git/config expect'
71
72 cat > .git/config << EOF
73 [beta] ; silly comment # another comment
74 noIndent= sillyValue ; 'nother silly comment
75
76 # empty line
77                 ; comment
78                 haha   ="beta" # last silly comment
79 haha = hello
80         haha = bello
81 [nextSection] noNewline = ouch
82 EOF
83
84 cp .git/config .git/config2
85
86 test_expect_success 'multiple unset' \
87         'git-config-set --unset-all beta.haha'
88
89 cat > expect << EOF
90 [beta] ; silly comment # another comment
91 noIndent= sillyValue ; 'nother silly comment
92
93 # empty line
94                 ; comment
95 [nextSection] noNewline = ouch
96 EOF
97
98 test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
99
100 mv .git/config2 .git/config
101
102 test_expect_success '--replace-all' \
103         'git-config-set --replace-all beta.haha gamma'
104
105 cat > expect << EOF
106 [beta] ; silly comment # another comment
107 noIndent= sillyValue ; 'nother silly comment
108
109 # empty line
110                 ; comment
111         haha = gamma
112 [nextSection] noNewline = ouch
113 EOF
114
115 test_expect_success 'all replaced' 'cmp .git/config expect'
116
117 git-config-set beta.haha alpha
118
119 cat > expect << EOF
120 [beta] ; silly comment # another comment
121 noIndent= sillyValue ; 'nother silly comment
122
123 # empty line
124                 ; comment
125         haha = alpha
126 [nextSection] noNewline = ouch
127 EOF
128
129 test_expect_success 'really mean test' 'cmp .git/config expect'
130
131 git-config-set nextsection.nonewline wow
132
133 cat > expect << EOF
134 [beta] ; silly comment # another comment
135 noIndent= sillyValue ; 'nother silly comment
136
137 # empty line
138                 ; comment
139         haha = alpha
140 [nextSection]
141         nonewline = wow
142 EOF
143
144 test_expect_success 'really really mean test' 'cmp .git/config expect'
145
146 test_expect_success 'get value' 'test alpha = $(git-config-set beta.haha)'
147 git-config-set --unset beta.haha
148
149 cat > expect << EOF
150 [beta] ; silly comment # another comment
151 noIndent= sillyValue ; 'nother silly comment
152
153 # empty line
154                 ; comment
155 [nextSection]
156         nonewline = wow
157 EOF
158
159 test_expect_success 'unset' 'cmp .git/config expect'
160
161 git-config-set nextsection.NoNewLine "wow2 for me" "for me$"
162
163 cat > expect << EOF
164 [beta] ; silly comment # another comment
165 noIndent= sillyValue ; 'nother silly comment
166
167 # empty line
168                 ; comment
169 [nextSection]
170         nonewline = wow
171         NoNewLine = wow2 for me
172 EOF
173
174 test_expect_success 'multivar' 'cmp .git/config expect'
175
176 test_expect_failure 'ambiguous get' \
177         'git-config-set --get nextsection.nonewline'
178
179 test_expect_success 'get multivar' \
180         'git-config-set --get-all nextsection.nonewline'
181
182 git-config-set nextsection.nonewline "wow3" "wow$"
183
184 cat > expect << EOF
185 [beta] ; silly comment # another comment
186 noIndent= sillyValue ; 'nother silly comment
187
188 # empty line
189                 ; comment
190 [nextSection]
191         nonewline = wow3
192         NoNewLine = wow2 for me
193 EOF
194
195 test_expect_success 'multivar replace' 'cmp .git/config expect'
196
197 test_expect_failure 'ambiguous value' 'git-config-set nextsection.nonewline'
198
199 test_expect_failure 'ambiguous unset' \
200         'git-config-set --unset nextsection.nonewline'
201
202 test_expect_failure 'invalid unset' \
203         'git-config-set --unset somesection.nonewline'
204
205 git-config-set --unset nextsection.nonewline "wow3$"
206
207 cat > expect << EOF
208 [beta] ; silly comment # another comment
209 noIndent= sillyValue ; 'nother silly comment
210
211 # empty line
212                 ; comment
213 [nextSection]
214         NoNewLine = wow2 for me
215 EOF
216
217 test_expect_success 'multivar unset' 'cmp .git/config expect'
218
219 test_expect_failure 'invalid key' 'git-config-set inval.2key blabla'
220
221 test_expect_success 'correct key' 'git-config-set 123456.a123 987'
222
223 test_done
224