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_success
'ambiguous get' '
185 ! git config --get nextsection.nonewline
188 test_expect_success
'get multivar' \
189 'git config --get-all nextsection.nonewline'
191 git config nextsection.nonewline
"wow3" "wow$"
194 [beta] ; silly comment # another comment
195 noIndent= sillyValue ; 'nother silly comment
201 NoNewLine = wow2 for me
204 test_expect_success
'multivar replace' 'cmp .git/config expect'
206 test_expect_success
'ambiguous value' '
207 ! git config nextsection.nonewline
210 test_expect_success
'ambiguous unset' '
211 ! git config --unset nextsection.nonewline
214 test_expect_success
'invalid unset' '
215 ! git config --unset somesection.nonewline
218 git config
--unset nextsection.nonewline
"wow3$"
221 [beta] ; silly comment # another comment
222 noIndent= sillyValue ; 'nother silly comment
227 NoNewLine = wow2 for me
230 test_expect_success
'multivar unset' 'cmp .git/config expect'
232 test_expect_success
'invalid key' '! git config inval.2key blabla'
234 test_expect_success
'correct key' 'git config 123456.a123 987'
236 test_expect_success
'hierarchical section' \
237 'git config Version.1.2.3eX.Alpha beta'
240 [beta] ; silly comment # another comment
241 noIndent= sillyValue ; 'nother silly comment
246 NoNewLine = wow2 for me
253 test_expect_success
'hierarchical section value' 'cmp .git/config expect'
256 beta.noindent=sillyValue
257 nextsection.nonewline=wow2 for me
259 version.1.2.3eX.alpha=beta
262 test_expect_success
'working --list' \
263 'git config --list > output && cmp output expect'
266 beta.noindent sillyValue
267 nextsection.nonewline wow2 for me
270 test_expect_success
'--get-regexp' \
271 'git config --get-regexp in > output && cmp output expect'
273 git config
--add nextsection.nonewline
"wow4 for you"
280 test_expect_success
'--add' \
281 'git config --get-all nextsection.nonewline > output && cmp output expect'
283 cat > .git
/config
<< EOF
290 test_expect_success
'get variable with no value' \
291 'git config --get novalue.variable ^$'
293 test_expect_success
'get variable with empty value' \
294 'git config --get emptyvalue.variable ^$'
296 echo novalue.variable
> expect
298 test_expect_success
'get-regexp variable with no value' \
299 'git config --get-regexp novalue > output &&
302 echo 'emptyvalue.variable ' > expect
304 test_expect_success
'get-regexp variable with empty value' \
305 'git config --get-regexp emptyvalue > output &&
310 test_expect_success
'get bool variable with no value' \
311 'git config --bool novalue.variable > output &&
316 test_expect_success
'get bool variable with empty value' \
317 'git config --bool emptyvalue.variable > output &&
320 git config
> output
2>&1
322 test_expect_success
'no arguments, but no crash' \
323 "test $? = 129 && grep usage output"
325 cat > .git
/config
<< EOF
339 test_expect_success
'new section is partial match of another' 'cmp .git/config expect'
354 test_expect_success
'new variable inserts into proper section' 'cmp .git/config expect'
356 test_expect_success
'alternative GIT_CONFIG (non-existing file should fail)' \
357 'git config --file non-existing-config -l; test $? != 0'
359 cat > other-config
<< EOF
368 GIT_CONFIG
=other-config git config
-l > output
370 test_expect_success
'alternative GIT_CONFIG' 'cmp output expect'
372 test_expect_success
'alternative GIT_CONFIG (--file)' \
373 'git config --file other-config -l > output && cmp output expect'
375 GIT_CONFIG
=other-config git config anwohner.park ausweis
384 test_expect_success
'--set in alternative GIT_CONFIG' 'cmp other-config expect'
386 cat > .git
/config
<< EOF
393 [branch "1 234 blabl/a"]
397 test_expect_success
"rename section" \
398 "git config --rename-section branch.eins branch.zwei"
407 [branch "1 234 blabl/a"]
411 test_expect_success
"rename succeeded" "git diff expect .git/config"
413 test_expect_success
"rename non-existing section" '
414 ! git config --rename-section branch."world domination" branch.drei
417 test_expect_success
"rename succeeded" "git diff expect .git/config"
419 test_expect_success
"rename another section" \
420 'git config --rename-section branch."1 234 blabl/a" branch.drei'
433 test_expect_success
"rename succeeded" "git diff expect .git/config"
435 cat >> .git
/config
<< EOF
436 [branch "zwei"] a = 1 [branch "vier"]
439 test_expect_success
"remove section" "git config --remove-section branch.zwei"
448 test_expect_success
"section was removed properly" \
449 "git diff -u expect .git/config"
456 dbname = %Ggitcvs2.%a.%m.sqlite
458 dbname = %Ggitcvs1.%a.%m.sqlite
461 test_expect_success
'section ending' '
463 git config gitcvs.enabled true &&
464 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
465 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
466 cmp .git/config expect
470 test_expect_success numbers
'
472 git config kilo.gram 1k &&
473 git config mega.ton 1m &&
474 k=$(git config --int --get kilo.gram) &&
475 test z1024 = "z$k" &&
476 m=$(git config --int --get mega.ton) &&
477 test z1048576 = "z$m"
481 fatal: bad config value for 'aninvalid.unit' in .git/config
484 test_expect_success
'invalid unit' '
486 git config aninvalid.unit "1auto" &&
487 s=$(git config aninvalid.unit) &&
488 test "z1auto" = "z$s" &&
489 if git config --int --get aninvalid.unit 2>actual
491 echo config should have failed
508 test_expect_success bool
'
510 git config bool.true1 01 &&
511 git config bool.true2 -1 &&
512 git config bool.true3 YeS &&
513 git config bool.true4 true &&
514 git config bool.false1 000 &&
515 git config bool.false2 "" &&
516 git config bool.false3 nO &&
517 git config bool.false4 FALSE &&
521 git config --bool --get bool.true$i >>result
522 git config --bool --get bool.false$i >>result
526 test_expect_success
'invalid bool (--get)' '
528 git config bool.nobool foobar &&
529 ! git config --bool --get bool.nobool'
531 test_expect_success
'invalid bool (set)' '
533 ! git config --bool bool.nobool foobar'
549 test_expect_success
'set --bool' '
551 git config --bool bool.true1 01 &&
552 git config --bool bool.true2 -1 &&
553 git config --bool bool.true3 YeS &&
554 git config --bool bool.true4 true &&
555 git config --bool bool.false1 000 &&
556 git config --bool bool.false2 "" &&
557 git config --bool bool.false3 nO &&
558 git config --bool bool.false4 FALSE &&
559 cmp expect .git/config'
570 test_expect_success
'set --int' '
572 git config --int int.val1 01 &&
573 git config --int int.val2 -1 &&
574 git config --int int.val3 5m &&
575 cmp expect .git/config'
579 git config quote.leading
" test"
580 git config quote.ending
"test "
581 git config quote.semicolon
"test;test"
582 git config quote.
hash "test#test"
588 semicolon = "test;test"
592 test_expect_success
'quoting' 'cmp .git/config expect'
594 test_expect_success
'key with newline' '
595 ! git config "key.with
598 test_expect_success
'value with newline' 'git config key.sub value.with\\\
601 cat > .git
/config
<<\EOF
606 noncont
= not continued
; \
612 section.continued
=continued
613 section.noncont
=not continued
614 section.quotecont
=cont
;inued
617 git config
--list > result
619 test_expect_success
'value continued on next line' 'cmp result expect'
621 cat > .git
/config
<<\EOF
622 [section
"sub=section"]
631 section.sub
=section.val1
632 foo
=barQsection.sub
=section.val2
634 barQsection.sub
=section.val3
637 Qsection.sub
=section.val4
638 Qsection.sub
=section.val5Q
641 git config
--null --list |
tr '\000' 'Q' > result
644 test_expect_success
'--null --list' 'cmp result expect'
646 git config
--null --get-regexp 'val[0-9]' |
tr '\000' 'Q' > result
649 test_expect_success
'--null --get-regexp' 'cmp result expect'
651 test_expect_success
'symlinked configuration' '
653 ln -s notyet myconfig &&
654 GIT_CONFIG=myconfig git config test.frotz nitfol &&
657 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
658 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
661 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
662 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov