df89216b19f4320d84c6cd23f45943b11507d3b6
[git.git] / 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 [nextSection] noNewline = ouch
80 EOF
81
82 git-config-set beta.haha alpha
83
84 cat > expect << EOF
85 [beta] ; silly comment # another comment
86 noIndent= sillyValue ; 'nother silly comment
87
88 # empty line
89                 ; comment
90         haha = alpha
91 [nextSection] noNewline = ouch
92 EOF
93
94 test_expect_success 'really mean test' 'cmp .git/config expect'
95
96 git-config-set nextsection.nonewline wow
97
98 cat > expect << EOF
99 [beta] ; silly comment # another comment
100 noIndent= sillyValue ; 'nother silly comment
101
102 # empty line
103                 ; comment
104         haha = alpha
105 [nextSection]
106         nonewline = wow
107 EOF
108
109 test_expect_success 'really really mean test' 'cmp .git/config expect'
110
111 git-config-set beta.haha
112
113 cat > expect << EOF
114 [beta] ; silly comment # another comment
115 noIndent= sillyValue ; 'nother silly comment
116
117 # empty line
118                 ; comment
119 [nextSection]
120         nonewline = wow
121 EOF
122
123 test_expect_success 'unset' 'cmp .git/config expect'
124
125 git-config-set nextsection.NoNewLine "wow2 for me" "for me$"
126
127 cat > expect << EOF
128 [beta] ; silly comment # another comment
129 noIndent= sillyValue ; 'nother silly comment
130
131 # empty line
132                 ; comment
133 [nextSection]
134         nonewline = wow
135         NoNewLine = wow2 for me
136 EOF
137
138 test_expect_success 'multivar' 'cmp .git/config expect'
139
140 git-config-set nextsection.nonewline "wow3" "wow$"
141
142 cat > expect << EOF
143 [beta] ; silly comment # another comment
144 noIndent= sillyValue ; 'nother silly comment
145
146 # empty line
147                 ; comment
148 [nextSection]
149         nonewline = wow3
150         NoNewLine = wow2 for me
151 EOF
152
153 test_expect_success 'multivar replace' 'cmp .git/config expect'
154
155 test_expect_failure 'ambiguous unset' \
156         'git-config-set --unset nextsection.nonewline'
157
158 test_expect_failure 'invalid unset' \
159         'git-config-set --unset somesection.nonewline'
160
161 git-config-set --unset nextsection.nonewline "wow3$"
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 = wow2 for me
171 EOF
172
173 test_expect_success 'multivar unset' 'cmp .git/config expect'
174
175 test_expect_failure 'invalid key' 'git-config-set inval.2key blabla'
176
177 test_expect_success 'correct key' 'git-config-set 123456.a123 987'
178
179 test_done
180