War on whitespace
[git/jnareb-git/bp-gitweb.git] / t / t1300-repo-config.sh
blob7731fa72ceef16ba85b3ce4dcf1c21630f81f634
1 #!/bin/sh
3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test git-config in different settings'
8 . ./test-lib.sh
10 test -f .git/config && rm .git/config
12 git-config core.penguin "little blue"
14 cat > expect << EOF
15 [core]
16 penguin = little blue
17 EOF
19 test_expect_success 'initial' 'cmp .git/config expect'
21 git-config Core.Movie BadPhysics
23 cat > expect << EOF
24 [core]
25 penguin = little blue
26 Movie = BadPhysics
27 EOF
29 test_expect_success 'mixed case' 'cmp .git/config expect'
31 git-config Cores.WhatEver Second
33 cat > expect << EOF
34 [core]
35 penguin = little blue
36 Movie = BadPhysics
37 [Cores]
38 WhatEver = Second
39 EOF
41 test_expect_success 'similar section' 'cmp .git/config expect'
43 git-config CORE.UPPERCASE true
45 cat > expect << EOF
46 [core]
47 penguin = little blue
48 Movie = BadPhysics
49 UPPERCASE = true
50 [Cores]
51 WhatEver = Second
52 EOF
54 test_expect_success 'similar section' 'cmp .git/config expect'
56 test_expect_success 'replace with non-match' \
57 'git-config core.penguin kingpin !blue'
59 test_expect_success 'replace with non-match (actually matching)' \
60 'git-config core.penguin "very blue" !kingpin'
62 cat > expect << EOF
63 [core]
64 penguin = very blue
65 Movie = BadPhysics
66 UPPERCASE = true
67 penguin = kingpin
68 [Cores]
69 WhatEver = Second
70 EOF
72 test_expect_success 'non-match result' 'cmp .git/config expect'
74 cat > .git/config << EOF
75 [beta] ; silly comment # another comment
76 noIndent= sillyValue ; 'nother silly comment
78 # empty line
79 ; comment
80 haha ="beta" # last silly comment
81 haha = hello
82 haha = bello
83 [nextSection] noNewline = ouch
84 EOF
86 cp .git/config .git/config2
88 test_expect_success 'multiple unset' \
89 'git-config --unset-all beta.haha'
91 cat > expect << EOF
92 [beta] ; silly comment # another comment
93 noIndent= sillyValue ; 'nother silly comment
95 # empty line
96 ; comment
97 [nextSection] noNewline = ouch
98 EOF
100 test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
102 mv .git/config2 .git/config
104 test_expect_success '--replace-all' \
105 'git-config --replace-all beta.haha gamma'
107 cat > expect << EOF
108 [beta] ; silly comment # another comment
109 noIndent= sillyValue ; 'nother silly comment
111 # empty line
112 ; comment
113 haha = gamma
114 [nextSection] noNewline = ouch
117 test_expect_success 'all replaced' 'cmp .git/config expect'
119 git-config beta.haha alpha
121 cat > expect << EOF
122 [beta] ; silly comment # another comment
123 noIndent= sillyValue ; 'nother silly comment
125 # empty line
126 ; comment
127 haha = alpha
128 [nextSection] noNewline = ouch
131 test_expect_success 'really mean test' 'cmp .git/config expect'
133 git-config nextsection.nonewline wow
135 cat > expect << EOF
136 [beta] ; silly comment # another comment
137 noIndent= sillyValue ; 'nother silly comment
139 # empty line
140 ; comment
141 haha = alpha
142 [nextSection]
143 nonewline = wow
146 test_expect_success 'really really mean test' 'cmp .git/config expect'
148 test_expect_success 'get value' 'test alpha = $(git-config beta.haha)'
149 git-config --unset beta.haha
151 cat > expect << EOF
152 [beta] ; silly comment # another comment
153 noIndent= sillyValue ; 'nother silly comment
155 # empty line
156 ; comment
157 [nextSection]
158 nonewline = wow
161 test_expect_success 'unset' 'cmp .git/config expect'
163 git-config nextsection.NoNewLine "wow2 for me" "for me$"
165 cat > expect << EOF
166 [beta] ; silly comment # another comment
167 noIndent= sillyValue ; 'nother silly comment
169 # empty line
170 ; comment
171 [nextSection]
172 nonewline = wow
173 NoNewLine = wow2 for me
176 test_expect_success 'multivar' 'cmp .git/config expect'
178 test_expect_success 'non-match' \
179 'git-config --get nextsection.nonewline !for'
181 test_expect_success 'non-match value' \
182 'test wow = $(git-config --get nextsection.nonewline !for)'
184 test_expect_failure 'ambiguous get' \
185 'git-config --get nextsection.nonewline'
187 test_expect_success 'get multivar' \
188 'git-config --get-all nextsection.nonewline'
190 git-config nextsection.nonewline "wow3" "wow$"
192 cat > expect << EOF
193 [beta] ; silly comment # another comment
194 noIndent= sillyValue ; 'nother silly comment
196 # empty line
197 ; comment
198 [nextSection]
199 nonewline = wow3
200 NoNewLine = wow2 for me
203 test_expect_success 'multivar replace' 'cmp .git/config expect'
205 test_expect_failure 'ambiguous value' 'git-config nextsection.nonewline'
207 test_expect_failure 'ambiguous unset' \
208 'git-config --unset nextsection.nonewline'
210 test_expect_failure 'invalid unset' \
211 'git-config --unset somesection.nonewline'
213 git-config --unset nextsection.nonewline "wow3$"
215 cat > expect << EOF
216 [beta] ; silly comment # another comment
217 noIndent= sillyValue ; 'nother silly comment
219 # empty line
220 ; comment
221 [nextSection]
222 NoNewLine = wow2 for me
225 test_expect_success 'multivar unset' 'cmp .git/config expect'
227 test_expect_failure 'invalid key' 'git-config inval.2key blabla'
229 test_expect_success 'correct key' 'git-config 123456.a123 987'
231 test_expect_success 'hierarchical section' \
232 'git-config Version.1.2.3eX.Alpha beta'
234 cat > expect << EOF
235 [beta] ; silly comment # another comment
236 noIndent= sillyValue ; 'nother silly comment
238 # empty line
239 ; comment
240 [nextSection]
241 NoNewLine = wow2 for me
242 [123456]
243 a123 = 987
244 [Version "1.2.3eX"]
245 Alpha = beta
248 test_expect_success 'hierarchical section value' 'cmp .git/config expect'
250 cat > expect << EOF
251 beta.noindent=sillyValue
252 nextsection.nonewline=wow2 for me
253 123456.a123=987
254 version.1.2.3eX.alpha=beta
257 test_expect_success 'working --list' \
258 'git-config --list > output && cmp output expect'
260 cat > expect << EOF
261 beta.noindent sillyValue
262 nextsection.nonewline wow2 for me
265 test_expect_success '--get-regexp' \
266 'git-config --get-regexp in > output && cmp output expect'
268 git-config --add nextsection.nonewline "wow4 for you"
270 cat > expect << EOF
271 wow2 for me
272 wow4 for you
275 test_expect_success '--add' \
276 'git-config --get-all nextsection.nonewline > output && cmp output expect'
278 cat > .git/config << EOF
279 [novalue]
280 variable
283 test_expect_success 'get variable with no value' \
284 'git-config --get novalue.variable ^$'
286 git-config > output 2>&1
288 test_expect_success 'no arguments, but no crash' \
289 "test $? = 129 && grep usage output"
291 cat > .git/config << EOF
292 [a.b]
293 c = d
296 git-config a.x y
298 cat > expect << EOF
299 [a.b]
300 c = d
302 x = y
305 test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
307 git-config b.x y
308 git-config a.b c
310 cat > expect << EOF
311 [a.b]
312 c = d
314 x = y
315 b = c
317 x = y
320 test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
322 cat > other-config << EOF
323 [ein]
324 bahn = strasse
327 cat > expect << EOF
328 ein.bahn=strasse
331 GIT_CONFIG=other-config git-config -l > output
333 test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
335 GIT_CONFIG=other-config git-config anwohner.park ausweis
337 cat > expect << EOF
338 [ein]
339 bahn = strasse
340 [anwohner]
341 park = ausweis
344 test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
346 cat > .git/config << EOF
347 # Hallo
348 #Bello
349 [branch "eins"]
350 x = 1
351 [branch.eins]
352 y = 1
353 [branch "1 234 blabl/a"]
354 weird
357 test_expect_success "rename section" \
358 "git-config --rename-section branch.eins branch.zwei"
360 cat > expect << EOF
361 # Hallo
362 #Bello
363 [branch "zwei"]
364 x = 1
365 [branch "zwei"]
366 y = 1
367 [branch "1 234 blabl/a"]
368 weird
371 test_expect_success "rename succeeded" "git diff expect .git/config"
373 test_expect_failure "rename non-existing section" \
374 'git-config --rename-section branch."world domination" branch.drei'
376 test_expect_success "rename succeeded" "git diff expect .git/config"
378 test_expect_success "rename another section" \
379 'git-config --rename-section branch."1 234 blabl/a" branch.drei'
381 cat > expect << EOF
382 # Hallo
383 #Bello
384 [branch "zwei"]
385 x = 1
386 [branch "zwei"]
387 y = 1
388 [branch "drei"]
389 weird
392 test_expect_success "rename succeeded" "git diff expect .git/config"
394 cat >> .git/config << EOF
395 [branch "zwei"] a = 1 [branch "vier"]
398 test_expect_success "remove section" "git config --remove-section branch.zwei"
400 cat > expect << EOF
401 # Hallo
402 #Bello
403 [branch "drei"]
404 weird
407 test_expect_success "section was removed properly" \
408 "git diff -u expect .git/config"
410 rm .git/config
412 cat > expect << EOF
413 [gitcvs]
414 enabled = true
415 dbname = %Ggitcvs2.%a.%m.sqlite
416 [gitcvs "ext"]
417 dbname = %Ggitcvs1.%a.%m.sqlite
420 test_expect_success 'section ending' '
422 git-config gitcvs.enabled true &&
423 git-config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
424 git-config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
425 cmp .git/config expect
429 test_expect_success numbers '
431 git-config kilo.gram 1k &&
432 git-config mega.ton 1m &&
433 k=$(git-config --int --get kilo.gram) &&
434 test z1024 = "z$k" &&
435 m=$(git-config --int --get mega.ton) &&
436 test z1048576 = "z$m"
439 cat > expect << EOF
440 true
441 false
442 true
443 false
444 true
445 false
446 true
447 false
450 test_expect_success bool '
452 git-config bool.true1 01 &&
453 git-config bool.true2 -1 &&
454 git-config bool.true3 YeS &&
455 git-config bool.true4 true &&
456 git-config bool.false1 000 &&
457 git-config bool.false2 "" &&
458 git-config bool.false3 nO &&
459 git-config bool.false4 FALSE &&
460 rm -f result &&
461 for i in 1 2 3 4
463 git-config --bool --get bool.true$i >>result
464 git-config --bool --get bool.false$i >>result
465 done &&
466 cmp expect result'
468 test_expect_failure 'invalid bool' '
470 git-config bool.nobool foobar &&
471 git-config --bool --get bool.nobool'
473 rm .git/config
475 git-config quote.leading " test"
476 git-config quote.ending "test "
477 git-config quote.semicolon "test;test"
478 git-config quote.hash "test#test"
480 cat > expect << EOF
481 [quote]
482 leading = " test"
483 ending = "test "
484 semicolon = "test;test"
485 hash = "test#test"
488 test_expect_success 'quoting' 'cmp .git/config expect'
490 test_expect_failure 'key with newline' 'git config key.with\\\
491 newline 123'
493 test_expect_success 'value with newline' 'git config key.sub value.with\\\
494 newline'
496 cat > .git/config <<\EOF
497 [section]
498 ; comment \
499 continued = cont\
500 inued
501 noncont = not continued ; \
502 quotecont = "cont;\
503 inued"
506 cat > expect <<\EOF
507 section.continued=continued
508 section.noncont=not continued
509 section.quotecont=cont;inued
512 git config --list > result
514 test_expect_success 'value continued on next line' 'cmp result expect'
516 test_done