3 # Copyright (c) 2005 Johannes Schindelin
6 test_description
='Test git config in different settings'
10 test_expect_success
'clear default config' '
18 test_expect_success
'initial' '
19 git config core.penguin "little blue" &&
20 test_cmp expect .git/config
28 test_expect_success
'mixed case' '
29 git config Core.Movie BadPhysics &&
30 test_cmp expect .git/config
40 test_expect_success
'similar section' '
41 git config Cores.WhatEver Second
42 test_cmp expect .git/config
53 test_expect_success
'uppercase section' '
54 git config CORE.UPPERCASE true &&
55 test_cmp expect .git/config
58 test_expect_success
'replace with non-match' \
59 'git config core.penguin kingpin !blue'
61 test_expect_success
'replace with non-match (actually matching)' \
62 'git config core.penguin "very blue" !kingpin'
74 test_expect_success
'non-match result' 'test_cmp expect .git/config'
76 cat > .git
/config
<<\EOF
84 test_expect_success
'unset with cont. lines' \
85 'git config --unset beta.baz'
93 test_expect_success
'unset with cont. lines is correct' 'test_cmp expect .git/config'
95 cat > .git
/config
<< EOF
96 [beta] ; silly comment # another comment
97 noIndent= sillyValue ; 'nother silly comment
101 haha ="beta" # last silly comment
104 [nextSection] noNewline = ouch
107 cp .git
/config .git
/config2
109 test_expect_success
'multiple unset' \
110 'git config --unset-all beta.haha'
113 [beta] ; silly comment # another comment
114 noIndent= sillyValue ; 'nother silly comment
118 [nextSection] noNewline = ouch
121 test_expect_success
'multiple unset is correct' 'test_cmp expect .git/config'
123 cp .git
/config2 .git
/config
125 test_expect_success
'--replace-all missing value' '
126 test_must_fail git config --replace-all beta.haha &&
127 test_cmp .git/config2 .git/config
132 test_expect_success
'--replace-all' \
133 'git config --replace-all beta.haha gamma'
136 [beta] ; silly comment # another comment
137 noIndent= sillyValue ; 'nother silly comment
142 [nextSection] noNewline = ouch
145 test_expect_success
'all replaced' 'test_cmp expect .git/config'
148 [beta] ; silly comment # another comment
149 noIndent= sillyValue ; 'nother silly comment
154 [nextSection] noNewline = ouch
156 test_expect_success
'really mean test' '
157 git config beta.haha alpha &&
158 test_cmp expect .git/config
162 [beta] ; silly comment # another comment
163 noIndent= sillyValue ; 'nother silly comment
171 test_expect_success
'really really mean test' '
172 git config nextsection.nonewline wow &&
173 test_cmp expect .git/config
176 test_expect_success
'get value' 'test alpha = $(git config beta.haha)'
179 [beta] ; silly comment # another comment
180 noIndent= sillyValue ; 'nother silly comment
187 test_expect_success
'unset' '
188 git config --unset beta.haha &&
189 test_cmp expect .git/config
193 [beta] ; silly comment # another comment
194 noIndent= sillyValue ; 'nother silly comment
200 NoNewLine = wow2 for me
202 test_expect_success
'multivar' '
203 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
204 test_cmp expect .git/config
207 test_expect_success
'non-match' \
208 'git config --get nextsection.nonewline !for'
210 test_expect_success
'non-match value' \
211 'test wow = $(git config --get nextsection.nonewline !for)'
213 test_expect_success
'ambiguous get' '
214 test_must_fail git config --get nextsection.nonewline
217 test_expect_success
'get multivar' \
218 'git config --get-all nextsection.nonewline'
221 [beta] ; silly comment # another comment
222 noIndent= sillyValue ; 'nother silly comment
228 NoNewLine = wow2 for me
230 test_expect_success
'multivar replace' '
231 git config nextsection.nonewline "wow3" "wow$" &&
232 test_cmp expect .git/config
235 test_expect_success
'ambiguous value' '
236 test_must_fail git config nextsection.nonewline
239 test_expect_success
'ambiguous unset' '
240 test_must_fail git config --unset nextsection.nonewline
243 test_expect_success
'invalid unset' '
244 test_must_fail git config --unset somesection.nonewline
248 [beta] ; silly comment # another comment
249 noIndent= sillyValue ; 'nother silly comment
254 NoNewLine = wow2 for me
257 test_expect_success
'multivar unset' '
258 git config --unset nextsection.nonewline "wow3$" &&
259 test_cmp expect .git/config
262 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
264 test_expect_success
'correct key' 'git config 123456.a123 987'
266 test_expect_success
'hierarchical section' \
267 'git config Version.1.2.3eX.Alpha beta'
270 [beta] ; silly comment # another comment
271 noIndent= sillyValue ; 'nother silly comment
276 NoNewLine = wow2 for me
283 test_expect_success
'hierarchical section value' 'test_cmp expect .git/config'
286 beta.noindent=sillyValue
287 nextsection.nonewline=wow2 for me
289 version.1.2.3eX.alpha=beta
292 test_expect_success
'working --list' \
293 'git config --list > output && cmp output expect'
298 test_expect_success
'--list without repo produces empty output' '
299 git --git-dir=nonexistent config --list >output &&
300 test_cmp expect output
304 beta.noindent sillyValue
305 nextsection.nonewline wow2 for me
308 test_expect_success
'--get-regexp' \
309 'git config --get-regexp in > output && cmp output expect'
316 test_expect_success
'--add' '
317 git config --add nextsection.nonewline "wow4 for you" &&
318 git config --get-all nextsection.nonewline > output &&
319 test_cmp expect output
322 cat > .git
/config
<< EOF
329 test_expect_success
'get variable with no value' \
330 'git config --get novalue.variable ^$'
332 test_expect_success
'get variable with empty value' \
333 'git config --get emptyvalue.variable ^$'
335 echo novalue.variable
> expect
337 test_expect_success
'get-regexp variable with no value' \
338 'git config --get-regexp novalue > output &&
341 echo 'emptyvalue.variable ' > expect
343 test_expect_success
'get-regexp variable with empty value' \
344 'git config --get-regexp emptyvalue > output &&
349 test_expect_success
'get bool variable with no value' \
350 'git config --bool novalue.variable > output &&
355 test_expect_success
'get bool variable with empty value' \
356 'git config --bool emptyvalue.variable > output &&
359 test_expect_success
'no arguments, but no crash' '
360 test_must_fail git config >output 2>&1 &&
364 cat > .git
/config
<< EOF
376 test_expect_success
'new section is partial match of another' '
378 test_cmp expect .git/config
391 test_expect_success
'new variable inserts into proper section' '
394 test_cmp expect .git/config
397 test_expect_success
'alternative GIT_CONFIG (non-existing file should fail)' \
398 'test_must_fail git config --file non-existing-config -l'
400 cat > other-config
<< EOF
409 test_expect_success
'alternative GIT_CONFIG' '
410 GIT_CONFIG=other-config git config -l >output &&
411 test_cmp expect output
414 test_expect_success
'alternative GIT_CONFIG (--file)' \
415 'git config --file other-config -l > output && cmp output expect'
417 test_expect_success
'refer config from subdirectory' '
422 git config --get --file ../other-config ein.bahn >actual &&
423 test_cmp expect actual
435 test_expect_success
'--set in alternative GIT_CONFIG' '
436 GIT_CONFIG=other-config git config anwohner.park ausweis &&
437 test_cmp expect other-config
440 cat > .git
/config
<< EOF
447 [branch "1 234 blabl/a"]
451 test_expect_success
"rename section" \
452 "git config --rename-section branch.eins branch.zwei"
461 [branch "1 234 blabl/a"]
465 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
467 test_expect_success
"rename non-existing section" '
468 test_must_fail git config --rename-section \
469 branch."world domination" branch.drei
472 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
474 test_expect_success
"rename another section" \
475 'git config --rename-section branch."1 234 blabl/a" branch.drei'
488 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
490 cat >> .git
/config
<< EOF
491 [branch "vier"] z = 1
494 test_expect_success
"rename a section with a var on the same line" \
495 'git config --rename-section branch.vier branch.zwei'
510 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
512 cat >> .git
/config
<< EOF
513 [branch "zwei"] a = 1 [branch "vier"]
516 test_expect_success
"remove section" "git config --remove-section branch.zwei"
525 test_expect_success
"section was removed properly" \
526 "test_cmp expect .git/config"
533 dbname = %Ggitcvs2.%a.%m.sqlite
535 dbname = %Ggitcvs1.%a.%m.sqlite
538 test_expect_success
'section ending' '
540 git config gitcvs.enabled true &&
541 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
542 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
543 test_cmp expect .git/config
547 test_expect_success numbers
'
549 git config kilo.gram 1k &&
550 git config mega.ton 1m &&
551 k=$(git config --int --get kilo.gram) &&
552 test z1024 = "z$k" &&
553 m=$(git config --int --get mega.ton) &&
554 test z1048576 = "z$m"
558 fatal: bad config value for 'aninvalid.unit' in .git/config
561 test_expect_success
'invalid unit' '
563 git config aninvalid.unit "1auto" &&
564 s=$(git config aninvalid.unit) &&
565 test "z1auto" = "z$s" &&
566 if git config --int --get aninvalid.unit 2>actual
568 echo config should have failed
585 test_expect_success bool
'
587 git config bool.true1 01 &&
588 git config bool.true2 -1 &&
589 git config bool.true3 YeS &&
590 git config bool.true4 true &&
591 git config bool.false1 000 &&
592 git config bool.false2 "" &&
593 git config bool.false3 nO &&
594 git config bool.false4 FALSE &&
598 git config --bool --get bool.true$i >>result
599 git config --bool --get bool.false$i >>result
603 test_expect_success
'invalid bool (--get)' '
605 git config bool.nobool foobar &&
606 test_must_fail git config --bool --get bool.nobool'
608 test_expect_success
'invalid bool (set)' '
610 test_must_fail git config --bool bool.nobool foobar'
626 test_expect_success
'set --bool' '
628 git config --bool bool.true1 01 &&
629 git config --bool bool.true2 -1 &&
630 git config --bool bool.true3 YeS &&
631 git config --bool bool.true4 true &&
632 git config --bool bool.false1 000 &&
633 git config --bool bool.false2 "" &&
634 git config --bool bool.false3 nO &&
635 git config --bool bool.false4 FALSE &&
636 cmp expect .git/config'
647 test_expect_success
'set --int' '
649 git config --int int.val1 01 &&
650 git config --int int.val2 -1 &&
651 git config --int int.val3 5m &&
652 cmp expect .git/config'
668 test_expect_success
'get --bool-or-int' '
679 test $(git config --bool-or-int bool.true1) = true &&
680 test $(git config --bool-or-int bool.true2) = true &&
681 test $(git config --bool-or-int bool.false) = false &&
682 test $(git config --bool-or-int int.int1) = 0 &&
683 test $(git config --bool-or-int int.int2) = 1 &&
684 test $(git config --bool-or-int int.int3) = -1
701 test_expect_success
'set --bool-or-int' '
702 git config --bool-or-int bool.true1 true &&
703 git config --bool-or-int bool.false1 false &&
704 git config --bool-or-int bool.true2 yes &&
705 git config --bool-or-int bool.false2 no &&
706 git config --bool-or-int int.int1 0 &&
707 git config --bool-or-int int.int2 1 &&
708 git config --bool-or-int int.int3 -1 &&
709 test_cmp expect .git/config
721 test_expect_success NOT_MINGW
'set --path' '
722 git config --path path.home "~/" &&
723 git config --path path.normal "/dev/null" &&
724 git config --path path.trailingtilde "foo~" &&
725 test_cmp expect .git/config'
727 if test_have_prereq NOT_MINGW
&& test "${HOME+set}"
729 test_set_prereq HOMEVAR
738 test_expect_success HOMEVAR
'get --path' '
739 git config --get --path path.home > result &&
740 git config --get --path path.normal >> result &&
741 git config --get --path path.trailingtilde >> result &&
742 test_cmp expect result
750 test_expect_success NOT_MINGW
'get --path copes with unset $HOME' '
753 test_must_fail git config --get --path path.home \
755 git config --get --path path.normal >>result &&
756 git config --get --path path.trailingtilde >>result
758 grep "[Ff]ailed to expand.*~/" msg &&
759 test_cmp expect result
766 semicolon = "test;test"
769 test_expect_success
'quoting' '
771 git config quote.leading " test" &&
772 git config quote.ending "test " &&
773 git config quote.semicolon "test;test" &&
774 git config quote.hash "test#test" &&
775 test_cmp expect .git/config
778 test_expect_success
'key with newline' '
779 test_must_fail git config "key.with
782 test_expect_success
'value with newline' 'git config key.sub value.with\\\
785 cat > .git
/config
<<\EOF
790 noncont
= not continued
; \
796 section.continued
=continued
797 section.noncont
=not continued
798 section.quotecont
=cont
;inued
801 test_expect_success
'value continued on next line' '
802 git config --list > result &&
806 cat > .git
/config
<<\EOF
807 [section
"sub=section"]
816 section.sub
=section.val1
817 foo
=barQsection.sub
=section.val2
819 barQsection.sub
=section.val3
822 Qsection.sub
=section.val4
823 Qsection.sub
=section.val5Q
825 test_expect_success
'--null --list' '
826 git config --null --list | nul_to_q >result &&
828 test_cmp expect result
831 test_expect_success
'--null --get-regexp' '
832 git config --null --get-regexp "val[0-9]" | nul_to_q >result &&
834 test_cmp expect result
837 test_expect_success
'inner whitespace kept verbatim' '
838 git config section.val "foo bar" &&
839 test "z$(git config section.val)" = "zfoo bar"
842 test_expect_success SYMLINKS
'symlinked configuration' '
844 ln -s notyet myconfig &&
845 GIT_CONFIG=myconfig git config test.frotz nitfol &&
848 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
849 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
852 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
853 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
857 test_expect_success
'nonexistent configuration' '
859 GIT_CONFIG=doesnotexist &&
861 test_must_fail git config --list &&
862 test_must_fail git config test.xyzzy
866 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
867 ln -s doesnotexist linktonada &&
868 ln -s linktonada linktolinktonada &&
870 GIT_CONFIG=linktonada &&
872 test_must_fail git config --list &&
873 GIT_CONFIG=linktolinktonada &&
874 test_must_fail git config --list
878 test_expect_success
'check split_cmdline return' "
879 git config alias.split-cmdline-fix 'echo \"' &&
880 test_must_fail git split-cmdline-fix &&
883 git commit -m 'initial commit' &&
884 git config branch.master.mergeoptions 'echo \"' &&
885 test_must_fail git merge master
888 test_expect_success
'git -c "key=value" support' '
889 test "z$(git -c core.name=value config core.name)" = zvalue &&
890 test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue &&
891 test "z$(git -c foo.flag config --bool foo.flag)" = ztrue &&
892 test_must_fail git -c name=value config core.name
895 test_expect_success
'key sanity-checking' '
896 test_must_fail git config foo=bar &&
897 test_must_fail git config foo=.bar &&
898 test_must_fail git config foo.ba=r &&
899 test_must_fail git config foo.1bar &&
900 test_must_fail git config foo."ba
902 test_must_fail git config . false &&
903 test_must_fail git config .foo false &&
904 test_must_fail git config foo. false &&
905 test_must_fail git config .foo. false &&
906 git config foo.bar true &&
907 git config foo."ba =z".bar false
910 test_expect_success
'git -c works with aliases of builtins' '
911 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
913 git checkconfig >actual &&
914 test_cmp expect actual
917 test_expect_success
'git -c does not split values on equals' '
918 echo "value with = in it" >expect &&
919 git -c core.foo="value with = in it" config core.foo >actual &&
920 test_cmp expect actual
923 test_expect_success
'git -c dies on bogus config' '
924 test_must_fail git -c core.bare=foo rev-parse
927 test_expect_success
'git -c complains about empty key' '
928 test_must_fail git -c "=foo" rev-parse
931 test_expect_success
'git -c complains about empty key and value' '
932 test_must_fail git -c "" rev-parse