config.c: guard config parser from value=NULL
[git/gitweb.git] / t / t1300-repo-config.sh
blob44dcc1f94f581660bcf04c75281d60466c95b0be
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 [alpha]
76 bar = foo
77 [beta]
78 baz = multiple \
79 lines
80 EOF
82 test_expect_success 'unset with cont. lines' \
83 'git config --unset beta.baz'
85 cat > expect <<\EOF
86 [alpha]
87 bar = foo
88 [beta]
89 EOF
91 test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
93 cat > .git/config << EOF
94 [beta] ; silly comment # another comment
95 noIndent= sillyValue ; 'nother silly comment
97 # empty line
98 ; comment
99 haha ="beta" # last silly comment
100 haha = hello
101 haha = bello
102 [nextSection] noNewline = ouch
105 cp .git/config .git/config2
107 test_expect_success 'multiple unset' \
108 'git config --unset-all beta.haha'
110 cat > expect << EOF
111 [beta] ; silly comment # another comment
112 noIndent= sillyValue ; 'nother silly comment
114 # empty line
115 ; comment
116 [nextSection] noNewline = ouch
119 test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
121 mv .git/config2 .git/config
123 test_expect_success '--replace-all' \
124 'git config --replace-all beta.haha gamma'
126 cat > expect << EOF
127 [beta] ; silly comment # another comment
128 noIndent= sillyValue ; 'nother silly comment
130 # empty line
131 ; comment
132 haha = gamma
133 [nextSection] noNewline = ouch
136 test_expect_success 'all replaced' 'cmp .git/config expect'
138 git config beta.haha alpha
140 cat > expect << EOF
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
144 # empty line
145 ; comment
146 haha = alpha
147 [nextSection] noNewline = ouch
150 test_expect_success 'really mean test' 'cmp .git/config expect'
152 git config nextsection.nonewline wow
154 cat > expect << EOF
155 [beta] ; silly comment # another comment
156 noIndent= sillyValue ; 'nother silly comment
158 # empty line
159 ; comment
160 haha = alpha
161 [nextSection]
162 nonewline = wow
165 test_expect_success 'really really mean test' 'cmp .git/config expect'
167 test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
168 git config --unset beta.haha
170 cat > expect << EOF
171 [beta] ; silly comment # another comment
172 noIndent= sillyValue ; 'nother silly comment
174 # empty line
175 ; comment
176 [nextSection]
177 nonewline = wow
180 test_expect_success 'unset' 'cmp .git/config expect'
182 git config nextsection.NoNewLine "wow2 for me" "for me$"
184 cat > expect << EOF
185 [beta] ; silly comment # another comment
186 noIndent= sillyValue ; 'nother silly comment
188 # empty line
189 ; comment
190 [nextSection]
191 nonewline = wow
192 NoNewLine = wow2 for me
195 test_expect_success 'multivar' 'cmp .git/config expect'
197 test_expect_success 'non-match' \
198 'git config --get nextsection.nonewline !for'
200 test_expect_success 'non-match value' \
201 'test wow = $(git config --get nextsection.nonewline !for)'
203 test_expect_failure 'ambiguous get' \
204 'git config --get nextsection.nonewline'
206 test_expect_success 'get multivar' \
207 'git config --get-all nextsection.nonewline'
209 git config nextsection.nonewline "wow3" "wow$"
211 cat > expect << EOF
212 [beta] ; silly comment # another comment
213 noIndent= sillyValue ; 'nother silly comment
215 # empty line
216 ; comment
217 [nextSection]
218 nonewline = wow3
219 NoNewLine = wow2 for me
222 test_expect_success 'multivar replace' 'cmp .git/config expect'
224 test_expect_failure 'ambiguous value' 'git config nextsection.nonewline'
226 test_expect_failure 'ambiguous unset' \
227 'git config --unset nextsection.nonewline'
229 test_expect_failure 'invalid unset' \
230 'git config --unset somesection.nonewline'
232 git config --unset nextsection.nonewline "wow3$"
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
244 test_expect_success 'multivar unset' 'cmp .git/config expect'
246 test_expect_failure 'invalid key' 'git config inval.2key blabla'
248 test_expect_success 'correct key' 'git config 123456.a123 987'
250 test_expect_success 'hierarchical section' \
251 'git config Version.1.2.3eX.Alpha beta'
253 cat > expect << EOF
254 [beta] ; silly comment # another comment
255 noIndent= sillyValue ; 'nother silly comment
257 # empty line
258 ; comment
259 [nextSection]
260 NoNewLine = wow2 for me
261 [123456]
262 a123 = 987
263 [Version "1.2.3eX"]
264 Alpha = beta
267 test_expect_success 'hierarchical section value' 'cmp .git/config expect'
269 cat > expect << EOF
270 beta.noindent=sillyValue
271 nextsection.nonewline=wow2 for me
272 123456.a123=987
273 version.1.2.3eX.alpha=beta
276 test_expect_success 'working --list' \
277 'git config --list > output && cmp output expect'
279 cat > expect << EOF
280 beta.noindent sillyValue
281 nextsection.nonewline wow2 for me
284 test_expect_success '--get-regexp' \
285 'git config --get-regexp in > output && cmp output expect'
287 git config --add nextsection.nonewline "wow4 for you"
289 cat > expect << EOF
290 wow2 for me
291 wow4 for you
294 test_expect_success '--add' \
295 'git config --get-all nextsection.nonewline > output && cmp output expect'
297 cat > .git/config << EOF
298 [novalue]
299 variable
302 test_expect_success 'get variable with no value' \
303 'git config --get novalue.variable ^$'
305 echo novalue.variable > expect
307 test_expect_success 'get-regexp variable with no value' \
308 'git config --get-regexp novalue > output &&
309 cmp output expect'
311 git config > output 2>&1
313 test_expect_success 'no arguments, but no crash' \
314 "test $? = 129 && grep usage output"
316 cat > .git/config << EOF
317 [a.b]
318 c = d
321 git config a.x y
323 cat > expect << EOF
324 [a.b]
325 c = d
327 x = y
330 test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
332 git config b.x y
333 git config a.b c
335 cat > expect << EOF
336 [a.b]
337 c = d
339 x = y
340 b = c
342 x = y
345 test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
347 test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
348 'git config --file non-existing-config -l; test $? != 0'
350 cat > other-config << EOF
351 [ein]
352 bahn = strasse
355 cat > expect << EOF
356 ein.bahn=strasse
359 GIT_CONFIG=other-config git config -l > output
361 test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
363 test_expect_success 'alternative GIT_CONFIG (--file)' \
364 'git config --file other-config -l > output && cmp output expect'
366 GIT_CONFIG=other-config git config anwohner.park ausweis
368 cat > expect << EOF
369 [ein]
370 bahn = strasse
371 [anwohner]
372 park = ausweis
375 test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
377 cat > .git/config << EOF
378 # Hallo
379 #Bello
380 [branch "eins"]
381 x = 1
382 [branch.eins]
383 y = 1
384 [branch "1 234 blabl/a"]
385 weird
388 test_expect_success "rename section" \
389 "git config --rename-section branch.eins branch.zwei"
391 cat > expect << EOF
392 # Hallo
393 #Bello
394 [branch "zwei"]
395 x = 1
396 [branch "zwei"]
397 y = 1
398 [branch "1 234 blabl/a"]
399 weird
402 test_expect_success "rename succeeded" "git diff expect .git/config"
404 test_expect_failure "rename non-existing section" \
405 'git config --rename-section branch."world domination" branch.drei'
407 test_expect_success "rename succeeded" "git diff expect .git/config"
409 test_expect_success "rename another section" \
410 'git config --rename-section branch."1 234 blabl/a" branch.drei'
412 cat > expect << EOF
413 # Hallo
414 #Bello
415 [branch "zwei"]
416 x = 1
417 [branch "zwei"]
418 y = 1
419 [branch "drei"]
420 weird
423 test_expect_success "rename succeeded" "git diff expect .git/config"
425 cat >> .git/config << EOF
426 [branch "zwei"] a = 1 [branch "vier"]
429 test_expect_success "remove section" "git config --remove-section branch.zwei"
431 cat > expect << EOF
432 # Hallo
433 #Bello
434 [branch "drei"]
435 weird
438 test_expect_success "section was removed properly" \
439 "git diff -u expect .git/config"
441 rm .git/config
443 cat > expect << EOF
444 [gitcvs]
445 enabled = true
446 dbname = %Ggitcvs2.%a.%m.sqlite
447 [gitcvs "ext"]
448 dbname = %Ggitcvs1.%a.%m.sqlite
451 test_expect_success 'section ending' '
453 git config gitcvs.enabled true &&
454 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
455 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
456 cmp .git/config expect
460 test_expect_success numbers '
462 git config kilo.gram 1k &&
463 git config mega.ton 1m &&
464 k=$(git config --int --get kilo.gram) &&
465 test z1024 = "z$k" &&
466 m=$(git config --int --get mega.ton) &&
467 test z1048576 = "z$m"
470 cat > expect <<EOF
471 fatal: bad config value for 'aninvalid.unit' in .git/config
474 test_expect_success 'invalid unit' '
476 git config aninvalid.unit "1auto" &&
477 s=$(git config aninvalid.unit) &&
478 test "z1auto" = "z$s" &&
479 if git config --int --get aninvalid.unit 2>actual
480 then
481 echo config should have failed
482 false
483 fi &&
484 cmp actual expect
487 cat > expect << EOF
488 true
489 false
490 true
491 false
492 true
493 false
494 true
495 false
498 test_expect_success bool '
500 git config bool.true1 01 &&
501 git config bool.true2 -1 &&
502 git config bool.true3 YeS &&
503 git config bool.true4 true &&
504 git config bool.false1 000 &&
505 git config bool.false2 "" &&
506 git config bool.false3 nO &&
507 git config bool.false4 FALSE &&
508 rm -f result &&
509 for i in 1 2 3 4
511 git config --bool --get bool.true$i >>result
512 git config --bool --get bool.false$i >>result
513 done &&
514 cmp expect result'
516 test_expect_failure 'invalid bool (--get)' '
518 git config bool.nobool foobar &&
519 git config --bool --get bool.nobool'
521 test_expect_failure 'invalid bool (set)' '
523 git config --bool bool.nobool foobar'
525 rm .git/config
527 cat > expect <<\EOF
528 [bool]
529 true1 = true
530 true2 = true
531 true3 = true
532 true4 = true
533 false1 = false
534 false2 = false
535 false3 = false
536 false4 = false
539 test_expect_success 'set --bool' '
541 git config --bool bool.true1 01 &&
542 git config --bool bool.true2 -1 &&
543 git config --bool bool.true3 YeS &&
544 git config --bool bool.true4 true &&
545 git config --bool bool.false1 000 &&
546 git config --bool bool.false2 "" &&
547 git config --bool bool.false3 nO &&
548 git config --bool bool.false4 FALSE &&
549 cmp expect .git/config'
551 rm .git/config
553 cat > expect <<\EOF
554 [int]
555 val1 = 1
556 val2 = -1
557 val3 = 5242880
560 test_expect_success 'set --int' '
562 git config --int int.val1 01 &&
563 git config --int int.val2 -1 &&
564 git config --int int.val3 5m &&
565 cmp expect .git/config'
567 rm .git/config
569 git config quote.leading " test"
570 git config quote.ending "test "
571 git config quote.semicolon "test;test"
572 git config quote.hash "test#test"
574 cat > expect << EOF
575 [quote]
576 leading = " test"
577 ending = "test "
578 semicolon = "test;test"
579 hash = "test#test"
582 test_expect_success 'quoting' 'cmp .git/config expect'
584 test_expect_failure 'key with newline' 'git config key.with\\\
585 newline 123'
587 test_expect_success 'value with newline' 'git config key.sub value.with\\\
588 newline'
590 cat > .git/config <<\EOF
591 [section]
592 ; comment \
593 continued = cont\
594 inued
595 noncont = not continued ; \
596 quotecont = "cont;\
597 inued"
600 cat > expect <<\EOF
601 section.continued=continued
602 section.noncont=not continued
603 section.quotecont=cont;inued
606 git config --list > result
608 test_expect_success 'value continued on next line' 'cmp result expect'
610 cat > .git/config <<\EOF
611 [section "sub=section"]
612 val1 = foo=bar
613 val2 = foo\nbar
614 val3 = \n\n
615 val4 =
616 val5
619 cat > expect <<\EOF
620 section.sub=section.val1
621 foo=barQsection.sub=section.val2
623 barQsection.sub=section.val3
626 Qsection.sub=section.val4
627 Qsection.sub=section.val5Q
630 git config --null --list | tr '\000' 'Q' > result
631 echo >>result
633 test_expect_success '--null --list' 'cmp result expect'
635 git config --null --get-regexp 'val[0-9]' | tr '\000' 'Q' > result
636 echo >>result
638 test_expect_success '--null --get-regexp' 'cmp result expect'
640 test_expect_success 'symlinked configuration' '
642 ln -s notyet myconfig &&
643 GIT_CONFIG=myconfig git config test.frotz nitfol &&
644 test -h myconfig &&
645 test -f notyet &&
646 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
647 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
648 test -h myconfig &&
649 test -f notyet &&
650 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
651 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
655 test_done