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_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$"
212 [beta] ; silly comment # another comment
213 noIndent= sillyValue ; 'nother silly comment
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$"
235 [beta] ; silly comment # another comment
236 noIndent= sillyValue ; 'nother silly comment
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'
254 [beta] ; silly comment # another comment
255 noIndent= sillyValue ; 'nother silly comment
260 NoNewLine = wow2 for me
267 test_expect_success
'hierarchical section value' 'cmp .git/config expect'
270 beta.noindent=sillyValue
271 nextsection.nonewline=wow2 for me
273 version.1.2.3eX.alpha=beta
276 test_expect_success
'working --list' \
277 'git config --list > output && cmp output expect'
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"
294 test_expect_success
'--add' \
295 'git config --get-all nextsection.nonewline > output && cmp output expect'
297 cat > .git
/config
<< EOF
304 test_expect_success
'get variable with no value' \
305 'git config --get novalue.variable ^$'
307 test_expect_success
'get variable with empty value' \
308 'git config --get emptyvalue.variable ^$'
310 echo novalue.variable
> expect
312 test_expect_success
'get-regexp variable with no value' \
313 'git config --get-regexp novalue > output &&
316 echo 'emptyvalue.variable ' > expect
318 test_expect_success
'get-regexp variable with empty value' \
319 'git config --get-regexp emptyvalue > output &&
324 test_expect_success
'get bool variable with no value' \
325 'git config --bool novalue.variable > output &&
330 test_expect_success
'get bool variable with empty value' \
331 'git config --bool emptyvalue.variable > output &&
334 git config
> output
2>&1
336 test_expect_success
'no arguments, but no crash' \
337 "test $? = 129 && grep usage output"
339 cat > .git
/config
<< EOF
353 test_expect_success
'new section is partial match of another' 'cmp .git/config expect'
368 test_expect_success
'new variable inserts into proper section' 'cmp .git/config expect'
370 test_expect_success
'alternative GIT_CONFIG (non-existing file should fail)' \
371 'git config --file non-existing-config -l; test $? != 0'
373 cat > other-config
<< EOF
382 GIT_CONFIG
=other-config git config
-l > output
384 test_expect_success
'alternative GIT_CONFIG' 'cmp output expect'
386 test_expect_success
'alternative GIT_CONFIG (--file)' \
387 'git config --file other-config -l > output && cmp output expect'
389 GIT_CONFIG
=other-config git config anwohner.park ausweis
398 test_expect_success
'--set in alternative GIT_CONFIG' 'cmp other-config expect'
400 cat > .git
/config
<< EOF
407 [branch "1 234 blabl/a"]
411 test_expect_success
"rename section" \
412 "git config --rename-section branch.eins branch.zwei"
421 [branch "1 234 blabl/a"]
425 test_expect_success
"rename succeeded" "git diff expect .git/config"
427 test_expect_failure
"rename non-existing section" \
428 'git config --rename-section branch."world domination" branch.drei'
430 test_expect_success
"rename succeeded" "git diff expect .git/config"
432 test_expect_success
"rename another section" \
433 'git config --rename-section branch."1 234 blabl/a" branch.drei'
446 test_expect_success
"rename succeeded" "git diff expect .git/config"
448 cat >> .git
/config
<< EOF
449 [branch "zwei"] a = 1 [branch "vier"]
452 test_expect_success
"remove section" "git config --remove-section branch.zwei"
461 test_expect_success
"section was removed properly" \
462 "git diff -u expect .git/config"
469 dbname = %Ggitcvs2.%a.%m.sqlite
471 dbname = %Ggitcvs1.%a.%m.sqlite
474 test_expect_success
'section ending' '
476 git config gitcvs.enabled true &&
477 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
478 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
479 cmp .git/config expect
483 test_expect_success numbers
'
485 git config kilo.gram 1k &&
486 git config mega.ton 1m &&
487 k=$(git config --int --get kilo.gram) &&
488 test z1024 = "z$k" &&
489 m=$(git config --int --get mega.ton) &&
490 test z1048576 = "z$m"
494 fatal: bad config value for 'aninvalid.unit' in .git/config
497 test_expect_success
'invalid unit' '
499 git config aninvalid.unit "1auto" &&
500 s=$(git config aninvalid.unit) &&
501 test "z1auto" = "z$s" &&
502 if git config --int --get aninvalid.unit 2>actual
504 echo config should have failed
521 test_expect_success bool
'
523 git config bool.true1 01 &&
524 git config bool.true2 -1 &&
525 git config bool.true3 YeS &&
526 git config bool.true4 true &&
527 git config bool.false1 000 &&
528 git config bool.false2 "" &&
529 git config bool.false3 nO &&
530 git config bool.false4 FALSE &&
534 git config --bool --get bool.true$i >>result
535 git config --bool --get bool.false$i >>result
539 test_expect_failure
'invalid bool (--get)' '
541 git config bool.nobool foobar &&
542 git config --bool --get bool.nobool'
544 test_expect_failure
'invalid bool (set)' '
546 git config --bool bool.nobool foobar'
562 test_expect_success
'set --bool' '
564 git config --bool bool.true1 01 &&
565 git config --bool bool.true2 -1 &&
566 git config --bool bool.true3 YeS &&
567 git config --bool bool.true4 true &&
568 git config --bool bool.false1 000 &&
569 git config --bool bool.false2 "" &&
570 git config --bool bool.false3 nO &&
571 git config --bool bool.false4 FALSE &&
572 cmp expect .git/config'
583 test_expect_success
'set --int' '
585 git config --int int.val1 01 &&
586 git config --int int.val2 -1 &&
587 git config --int int.val3 5m &&
588 cmp expect .git/config'
592 git config quote.leading
" test"
593 git config quote.ending
"test "
594 git config quote.semicolon
"test;test"
595 git config quote.
hash "test#test"
601 semicolon = "test;test"
605 test_expect_success
'quoting' 'cmp .git/config expect'
607 test_expect_failure
'key with newline' 'git config key.with\\\
610 test_expect_success
'value with newline' 'git config key.sub value.with\\\
613 cat > .git
/config
<<\EOF
618 noncont
= not continued
; \
624 section.continued
=continued
625 section.noncont
=not continued
626 section.quotecont
=cont
;inued
629 git config
--list > result
631 test_expect_success
'value continued on next line' 'cmp result expect'
633 cat > .git
/config
<<\EOF
634 [section
"sub=section"]
643 section.sub
=section.val1
644 foo
=barQsection.sub
=section.val2
646 barQsection.sub
=section.val3
649 Qsection.sub
=section.val4
650 Qsection.sub
=section.val5Q
653 git config
--null --list |
tr '\000' 'Q' > result
656 test_expect_success
'--null --list' 'cmp result expect'
658 git config
--null --get-regexp 'val[0-9]' |
tr '\000' 'Q' > result
661 test_expect_success
'--null --get-regexp' 'cmp result expect'
663 test_expect_success
'symlinked configuration' '
665 ln -s notyet myconfig &&
666 GIT_CONFIG=myconfig git config test.frotz nitfol &&
669 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
670 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
673 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
674 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov