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 cp .git
/config2 .git
/config
123 test_expect_success
'--replace-all missing value' '
124 test_must_fail git config --replace-all beta.haha &&
125 test_cmp .git/config2 .git/config
130 test_expect_success
'--replace-all' \
131 'git config --replace-all beta.haha gamma'
134 [beta] ; silly comment # another comment
135 noIndent= sillyValue ; 'nother silly comment
140 [nextSection] noNewline = ouch
143 test_expect_success
'all replaced' 'cmp .git/config expect'
145 git config beta.haha alpha
148 [beta] ; silly comment # another comment
149 noIndent= sillyValue ; 'nother silly comment
154 [nextSection] noNewline = ouch
157 test_expect_success
'really mean test' 'cmp .git/config expect'
159 git config nextsection.nonewline wow
162 [beta] ; silly comment # another comment
163 noIndent= sillyValue ; 'nother silly comment
172 test_expect_success
'really really mean test' 'cmp .git/config expect'
174 test_expect_success
'get value' 'test alpha = $(git config beta.haha)'
175 git config
--unset beta.haha
178 [beta] ; silly comment # another comment
179 noIndent= sillyValue ; 'nother silly comment
187 test_expect_success
'unset' 'cmp .git/config expect'
189 git config nextsection.NoNewLine
"wow2 for me" "for me$"
192 [beta] ; silly comment # another comment
193 noIndent= sillyValue ; 'nother silly comment
199 NoNewLine = wow2 for me
202 test_expect_success
'multivar' 'cmp .git/config expect'
204 test_expect_success
'non-match' \
205 'git config --get nextsection.nonewline !for'
207 test_expect_success
'non-match value' \
208 'test wow = $(git config --get nextsection.nonewline !for)'
210 test_expect_success
'ambiguous get' '
211 test_must_fail git config --get nextsection.nonewline
214 test_expect_success
'get multivar' \
215 'git config --get-all nextsection.nonewline'
217 git config nextsection.nonewline
"wow3" "wow$"
220 [beta] ; silly comment # another comment
221 noIndent= sillyValue ; 'nother silly comment
227 NoNewLine = wow2 for me
230 test_expect_success
'multivar replace' 'cmp .git/config expect'
232 test_expect_success
'ambiguous value' '
233 test_must_fail git config nextsection.nonewline
236 test_expect_success
'ambiguous unset' '
237 test_must_fail git config --unset nextsection.nonewline
240 test_expect_success
'invalid unset' '
241 test_must_fail git config --unset somesection.nonewline
244 git config
--unset nextsection.nonewline
"wow3$"
247 [beta] ; silly comment # another comment
248 noIndent= sillyValue ; 'nother silly comment
253 NoNewLine = wow2 for me
256 test_expect_success
'multivar unset' 'cmp .git/config expect'
258 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
260 test_expect_success
'correct key' 'git config 123456.a123 987'
262 test_expect_success
'hierarchical section' \
263 'git config Version.1.2.3eX.Alpha beta'
266 [beta] ; silly comment # another comment
267 noIndent= sillyValue ; 'nother silly comment
272 NoNewLine = wow2 for me
279 test_expect_success
'hierarchical section value' 'cmp .git/config expect'
282 beta.noindent=sillyValue
283 nextsection.nonewline=wow2 for me
285 version.1.2.3eX.alpha=beta
288 test_expect_success
'working --list' \
289 'git config --list > output && cmp output expect'
294 test_expect_success
'--list without repo produces empty output' '
295 git --git-dir=nonexistent config --list >output &&
296 test_cmp expect output
300 beta.noindent sillyValue
301 nextsection.nonewline wow2 for me
304 test_expect_success
'--get-regexp' \
305 'git config --get-regexp in > output && cmp output expect'
307 git config
--add nextsection.nonewline
"wow4 for you"
314 test_expect_success
'--add' \
315 'git config --get-all nextsection.nonewline > output && cmp output expect'
317 cat > .git
/config
<< EOF
324 test_expect_success
'get variable with no value' \
325 'git config --get novalue.variable ^$'
327 test_expect_success
'get variable with empty value' \
328 'git config --get emptyvalue.variable ^$'
330 echo novalue.variable
> expect
332 test_expect_success
'get-regexp variable with no value' \
333 'git config --get-regexp novalue > output &&
336 echo 'novalue.variable true' > expect
338 test_expect_success
'get-regexp --bool variable with no value' \
339 'git config --bool --get-regexp novalue > output &&
342 echo 'emptyvalue.variable ' > expect
344 test_expect_success
'get-regexp variable with empty value' \
345 'git config --get-regexp emptyvalue > output &&
350 test_expect_success
'get bool variable with no value' \
351 'git config --bool novalue.variable > output &&
356 test_expect_success
'get bool variable with empty value' \
357 'git config --bool emptyvalue.variable > output &&
360 test_expect_success
'no arguments, but no crash' '
361 test_must_fail git config >output 2>&1 &&
365 cat > .git
/config
<< EOF
379 test_expect_success
'new section is partial match of another' 'cmp .git/config expect'
394 test_expect_success
'new variable inserts into proper section' 'cmp .git/config expect'
396 test_expect_success
'alternative GIT_CONFIG (non-existing file should fail)' \
397 'test_must_fail git config --file non-existing-config -l'
399 cat > other-config
<< EOF
408 GIT_CONFIG
=other-config git config
-l > output
410 test_expect_success
'alternative GIT_CONFIG' 'cmp output expect'
412 test_expect_success
'alternative GIT_CONFIG (--file)' \
413 'git config --file other-config -l > output && cmp output expect'
415 test_expect_success
'refer config from subdirectory' '
420 git config --get --file ../other-config ein.bahn >actual &&
421 test_cmp expect actual
426 GIT_CONFIG
=other-config git config anwohner.park ausweis
435 test_expect_success
'--set in alternative GIT_CONFIG' 'cmp other-config expect'
437 cat > .git
/config
<< EOF
444 [branch "1 234 blabl/a"]
448 test_expect_success
"rename section" \
449 "git config --rename-section branch.eins branch.zwei"
458 [branch "1 234 blabl/a"]
462 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
464 test_expect_success
"rename non-existing section" '
465 test_must_fail git config --rename-section \
466 branch."world domination" branch.drei
469 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
471 test_expect_success
"rename another section" \
472 'git config --rename-section branch."1 234 blabl/a" branch.drei'
485 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
487 cat >> .git
/config
<< EOF
488 [branch "vier"] z = 1
491 test_expect_success
"rename a section with a var on the same line" \
492 'git config --rename-section branch.vier branch.zwei'
507 test_expect_success
"rename succeeded" "test_cmp expect .git/config"
509 cat >> .git
/config
<< EOF
510 [branch "zwei"] a = 1 [branch "vier"]
513 test_expect_success
"remove section" "git config --remove-section branch.zwei"
522 test_expect_success
"section was removed properly" \
523 "test_cmp expect .git/config"
530 dbname = %Ggitcvs2.%a.%m.sqlite
532 dbname = %Ggitcvs1.%a.%m.sqlite
535 test_expect_success
'section ending' '
537 git config gitcvs.enabled true &&
538 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
539 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
540 cmp .git/config expect
544 test_expect_success numbers
'
546 git config kilo.gram 1k &&
547 git config mega.ton 1m &&
548 k=$(git config --int --get kilo.gram) &&
549 test z1024 = "z$k" &&
550 m=$(git config --int --get mega.ton) &&
551 test z1048576 = "z$m"
555 fatal: bad config value for 'aninvalid.unit' in .git/config
558 test_expect_success
'invalid unit' '
560 git config aninvalid.unit "1auto" &&
561 s=$(git config aninvalid.unit) &&
562 test "z1auto" = "z$s" &&
563 if git config --int --get aninvalid.unit 2>actual
565 echo config should have failed
582 test_expect_success bool
'
584 git config bool.true1 01 &&
585 git config bool.true2 -1 &&
586 git config bool.true3 YeS &&
587 git config bool.true4 true &&
588 git config bool.false1 000 &&
589 git config bool.false2 "" &&
590 git config bool.false3 nO &&
591 git config bool.false4 FALSE &&
595 git config --bool --get bool.true$i >>result
596 git config --bool --get bool.false$i >>result
600 test_expect_success
'invalid bool (--get)' '
602 git config bool.nobool foobar &&
603 test_must_fail git config --bool --get bool.nobool'
605 test_expect_success
'invalid bool (set)' '
607 test_must_fail git config --bool bool.nobool foobar'
623 test_expect_success
'set --bool' '
625 git config --bool bool.true1 01 &&
626 git config --bool bool.true2 -1 &&
627 git config --bool bool.true3 YeS &&
628 git config --bool bool.true4 true &&
629 git config --bool bool.false1 000 &&
630 git config --bool bool.false2 "" &&
631 git config --bool bool.false3 nO &&
632 git config --bool bool.false4 FALSE &&
633 cmp expect .git/config'
644 test_expect_success
'set --int' '
646 git config --int int.val1 01 &&
647 git config --int int.val2 -1 &&
648 git config --int int.val3 5m &&
649 cmp expect .git/config'
665 test_expect_success
'get --bool-or-int' '
676 test $(git config --bool-or-int bool.true1) = true &&
677 test $(git config --bool-or-int bool.true2) = true &&
678 test $(git config --bool-or-int bool.false) = false &&
679 test $(git config --bool-or-int int.int1) = 0 &&
680 test $(git config --bool-or-int int.int2) = 1 &&
681 test $(git config --bool-or-int int.int3) = -1
698 test_expect_success
'set --bool-or-int' '
699 git config --bool-or-int bool.true1 true &&
700 git config --bool-or-int bool.false1 false &&
701 git config --bool-or-int bool.true2 yes &&
702 git config --bool-or-int bool.false2 no &&
703 git config --bool-or-int int.int1 0 &&
704 git config --bool-or-int int.int2 1 &&
705 git config --bool-or-int int.int3 -1 &&
706 test_cmp expect .git/config
718 test_expect_success NOT_MINGW
'set --path' '
719 git config --path path.home "~/" &&
720 git config --path path.normal "/dev/null" &&
721 git config --path path.trailingtilde "foo~" &&
722 test_cmp expect .git/config'
724 if test_have_prereq NOT_MINGW
&& test "${HOME+set}"
726 test_set_prereq HOMEVAR
735 test_expect_success HOMEVAR
'get --path' '
736 git config --get --path path.home > result &&
737 git config --get --path path.normal >> result &&
738 git config --get --path path.trailingtilde >> result &&
739 test_cmp expect result
747 test_expect_success NOT_MINGW
'get --path copes with unset $HOME' '
750 test_must_fail git config --get --path path.home \
752 git config --get --path path.normal >>result &&
753 git config --get --path path.trailingtilde >>result
755 grep "[Ff]ailed to expand.*~/" msg &&
756 test_cmp expect result
761 git config quote.leading
" test"
762 git config quote.ending
"test "
763 git config quote.semicolon
"test;test"
764 git config quote.
hash "test#test"
770 semicolon = "test;test"
774 test_expect_success
'quoting' 'cmp .git/config expect'
776 test_expect_success
'key with newline' '
777 test_must_fail git config "key.with
780 test_expect_success
'value with newline' 'git config key.sub value.with\\\
783 cat > .git
/config
<<\EOF
788 noncont
= not continued
; \
794 section.continued
=continued
795 section.noncont
=not continued
796 section.quotecont
=cont
;inued
799 git config
--list > result
801 test_expect_success
'value continued on next line' 'cmp result expect'
803 cat > .git
/config
<<\EOF
804 [section
"sub=section"]
813 section.sub
=section.val1
814 foo
=barQsection.sub
=section.val2
816 barQsection.sub
=section.val3
819 Qsection.sub
=section.val4
820 Qsection.sub
=section.val5Q
823 git config
--null --list | perl
-pe 'y/\000/Q/' > result
826 test_expect_success
'--null --list' 'cmp result expect'
828 git config
--null --get-regexp 'val[0-9]' | perl
-pe 'y/\000/Q/' > result
831 test_expect_success
'--null --get-regexp' 'cmp result expect'
833 test_expect_success
'inner whitespace kept verbatim' '
834 git config section.val "foo bar" &&
835 test "z$(git config section.val)" = "zfoo bar"
838 test_expect_success SYMLINKS
'symlinked configuration' '
840 ln -s notyet myconfig &&
841 GIT_CONFIG=myconfig git config test.frotz nitfol &&
844 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
845 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
848 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
849 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
853 test_expect_success
'nonexistent configuration' '
855 GIT_CONFIG=doesnotexist &&
857 test_must_fail git config --list &&
858 test_must_fail git config test.xyzzy
862 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
863 ln -s doesnotexist linktonada &&
864 ln -s linktonada linktolinktonada &&
866 GIT_CONFIG=linktonada &&
868 test_must_fail git config --list &&
869 GIT_CONFIG=linktolinktonada &&
870 test_must_fail git config --list
874 test_expect_success
'check split_cmdline return' "
875 git config alias.split-cmdline-fix 'echo \"' &&
876 test_must_fail git split-cmdline-fix &&
879 git commit -m 'initial commit' &&
880 git config branch.master.mergeoptions 'echo \"' &&
881 test_must_fail git merge master
884 test_expect_success
'git -c "key=value" support' '
885 test "z$(git -c core.name=value config core.name)" = zvalue &&
886 test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue &&
887 test "z$(git -c foo.flag config --bool foo.flag)" = ztrue &&
888 test_must_fail git -c name=value config core.name
891 test_expect_success
'key sanity-checking' '
892 test_must_fail git config foo=bar &&
893 test_must_fail git config foo=.bar &&
894 test_must_fail git config foo.ba=r &&
895 test_must_fail git config foo.1bar &&
896 test_must_fail git config foo."ba
898 test_must_fail git config . false &&
899 test_must_fail git config .foo false &&
900 test_must_fail git config foo. false &&
901 test_must_fail git config .foo. false &&
902 git config foo.bar true &&
903 git config foo."ba =z".bar false
906 test_expect_success
'git -c works with aliases of builtins' '
907 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
909 git checkconfig >actual &&
910 test_cmp expect actual
913 test_expect_success
'git -c does not split values on equals' '
914 echo "value with = in it" >expect &&
915 git -c core.foo="value with = in it" config core.foo >actual &&
916 test_cmp expect actual
919 test_expect_success
'git -c dies on bogus config' '
920 test_must_fail git -c core.bare=foo rev-parse
923 test_expect_success
'git -c complains about empty key' '
924 test_must_fail git -c "=foo" rev-parse
927 test_expect_success
'git -c complains about empty key and value' '
928 test_must_fail git -c "" rev-parse
931 # malformed configuration files
932 test_expect_success
'barf on syntax error' '
933 cat >.git/config <<-\EOF &&
934 # broken section line
938 test_must_fail git config --get section.key >actual 2>error &&
939 grep " line 3 " error
942 test_expect_success
'barf on incomplete section header' '
943 cat >.git/config <<-\EOF &&
944 # broken section line
948 test_must_fail git config --get section.key >actual 2>error &&
949 grep " line 2 " error
952 test_expect_success
'barf on incomplete string' '
953 cat >.git/config <<-\EOF &&
954 # broken section line
958 test_must_fail git config --get section.key >actual 2>error &&
959 grep " line 3 " error