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 test_expect_success 'find mixed-case key by canonical name' '
77 echo Second >expect &&
78 git config cores.whatever >actual &&
79 test_cmp expect actual
82 test_expect_success 'find mixed-case key by non-canonical name' '
83 echo Second >expect &&
84 git config CoReS.WhAtEvEr >actual &&
85 test_cmp expect actual
88 test_expect_success 'subsections are not canonicalized by git-config' '
89 cat >>.git/config <<-\EOF &&
92 [section "SubSection"]
96 git config section.subsection.key >actual &&
97 test_cmp expect actual &&
99 git config section.SubSection.key >actual &&
100 test_cmp expect actual
103 cat > .git/config <<\EOF
111 test_expect_success 'unset with cont. lines' \
112 'git config --unset beta.baz'
120 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
122 cat > .git/config << EOF
123 [beta] ; silly comment # another comment
124 noIndent= sillyValue ; 'nother silly comment
128 haha ="beta" # last silly comment
131 [nextSection] noNewline = ouch
134 cp .git/config .git/config2
136 test_expect_success 'multiple unset' \
137 'git config --unset-all beta.haha'
140 [beta] ; silly comment # another comment
141 noIndent= sillyValue ; 'nother silly comment
145 [nextSection] noNewline = ouch
148 test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config'
150 cp .git/config2 .git/config
152 test_expect_success '--replace-all missing value' '
153 test_must_fail git config --replace-all beta.haha &&
154 test_cmp .git/config2 .git/config
159 test_expect_success '--replace-all' \
160 'git config --replace-all beta.haha gamma'
163 [beta] ; silly comment # another comment
164 noIndent= sillyValue ; 'nother silly comment
169 [nextSection] noNewline = ouch
172 test_expect_success 'all replaced' 'test_cmp expect .git/config'
175 [beta] ; silly comment # another comment
176 noIndent= sillyValue ; 'nother silly comment
181 [nextSection] noNewline = ouch
183 test_expect_success 'really mean test' '
184 git config beta.haha alpha &&
185 test_cmp expect .git/config
189 [beta] ; silly comment # another comment
190 noIndent= sillyValue ; 'nother silly comment
198 test_expect_success 'really really mean test' '
199 git config nextsection.nonewline wow &&
200 test_cmp expect .git/config
203 test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
206 [beta] ; silly comment # another comment
207 noIndent= sillyValue ; 'nother silly comment
214 test_expect_success 'unset' '
215 git config --unset beta.haha &&
216 test_cmp expect .git/config
220 [beta] ; silly comment # another comment
221 noIndent= sillyValue ; 'nother silly comment
227 NoNewLine = wow2 for me
229 test_expect_success 'multivar' '
230 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
231 test_cmp expect .git/config
234 test_expect_success 'non-match' \
235 'git config --get nextsection.nonewline !for'
237 test_expect_success 'non-match value' \
238 'test wow = $(git config --get nextsection.nonewline !for)'
240 test_expect_success 'ambiguous get' '
241 test_must_fail git config --get nextsection.nonewline
244 test_expect_success 'get multivar' \
245 'git config --get-all nextsection.nonewline'
248 [beta] ; silly comment # another comment
249 noIndent= sillyValue ; 'nother silly comment
255 NoNewLine = wow2 for me
257 test_expect_success 'multivar replace' '
258 git config nextsection.nonewline "wow3" "wow$" &&
259 test_cmp expect .git/config
262 test_expect_success 'ambiguous value' '
263 test_must_fail git config nextsection.nonewline
266 test_expect_success 'ambiguous unset' '
267 test_must_fail git config --unset nextsection.nonewline
270 test_expect_success 'invalid unset' '
271 test_must_fail git config --unset somesection.nonewline
275 [beta] ; silly comment # another comment
276 noIndent= sillyValue ; 'nother silly comment
281 NoNewLine = wow2 for me
284 test_expect_success 'multivar unset' '
285 git config --unset nextsection.nonewline "wow3$" &&
286 test_cmp expect .git/config
289 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
291 test_expect_success 'correct key' 'git config 123456.a123 987'
293 test_expect_success 'hierarchical section' \
294 'git config Version.1.2.3eX.Alpha beta'
297 [beta] ; silly comment # another comment
298 noIndent= sillyValue ; 'nother silly comment
303 NoNewLine = wow2 for me
310 test_expect_success 'hierarchical section value' 'test_cmp expect .git/config'
313 beta.noindent=sillyValue
314 nextsection.nonewline=wow2 for me
316 version.1.2.3eX.alpha=beta
319 test_expect_success 'working --list' \
320 'git config --list > output && cmp output expect'
325 test_expect_success '--list without repo produces empty output' '
326 git --git-dir=nonexistent config --list >output &&
327 test_cmp expect output
331 beta.noindent sillyValue
332 nextsection.nonewline wow2 for me
335 test_expect_success '--get-regexp' \
336 'git config --get-regexp in > output && cmp output expect'
343 test_expect_success '--add' '
344 git config --add nextsection.nonewline "wow4 for you" &&
345 git config --get-all nextsection.nonewline > output &&
346 test_cmp expect output
349 cat > .git/config << EOF
356 test_expect_success 'get variable with no value' \
357 'git config --get novalue.variable ^$'
359 test_expect_success 'get variable with empty value' \
360 'git config --get emptyvalue.variable ^$'
362 echo novalue.variable > expect
364 test_expect_success 'get-regexp variable with no value' \
365 'git config --get-regexp novalue > output &&
368 echo 'novalue.variable true' > expect
370 test_expect_success 'get-regexp --bool variable with no value' \
371 'git config --bool --get-regexp novalue > output &&
374 echo 'emptyvalue.variable ' > expect
376 test_expect_success 'get-regexp variable with empty value' \
377 'git config --get-regexp emptyvalue > output &&
382 test_expect_success 'get bool variable with no value' \
383 'git config --bool novalue.variable > output &&
388 test_expect_success 'get bool variable with empty value' \
389 'git config --bool emptyvalue.variable > output &&
392 test_expect_success 'no arguments, but no crash' '
393 test_must_fail git config >output 2>&1 &&
397 cat > .git/config << EOF
409 test_expect_success 'new section is partial match of another' '
411 test_cmp expect .git/config
424 test_expect_success 'new variable inserts into proper section' '
427 test_cmp expect .git/config
430 test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
431 'test_must_fail git config --file non-existing-config -l'
433 cat > other-config << EOF
442 test_expect_success 'alternative GIT_CONFIG' '
443 GIT_CONFIG=other-config git config -l >output &&
444 test_cmp expect output
447 test_expect_success 'alternative GIT_CONFIG (--file)' \
448 'git config --file other-config -l > output && cmp output expect'
450 test_expect_success 'refer config from subdirectory' '
455 git config --get --file ../other-config ein.bahn >actual &&
456 test_cmp expect actual
468 test_expect_success '--set in alternative GIT_CONFIG' '
469 GIT_CONFIG=other-config git config anwohner.park ausweis &&
470 test_cmp expect other-config
473 cat > .git/config << EOF
480 [branch "1 234 blabl/a"]
484 test_expect_success "rename section" \
485 "git config --rename-section branch.eins branch.zwei"
494 [branch "1 234 blabl/a"]
498 test_expect_success "rename succeeded" "test_cmp expect .git/config"
500 test_expect_success "rename non-existing section" '
501 test_must_fail git config --rename-section \
502 branch."world domination" branch.drei
505 test_expect_success "rename succeeded" "test_cmp expect .git/config"
507 test_expect_success "rename another section" \
508 'git config --rename-section branch."1 234 blabl/a" branch.drei'
521 test_expect_success "rename succeeded" "test_cmp expect .git/config"
523 cat >> .git/config << EOF
524 [branch "vier"] z = 1
527 test_expect_success "rename a section with a var on the same line" \
528 'git config --rename-section branch.vier branch.zwei'
543 test_expect_success "rename succeeded" "test_cmp expect .git/config"
545 cat >> .git/config << EOF
546 [branch "zwei"] a = 1 [branch "vier"]
549 test_expect_success "remove section" "git config --remove-section branch.zwei"
558 test_expect_success "section was removed properly" \
559 "test_cmp expect .git/config"
564 dbname = %Ggitcvs2.%a.%m.sqlite
566 dbname = %Ggitcvs1.%a.%m.sqlite
569 test_expect_success 'section ending' '
572 git config gitcvs.enabled true &&
573 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
574 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
575 test_cmp expect .git/config
579 test_expect_success numbers '
581 git config kilo.gram 1k &&
582 git config mega.ton 1m &&
583 k=$(git config --int --get kilo.gram) &&
584 test z1024 = "z$k" &&
585 m=$(git config --int --get mega.ton) &&
586 test z1048576 = "z$m"
590 fatal: bad config value for 'aninvalid.unit' in .git/config
593 test_expect_success 'invalid unit' '
595 git config aninvalid.unit "1auto" &&
596 s=$(git config aninvalid.unit) &&
597 test "z1auto" = "z$s" &&
598 if git config --int --get aninvalid.unit 2>actual
600 echo config should have failed
617 test_expect_success bool '
619 git config bool.true1 01 &&
620 git config bool.true2 -1 &&
621 git config bool.true3 YeS &&
622 git config bool.true4 true &&
623 git config bool.false1 000 &&
624 git config bool.false2 "" &&
625 git config bool.false3 nO &&
626 git config bool.false4 FALSE &&
630 git config --bool --get bool.true$i >>result
631 git config --bool --get bool.false$i >>result
635 test_expect_success 'invalid bool (--get)' '
637 git config bool.nobool foobar &&
638 test_must_fail git config --bool --get bool.nobool'
640 test_expect_success 'invalid bool (set)' '
642 test_must_fail git config --bool bool.nobool foobar'
656 test_expect_success 'set --bool' '
659 git config --bool bool.true1 01 &&
660 git config --bool bool.true2 -1 &&
661 git config --bool bool.true3 YeS &&
662 git config --bool bool.true4 true &&
663 git config --bool bool.false1 000 &&
664 git config --bool bool.false2 "" &&
665 git config --bool bool.false3 nO &&
666 git config --bool bool.false4 FALSE &&
667 cmp expect .git/config'
676 test_expect_success 'set --int' '
679 git config --int int.val1 01 &&
680 git config --int int.val2 -1 &&
681 git config --int int.val3 5m &&
682 cmp expect .git/config'
696 test_expect_success 'get --bool-or-int' '
708 test $(git config --bool-or-int bool.true1) = true &&
709 test $(git config --bool-or-int bool.true2) = true &&
710 test $(git config --bool-or-int bool.false) = false &&
711 test $(git config --bool-or-int int.int1) = 0 &&
712 test $(git config --bool-or-int int.int2) = 1 &&
713 test $(git config --bool-or-int int.int3) = -1
729 test_expect_success 'set --bool-or-int' '
731 git config --bool-or-int bool.true1 true &&
732 git config --bool-or-int bool.false1 false &&
733 git config --bool-or-int bool.true2 yes &&
734 git config --bool-or-int bool.false2 no &&
735 git config --bool-or-int int.int1 0 &&
736 git config --bool-or-int int.int2 1 &&
737 git config --bool-or-int int.int3 -1 &&
738 test_cmp expect .git/config
748 test_expect_success NOT_MINGW 'set --path' '
750 git config --path path.home "~/" &&
751 git config --path path.normal "/dev/null" &&
752 git config --path path.trailingtilde "foo~" &&
753 test_cmp expect .git/config'
755 if test_have_prereq NOT_MINGW && test "${HOME+set}"
757 test_set_prereq HOMEVAR
766 test_expect_success HOMEVAR 'get --path' '
767 git config --get --path path.home > result &&
768 git config --get --path path.normal >> result &&
769 git config --get --path path.trailingtilde >> result &&
770 test_cmp expect result
778 test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
781 test_must_fail git config --get --path path.home \
783 git config --get --path path.normal >>result &&
784 git config --get --path path.trailingtilde >>result
786 grep "[Ff]ailed to expand.*~/" msg &&
787 test_cmp expect result
794 semicolon = "test;test"
797 test_expect_success 'quoting' '
799 git config quote.leading " test" &&
800 git config quote.ending "test " &&
801 git config quote.semicolon "test;test" &&
802 git config quote.hash "test#test" &&
803 test_cmp expect .git/config
806 test_expect_success 'key with newline' '
807 test_must_fail git config "key.with
810 test_expect_success 'value with newline' 'git config key.sub value.with\\\
813 cat > .git/config <<\EOF
818 noncont = not continued ; \
824 section.continued=continued
825 section.noncont=not continued
826 section.quotecont=cont;inued
829 test_expect_success 'value continued on next line' '
830 git config --list > result &&
834 cat > .git/config <<\EOF
835 [section "sub=section"]
844 section.sub=section.val1
845 foo=barQsection.sub=section.val2
847 barQsection.sub=section.val3
850 Qsection.sub=section.val4
851 Qsection.sub=section.val5Q
853 test_expect_success '--null --list' '
854 git config --null --list | nul_to_q >result &&
856 test_cmp expect result
859 test_expect_success '--null --get-regexp' '
860 git config --null --get-regexp "val[0-9]" | nul_to_q >result &&
862 test_cmp expect result
865 test_expect_success 'inner whitespace kept verbatim' '
866 git config section.val "foo bar" &&
867 test "z$(git config section.val)" = "zfoo bar"
870 test_expect_success SYMLINKS 'symlinked configuration' '
872 ln -s notyet myconfig &&
873 GIT_CONFIG=myconfig git config test.frotz nitfol &&
876 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
877 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
880 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
881 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
885 test_expect_success 'nonexistent configuration' '
887 GIT_CONFIG=doesnotexist &&
889 test_must_fail git config --list &&
890 test_must_fail git config test.xyzzy
894 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
895 ln -s doesnotexist linktonada &&
896 ln -s linktonada linktolinktonada &&
898 GIT_CONFIG=linktonada &&
900 test_must_fail git config --list &&
901 GIT_CONFIG=linktolinktonada &&
902 test_must_fail git config --list
906 test_expect_success 'check split_cmdline return' "
907 git config alias.split-cmdline-fix 'echo \"' &&
908 test_must_fail git split-cmdline-fix &&
911 git commit -m 'initial commit' &&
912 git config branch.master.mergeoptions 'echo \"' &&
913 test_must_fail git merge master
916 test_expect_success 'git -c "key=value" support' '
917 test "z$(git -c core.name=value config core.name)" = zvalue &&
918 test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue &&
919 test "z$(git -c foo.flag config --bool foo.flag)" = ztrue &&
920 test_must_fail git -c name=value config core.name
923 test_expect_success 'key sanity-checking' '
924 test_must_fail git config foo=bar &&
925 test_must_fail git config foo=.bar &&
926 test_must_fail git config foo.ba=r &&
927 test_must_fail git config foo.1bar &&
928 test_must_fail git config foo."ba
930 test_must_fail git config . false &&
931 test_must_fail git config .foo false &&
932 test_must_fail git config foo. false &&
933 test_must_fail git config .foo. false &&
934 git config foo.bar true &&
935 git config foo."ba =z".bar false
938 test_expect_success 'git -c works with aliases of builtins' '
939 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
941 git checkconfig >actual &&
942 test_cmp expect actual
945 test_expect_success 'git -c does not split values on equals' '
946 echo "value with = in it" >expect &&
947 git -c core.foo="value with = in it" config core.foo >actual &&
948 test_cmp expect actual
951 test_expect_success 'git -c dies on bogus config' '
952 test_must_fail git -c core.bare=foo rev-parse
955 test_expect_success 'git -c complains about empty key' '
956 test_must_fail git -c "=foo" rev-parse
959 test_expect_success 'git -c complains about empty key and value' '
960 test_must_fail git -c "" rev-parse
963 # malformed configuration files
964 test_expect_success 'barf on syntax error' '
965 cat >.git/config <<-\EOF &&
966 # broken section line
970 test_must_fail git config --get section.key >actual 2>error &&
971 grep " line 3 " error
974 test_expect_success 'barf on incomplete section header' '
975 cat >.git/config <<-\EOF &&
976 # broken section line
980 test_must_fail git config --get section.key >actual 2>error &&
981 grep " line 2 " error
984 test_expect_success 'barf on incomplete string' '
985 cat >.git/config <<-\EOF &&
986 # broken section line
990 test_must_fail git config --get section.key >actual 2>error &&
991 grep " line 3 " error