Merge branch 'fl/config'
[git/jrn.git] / t / t1300-repo-config.sh
bloba2c11c4639a9e611c305b9eb2abb63099dbac1ef
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 echo novalue.variable > expect
288 test_expect_success 'get-regexp variable with no value' \
289 'git-config --get-regexp novalue > output &&
290 cmp output expect'
292 git-config > output 2>&1
294 test_expect_success 'no arguments, but no crash' \
295 "test $? = 129 && grep usage output"
297 cat > .git/config << EOF
298 [a.b]
299 c = d
302 git-config a.x y
304 cat > expect << EOF
305 [a.b]
306 c = d
308 x = y
311 test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
313 git-config b.x y
314 git-config a.b c
316 cat > expect << EOF
317 [a.b]
318 c = d
320 x = y
321 b = c
323 x = y
326 test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
328 cat > other-config << EOF
329 [ein]
330 bahn = strasse
333 cat > expect << EOF
334 ein.bahn=strasse
337 GIT_CONFIG=other-config git-config -l > output
339 test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
341 GIT_CONFIG=other-config git-config anwohner.park ausweis
343 cat > expect << EOF
344 [ein]
345 bahn = strasse
346 [anwohner]
347 park = ausweis
350 test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
352 cat > .git/config << EOF
353 # Hallo
354 #Bello
355 [branch "eins"]
356 x = 1
357 [branch.eins]
358 y = 1
359 [branch "1 234 blabl/a"]
360 weird
363 test_expect_success "rename section" \
364 "git-config --rename-section branch.eins branch.zwei"
366 cat > expect << EOF
367 # Hallo
368 #Bello
369 [branch "zwei"]
370 x = 1
371 [branch "zwei"]
372 y = 1
373 [branch "1 234 blabl/a"]
374 weird
377 test_expect_success "rename succeeded" "git diff expect .git/config"
379 test_expect_failure "rename non-existing section" \
380 'git-config --rename-section branch."world domination" branch.drei'
382 test_expect_success "rename succeeded" "git diff expect .git/config"
384 test_expect_success "rename another section" \
385 'git-config --rename-section branch."1 234 blabl/a" branch.drei'
387 cat > expect << EOF
388 # Hallo
389 #Bello
390 [branch "zwei"]
391 x = 1
392 [branch "zwei"]
393 y = 1
394 [branch "drei"]
395 weird
398 test_expect_success "rename succeeded" "git diff expect .git/config"
400 cat >> .git/config << EOF
401 [branch "zwei"] a = 1 [branch "vier"]
404 test_expect_success "remove section" "git config --remove-section branch.zwei"
406 cat > expect << EOF
407 # Hallo
408 #Bello
409 [branch "drei"]
410 weird
413 test_expect_success "section was removed properly" \
414 "git diff -u expect .git/config"
416 rm .git/config
418 cat > expect << EOF
419 [gitcvs]
420 enabled = true
421 dbname = %Ggitcvs2.%a.%m.sqlite
422 [gitcvs "ext"]
423 dbname = %Ggitcvs1.%a.%m.sqlite
426 test_expect_success 'section ending' '
428 git-config gitcvs.enabled true &&
429 git-config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
430 git-config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
431 cmp .git/config expect
435 test_expect_success numbers '
437 git-config kilo.gram 1k &&
438 git-config mega.ton 1m &&
439 k=$(git-config --int --get kilo.gram) &&
440 test z1024 = "z$k" &&
441 m=$(git-config --int --get mega.ton) &&
442 test z1048576 = "z$m"
445 cat > expect << EOF
446 true
447 false
448 true
449 false
450 true
451 false
452 true
453 false
456 test_expect_success bool '
458 git-config bool.true1 01 &&
459 git-config bool.true2 -1 &&
460 git-config bool.true3 YeS &&
461 git-config bool.true4 true &&
462 git-config bool.false1 000 &&
463 git-config bool.false2 "" &&
464 git-config bool.false3 nO &&
465 git-config bool.false4 FALSE &&
466 rm -f result &&
467 for i in 1 2 3 4
469 git-config --bool --get bool.true$i >>result
470 git-config --bool --get bool.false$i >>result
471 done &&
472 cmp expect result'
474 test_expect_failure 'invalid bool (--get)' '
476 git-config bool.nobool foobar &&
477 git-config --bool --get bool.nobool'
479 test_expect_failure 'invalid bool (set)' '
481 git-config --bool bool.nobool foobar'
483 rm .git/config
485 cat > expect <<\EOF
486 [bool]
487 true1 = true
488 true2 = true
489 true3 = true
490 true4 = true
491 false1 = false
492 false2 = false
493 false3 = false
494 false4 = false
497 test_expect_success 'set --bool' '
499 git-config --bool bool.true1 01 &&
500 git-config --bool bool.true2 -1 &&
501 git-config --bool bool.true3 YeS &&
502 git-config --bool bool.true4 true &&
503 git-config --bool bool.false1 000 &&
504 git-config --bool bool.false2 "" &&
505 git-config --bool bool.false3 nO &&
506 git-config --bool bool.false4 FALSE &&
507 cmp expect .git/config'
509 rm .git/config
511 cat > expect <<\EOF
512 [int]
513 val1 = 1
514 val2 = -1
515 val3 = 5242880
518 test_expect_success 'set --int' '
520 git-config --int int.val1 01 &&
521 git-config --int int.val2 -1 &&
522 git-config --int int.val3 5m &&
523 cmp expect .git/config'
525 rm .git/config
527 git-config quote.leading " test"
528 git-config quote.ending "test "
529 git-config quote.semicolon "test;test"
530 git-config quote.hash "test#test"
532 cat > expect << EOF
533 [quote]
534 leading = " test"
535 ending = "test "
536 semicolon = "test;test"
537 hash = "test#test"
540 test_expect_success 'quoting' 'cmp .git/config expect'
542 test_expect_failure 'key with newline' 'git config key.with\\\
543 newline 123'
545 test_expect_success 'value with newline' 'git config key.sub value.with\\\
546 newline'
548 cat > .git/config <<\EOF
549 [section]
550 ; comment \
551 continued = cont\
552 inued
553 noncont = not continued ; \
554 quotecont = "cont;\
555 inued"
558 cat > expect <<\EOF
559 section.continued=continued
560 section.noncont=not continued
561 section.quotecont=cont;inued
564 git config --list > result
566 test_expect_success 'value continued on next line' 'cmp result expect'
568 cat > .git/config <<\EOF
569 [section "sub=section"]
570 val1 = foo=bar
571 val2 = foo\nbar
572 val3 = \n\n
573 val4 =
574 val5
577 cat > expect <<\EOF
578 section.sub=section.val1
579 foo=barQsection.sub=section.val2
581 barQsection.sub=section.val3
584 Qsection.sub=section.val4
585 Qsection.sub=section.val5Q
588 git config --null --list | tr '[\000]' 'Q' > result
589 echo >>result
591 test_expect_success '--null --list' 'cmp result expect'
593 git config --null --get-regexp 'val[0-9]' | tr '[\000]' 'Q' > result
594 echo >>result
596 test_expect_success '--null --get-regexp' 'cmp result expect'
598 test_done