3 # Copyright (c) 2005 Johannes Schindelin
6 test_description
='Test git config in different settings'
10 test -f .git
/config
&& rm .git
/config
12 git config core.penguin
"little blue"
19 test_expect_success
'initial' 'cmp .git/config expect'
21 git config Core.Movie BadPhysics
29 test_expect_success
'mixed case' 'cmp .git/config expect'
31 git config Cores.WhatEver Second
41 test_expect_success
'similar section' 'cmp .git/config expect'
43 git config CORE.UPPERCASE true
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'
72 test_expect_success
'non-match result' 'cmp .git/config expect'
74 cat > .git
/config
<<\EOF
82 test_expect_success
'unset with cont. lines' \
83 'git config --unset beta.baz'
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
99 haha ="beta" # last silly comment
102 [nextSection] noNewline = ouch
105 cp .git
/config .git
/config2
107 test_expect_success
'multiple unset' \
108 'git config --unset-all beta.haha'
111 [beta] ; silly comment # another comment
112 noIndent= sillyValue ; 'nother silly 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'
127 [beta] ; silly comment # another comment
128 noIndent= sillyValue ; 'nother silly comment
133 [nextSection] noNewline = ouch
136 test_expect_success
'all replaced' 'cmp .git/config expect'
138 git config beta.haha alpha
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
147 [nextSection] noNewline = ouch
150 test_expect_success
'really mean test' 'cmp .git/config expect'
152 git config nextsection.nonewline wow
155 [beta] ; silly comment # another comment
156 noIndent= sillyValue ; 'nother silly comment
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
171 [beta] ; silly comment # another comment
172 noIndent= sillyValue ; 'nother silly comment
180 test_expect_success
'unset' 'cmp .git/config expect'
182 git config nextsection.NoNewLine
"wow2 for me" "for me$"
185 [beta] ; silly comment # another comment
186 noIndent= sillyValue ; 'nother silly comment
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_success
'ambiguous get' '
204 ! git config --get nextsection.nonewline
207 test_expect_success
'get multivar' \
208 'git config --get-all nextsection.nonewline'
210 git config nextsection.nonewline
"wow3" "wow$"
213 [beta] ; silly comment # another comment
214 noIndent= sillyValue ; 'nother silly comment
220 NoNewLine = wow2 for me
223 test_expect_success
'multivar replace' 'cmp .git/config expect'
225 test_expect_success
'ambiguous value' '
226 ! git config nextsection.nonewline
229 test_expect_success
'ambiguous unset' '
230 ! git config --unset nextsection.nonewline
233 test_expect_success
'invalid unset' '
234 ! git config --unset somesection.nonewline
237 git config
--unset nextsection.nonewline
"wow3$"
240 [beta] ; silly comment # another comment
241 noIndent= sillyValue ; 'nother silly comment
246 NoNewLine = wow2 for me
249 test_expect_success
'multivar unset' 'cmp .git/config expect'
251 test_expect_success
'invalid key' '! git config inval.2key blabla'
253 test_expect_success
'correct key' 'git config 123456.a123 987'
255 test_expect_success
'hierarchical section' \
256 'git config Version.1.2.3eX.Alpha beta'
259 [beta] ; silly comment # another comment
260 noIndent= sillyValue ; 'nother silly comment
265 NoNewLine = wow2 for me
272 test_expect_success
'hierarchical section value' 'cmp .git/config expect'
275 beta.noindent=sillyValue
276 nextsection.nonewline=wow2 for me
278 version.1.2.3eX.alpha=beta
281 test_expect_success
'working --list' \
282 'git config --list > output && cmp output expect'
285 beta.noindent sillyValue
286 nextsection.nonewline wow2 for me
289 test_expect_success
'--get-regexp' \
290 'git config --get-regexp in > output && cmp output expect'
292 git config
--add nextsection.nonewline
"wow4 for you"
299 test_expect_success
'--add' \
300 'git config --get-all nextsection.nonewline > output && cmp output expect'
302 cat > .git
/config
<< EOF
309 test_expect_success
'get variable with no value' \
310 'git config --get novalue.variable ^$'
312 test_expect_success
'get variable with empty value' \
313 'git config --get emptyvalue.variable ^$'
315 echo novalue.variable
> expect
317 test_expect_success
'get-regexp variable with no value' \
318 'git config --get-regexp novalue > output &&
321 echo 'emptyvalue.variable ' > expect
323 test_expect_success
'get-regexp variable with empty value' \
324 'git config --get-regexp emptyvalue > output &&
329 test_expect_success
'get bool variable with no value' \
330 'git config --bool novalue.variable > output &&
335 test_expect_success
'get bool variable with empty value' \
336 'git config --bool emptyvalue.variable > output &&
339 git config
> output
2>&1
341 test_expect_success
'no arguments, but no crash' \
342 "test $? = 129 && grep usage output"
344 cat > .git
/config
<< EOF
358 test_expect_success
'new section is partial match of another' 'cmp .git/config expect'
373 test_expect_success
'new variable inserts into proper section' 'cmp .git/config expect'
375 test_expect_success
'alternative GIT_CONFIG (non-existing file should fail)' \
376 'git config --file non-existing-config -l; test $? != 0'
378 cat > other-config
<< EOF
387 GIT_CONFIG
=other-config git config
-l > output
389 test_expect_success
'alternative GIT_CONFIG' 'cmp output expect'
391 test_expect_success
'alternative GIT_CONFIG (--file)' \
392 'git config --file other-config -l > output && cmp output expect'
394 GIT_CONFIG
=other-config git config anwohner.park ausweis
403 test_expect_success
'--set in alternative GIT_CONFIG' 'cmp other-config expect'
405 cat > .git
/config
<< EOF
412 [branch "1 234 blabl/a"]
416 test_expect_success
"rename section" \
417 "git config --rename-section branch.eins branch.zwei"
426 [branch "1 234 blabl/a"]
430 test_expect_success
"rename succeeded" "git diff expect .git/config"
432 test_expect_success
"rename non-existing section" '
433 ! git config --rename-section branch."world domination" branch.drei
436 test_expect_success
"rename succeeded" "git diff expect .git/config"
438 test_expect_success
"rename another section" \
439 'git config --rename-section branch."1 234 blabl/a" branch.drei'
452 test_expect_success
"rename succeeded" "git diff expect .git/config"
454 cat >> .git
/config
<< EOF
455 [branch "zwei"] a = 1 [branch "vier"]
458 test_expect_success
"remove section" "git config --remove-section branch.zwei"
467 test_expect_success
"section was removed properly" \
468 "git diff -u expect .git/config"
475 dbname = %Ggitcvs2.%a.%m.sqlite
477 dbname = %Ggitcvs1.%a.%m.sqlite
480 test_expect_success
'section ending' '
482 git config gitcvs.enabled true &&
483 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
484 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
485 cmp .git/config expect
489 test_expect_success numbers
'
491 git config kilo.gram 1k &&
492 git config mega.ton 1m &&
493 k=$(git config --int --get kilo.gram) &&
494 test z1024 = "z$k" &&
495 m=$(git config --int --get mega.ton) &&
496 test z1048576 = "z$m"
500 fatal: bad config value for 'aninvalid.unit' in .git/config
503 test_expect_success
'invalid unit' '
505 git config aninvalid.unit "1auto" &&
506 s=$(git config aninvalid.unit) &&
507 test "z1auto" = "z$s" &&
508 if git config --int --get aninvalid.unit 2>actual
510 echo config should have failed
527 test_expect_success bool
'
529 git config bool.true1 01 &&
530 git config bool.true2 -1 &&
531 git config bool.true3 YeS &&
532 git config bool.true4 true &&
533 git config bool.false1 000 &&
534 git config bool.false2 "" &&
535 git config bool.false3 nO &&
536 git config bool.false4 FALSE &&
540 git config --bool --get bool.true$i >>result
541 git config --bool --get bool.false$i >>result
545 test_expect_success
'invalid bool (--get)' '
547 git config bool.nobool foobar &&
548 ! git config --bool --get bool.nobool'
550 test_expect_success
'invalid bool (set)' '
552 ! git config --bool bool.nobool foobar'
568 test_expect_success
'set --bool' '
570 git config --bool bool.true1 01 &&
571 git config --bool bool.true2 -1 &&
572 git config --bool bool.true3 YeS &&
573 git config --bool bool.true4 true &&
574 git config --bool bool.false1 000 &&
575 git config --bool bool.false2 "" &&
576 git config --bool bool.false3 nO &&
577 git config --bool bool.false4 FALSE &&
578 cmp expect .git/config'
589 test_expect_success
'set --int' '
591 git config --int int.val1 01 &&
592 git config --int int.val2 -1 &&
593 git config --int int.val3 5m &&
594 cmp expect .git/config'
598 git config quote.leading
" test"
599 git config quote.ending
"test "
600 git config quote.semicolon
"test;test"
601 git config quote.
hash "test#test"
607 semicolon = "test;test"
611 test_expect_success
'quoting' 'cmp .git/config expect'
613 test_expect_success
'key with newline' '
614 ! git config "key.with
617 test_expect_success
'value with newline' 'git config key.sub value.with\\\
620 cat > .git
/config
<<\EOF
625 noncont
= not continued
; \
631 section.continued
=continued
632 section.noncont
=not continued
633 section.quotecont
=cont
;inued
636 git config
--list > result
638 test_expect_success
'value continued on next line' 'cmp result expect'
640 cat > .git
/config
<<\EOF
641 [section
"sub=section"]
650 section.sub
=section.val1
651 foo
=barQsection.sub
=section.val2
653 barQsection.sub
=section.val3
656 Qsection.sub
=section.val4
657 Qsection.sub
=section.val5Q
660 git config
--null --list |
tr '\000' 'Q' > result
663 test_expect_success
'--null --list' 'cmp result expect'
665 git config
--null --get-regexp 'val[0-9]' |
tr '\000' 'Q' > result
668 test_expect_success
'--null --get-regexp' 'cmp result expect'
670 test_expect_success
'symlinked configuration' '
672 ln -s notyet myconfig &&
673 GIT_CONFIG=myconfig git config test.frotz nitfol &&
676 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
677 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
680 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
681 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov