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
75 [beta] ; silly comment # another comment
76 noIndent= sillyValue ; 'nother silly comment
80 haha ="beta" # last silly comment
83 [nextSection] noNewline = ouch
86 cp .git
/config .git
/config2
88 test_expect_success
'multiple unset' \
89 'git config --unset-all beta.haha'
92 [beta] ; silly comment # another comment
93 noIndent= sillyValue ; 'nother silly comment
97 [nextSection] noNewline = ouch
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'
108 [beta] ; silly comment # another comment
109 noIndent= sillyValue ; 'nother silly comment
114 [nextSection] noNewline = ouch
117 test_expect_success
'all replaced' 'cmp .git/config expect'
119 git config beta.haha alpha
122 [beta] ; silly comment # another comment
123 noIndent= sillyValue ; 'nother silly comment
128 [nextSection] noNewline = ouch
131 test_expect_success
'really mean test' 'cmp .git/config expect'
133 git config nextsection.nonewline wow
136 [beta] ; silly comment # another comment
137 noIndent= sillyValue ; 'nother silly comment
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
152 [beta] ; silly comment # another comment
153 noIndent= sillyValue ; 'nother silly comment
161 test_expect_success
'unset' 'cmp .git/config expect'
163 git config nextsection.NoNewLine
"wow2 for me" "for me$"
166 [beta] ; silly comment # another comment
167 noIndent= sillyValue ; 'nother silly comment
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$"
193 [beta] ; silly comment # another comment
194 noIndent= sillyValue ; 'nother silly comment
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$"
216 [beta] ; silly comment # another comment
217 noIndent= sillyValue ; 'nother silly comment
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'
235 [beta] ; silly comment # another comment
236 noIndent= sillyValue ; 'nother silly comment
241 NoNewLine = wow2 for me
248 test_expect_success
'hierarchical section value' 'cmp .git/config expect'
251 beta.noindent=sillyValue
252 nextsection.nonewline=wow2 for me
254 version.1.2.3eX.alpha=beta
257 test_expect_success
'working --list' \
258 'git config --list > output && cmp output expect'
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"
275 test_expect_success
'--add' \
276 'git config --get-all nextsection.nonewline > output && cmp output expect'
278 cat > .git
/config
<< EOF
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 &&
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
311 test_expect_success
'new section is partial match of another' 'cmp .git/config expect'
326 test_expect_success
'new variable inserts into proper section' 'cmp .git/config expect'
328 test_expect_success
'alternative GIT_CONFIG (non-existing file should fail)' \
329 'git config --file non-existing-config -l; test $? != 0'
331 cat > other-config
<< EOF
340 GIT_CONFIG
=other-config git config
-l > output
342 test_expect_success
'alternative GIT_CONFIG' 'cmp output expect'
344 test_expect_success
'alternative GIT_CONFIG (--file)' \
345 'git config --file other-config -l > output && cmp output expect'
347 GIT_CONFIG
=other-config git config anwohner.park ausweis
356 test_expect_success
'--set in alternative GIT_CONFIG' 'cmp other-config expect'
358 cat > .git
/config
<< EOF
365 [branch "1 234 blabl/a"]
369 test_expect_success
"rename section" \
370 "git config --rename-section branch.eins branch.zwei"
379 [branch "1 234 blabl/a"]
383 test_expect_success
"rename succeeded" "git diff expect .git/config"
385 test_expect_failure
"rename non-existing section" \
386 'git config --rename-section branch."world domination" branch.drei'
388 test_expect_success
"rename succeeded" "git diff expect .git/config"
390 test_expect_success
"rename another section" \
391 'git config --rename-section branch."1 234 blabl/a" branch.drei'
404 test_expect_success
"rename succeeded" "git diff expect .git/config"
406 cat >> .git
/config
<< EOF
407 [branch "zwei"] a = 1 [branch "vier"]
410 test_expect_success
"remove section" "git config --remove-section branch.zwei"
419 test_expect_success
"section was removed properly" \
420 "git diff -u expect .git/config"
427 dbname = %Ggitcvs2.%a.%m.sqlite
429 dbname = %Ggitcvs1.%a.%m.sqlite
432 test_expect_success
'section ending' '
434 git config gitcvs.enabled true &&
435 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
436 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
437 cmp .git/config expect
441 test_expect_success numbers
'
443 git config kilo.gram 1k &&
444 git config mega.ton 1m &&
445 k=$(git config --int --get kilo.gram) &&
446 test z1024 = "z$k" &&
447 m=$(git config --int --get mega.ton) &&
448 test z1048576 = "z$m"
452 fatal: bad config value for 'aninvalid.unit' in .git/config
455 test_expect_success
'invalid unit' '
457 git config aninvalid.unit "1auto" &&
458 s=$(git config aninvalid.unit) &&
459 test "z1auto" = "z$s" &&
460 if git config --int --get aninvalid.unit 2>actual
462 echo config should have failed
479 test_expect_success bool
'
481 git config bool.true1 01 &&
482 git config bool.true2 -1 &&
483 git config bool.true3 YeS &&
484 git config bool.true4 true &&
485 git config bool.false1 000 &&
486 git config bool.false2 "" &&
487 git config bool.false3 nO &&
488 git config bool.false4 FALSE &&
492 git config --bool --get bool.true$i >>result
493 git config --bool --get bool.false$i >>result
497 test_expect_failure
'invalid bool (--get)' '
499 git config bool.nobool foobar &&
500 git config --bool --get bool.nobool'
502 test_expect_failure
'invalid bool (set)' '
504 git config --bool bool.nobool foobar'
520 test_expect_success
'set --bool' '
522 git config --bool bool.true1 01 &&
523 git config --bool bool.true2 -1 &&
524 git config --bool bool.true3 YeS &&
525 git config --bool bool.true4 true &&
526 git config --bool bool.false1 000 &&
527 git config --bool bool.false2 "" &&
528 git config --bool bool.false3 nO &&
529 git config --bool bool.false4 FALSE &&
530 cmp expect .git/config'
541 test_expect_success
'set --int' '
543 git config --int int.val1 01 &&
544 git config --int int.val2 -1 &&
545 git config --int int.val3 5m &&
546 cmp expect .git/config'
550 git config quote.leading
" test"
551 git config quote.ending
"test "
552 git config quote.semicolon
"test;test"
553 git config quote.
hash "test#test"
559 semicolon = "test;test"
563 test_expect_success
'quoting' 'cmp .git/config expect'
565 test_expect_failure
'key with newline' 'git config key.with\\\
568 test_expect_success
'value with newline' 'git config key.sub value.with\\\
571 cat > .git
/config
<<\EOF
576 noncont
= not continued
; \
582 section.continued
=continued
583 section.noncont
=not continued
584 section.quotecont
=cont
;inued
587 git config
--list > result
589 test_expect_success
'value continued on next line' 'cmp result expect'
591 cat > .git
/config
<<\EOF
592 [section
"sub=section"]
601 section.sub
=section.val1
602 foo
=barQsection.sub
=section.val2
604 barQsection.sub
=section.val3
607 Qsection.sub
=section.val4
608 Qsection.sub
=section.val5Q
611 git config
--null --list |
tr '\000' 'Q' > result
614 test_expect_success
'--null --list' 'cmp result expect'
616 git config
--null --get-regexp 'val[0-9]' |
tr '\000' 'Q' > result
619 test_expect_success
'--null --get-regexp' 'cmp result expect'
621 test_expect_success
'symlinked configuration' '
623 ln -s notyet myconfig &&
624 GIT_CONFIG=myconfig git config test.frotz nitfol &&
627 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
628 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
631 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
632 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov