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