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
62 test_expect_success
'replace with non-match (actually matching)' '
63 git config core.penguin "very blue" !kingpin
76 test_expect_success
'non-match result' 'test_cmp expect .git/config'
78 test_expect_success
'find mixed-case key by canonical name' '
79 echo Second >expect &&
80 git config cores.whatever >actual &&
81 test_cmp expect actual
84 test_expect_success
'find mixed-case key by non-canonical name' '
85 echo Second >expect &&
86 git config CoReS.WhAtEvEr >actual &&
87 test_cmp expect actual
90 test_expect_success
'subsections are not canonicalized by git-config' '
91 cat >>.git/config <<-\EOF &&
94 [section "SubSection"]
98 git config section.subsection.key >actual &&
99 test_cmp expect actual &&
101 git config section.SubSection.key >actual &&
102 test_cmp expect actual
105 cat > .git
/config
<<\EOF
114 test_expect_success
'unset with cont. lines' '
115 git config --unset beta.baz
125 test_expect_success
'unset with cont. lines is correct' 'test_cmp expect .git/config'
127 cat > .git
/config
<< EOF
128 [beta] ; silly comment # another comment
129 noIndent= sillyValue ; 'nother silly comment
133 haha ="beta" # last silly comment
136 [nextSection] noNewline = ouch
139 cp .git
/config .git
/config2
141 test_expect_success
'multiple unset' '
142 git config --unset-all beta.haha
146 [beta] ; silly comment # another comment
147 noIndent= sillyValue ; 'nother silly comment
151 [nextSection] noNewline = ouch
154 test_expect_success
'multiple unset is correct' '
155 test_cmp expect .git/config
158 cp .git
/config2 .git
/config
160 test_expect_success
'--replace-all missing value' '
161 test_must_fail git config --replace-all beta.haha &&
162 test_cmp .git/config2 .git/config
167 test_expect_success
'--replace-all' '
168 git config --replace-all beta.haha gamma
172 [beta] ; silly comment # another comment
173 noIndent= sillyValue ; 'nother silly comment
178 [nextSection] noNewline = ouch
181 test_expect_success
'all replaced' '
182 test_cmp expect .git/config
186 [beta] ; silly comment # another comment
187 noIndent= sillyValue ; 'nother silly comment
192 [nextSection] noNewline = ouch
194 test_expect_success
'really mean test' '
195 git config beta.haha alpha &&
196 test_cmp expect .git/config
200 [beta] ; silly comment # another comment
201 noIndent= sillyValue ; 'nother silly comment
209 test_expect_success
'really really mean test' '
210 git config nextsection.nonewline wow &&
211 test_cmp expect .git/config
214 test_expect_success
'get value' '
215 echo alpha >expect &&
216 git config beta.haha >actual &&
217 test_cmp expect actual
221 [beta] ; silly comment # another comment
222 noIndent= sillyValue ; 'nother silly comment
229 test_expect_success
'unset' '
230 git config --unset beta.haha &&
231 test_cmp expect .git/config
235 [beta] ; silly comment # another comment
236 noIndent= sillyValue ; 'nother silly comment
242 NoNewLine = wow2 for me
244 test_expect_success
'multivar' '
245 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
246 test_cmp expect .git/config
249 test_expect_success
'non-match' '
250 git config --get nextsection.nonewline !for
253 test_expect_success
'non-match value' '
255 git config --get nextsection.nonewline !for >actual &&
256 test_cmp expect actual
259 test_expect_success
'multi-valued get returns final one' '
260 echo "wow2 for me" >expect &&
261 git config --get nextsection.nonewline >actual &&
262 test_cmp expect actual
265 test_expect_success
'multi-valued get-all returns all' '
266 cat >expect <<-\EOF &&
270 git config --get-all nextsection.nonewline >actual &&
271 test_cmp expect actual
275 [beta] ; silly comment # another comment
276 noIndent= sillyValue ; 'nother silly comment
282 NoNewLine = wow2 for me
284 test_expect_success
'multivar replace' '
285 git config nextsection.nonewline "wow3" "wow$" &&
286 test_cmp expect .git/config
289 test_expect_success
'ambiguous unset' '
290 test_must_fail git config --unset nextsection.nonewline
293 test_expect_success
'invalid unset' '
294 test_must_fail git config --unset somesection.nonewline
298 [beta] ; silly comment # another comment
299 noIndent= sillyValue ; 'nother silly comment
304 NoNewLine = wow2 for me
307 test_expect_success
'multivar unset' '
308 git config --unset nextsection.nonewline "wow3$" &&
309 test_cmp expect .git/config
312 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
314 test_expect_success
'correct key' 'git config 123456.a123 987'
316 test_expect_success
'hierarchical section' '
317 git config Version.1.2.3eX.Alpha beta
321 [beta] ; silly comment # another comment
322 noIndent= sillyValue ; 'nother silly comment
327 NoNewLine = wow2 for me
334 test_expect_success
'hierarchical section value' '
335 test_cmp expect .git/config
339 beta.noindent=sillyValue
340 nextsection.nonewline=wow2 for me
342 version.1.2.3eX.alpha=beta
345 test_expect_success
'working --list' '
346 git config --list > output &&
347 test_cmp expect output
352 test_expect_success
'--list without repo produces empty output' '
353 git --git-dir=nonexistent config --list >output &&
354 test_cmp expect output
359 nextsection.nonewline
361 version.1.2.3eX.alpha
364 test_expect_success
'--name-only --list' '
365 git config --name-only --list >output &&
366 test_cmp expect output
370 beta.noindent sillyValue
371 nextsection.nonewline wow2 for me
374 test_expect_success
'--get-regexp' '
375 git config --get-regexp in >output &&
376 test_cmp expect output
381 nextsection.nonewline
384 test_expect_success
'--name-only --get-regexp' '
385 git config --name-only --get-regexp in >output &&
386 test_cmp expect output
394 test_expect_success
'--add' '
395 git config --add nextsection.nonewline "wow4 for you" &&
396 git config --get-all nextsection.nonewline > output &&
397 test_cmp expect output
400 cat > .git
/config
<< EOF
407 test_expect_success
'get variable with no value' '
408 git config --get novalue.variable ^$
411 test_expect_success
'get variable with empty value' '
412 git config --get emptyvalue.variable ^$
415 echo novalue.variable
> expect
417 test_expect_success
'get-regexp variable with no value' '
418 git config --get-regexp novalue > output &&
419 test_cmp expect output
422 echo 'novalue.variable true' > expect
424 test_expect_success
'get-regexp --bool variable with no value' '
425 git config --bool --get-regexp novalue > output &&
426 test_cmp expect output
429 echo 'emptyvalue.variable ' > expect
431 test_expect_success
'get-regexp variable with empty value' '
432 git config --get-regexp emptyvalue > output &&
433 test_cmp expect output
438 test_expect_success
'get bool variable with no value' '
439 git config --bool novalue.variable > output &&
440 test_cmp expect output
445 test_expect_success
'get bool variable with empty value' '
446 git config --bool emptyvalue.variable > output &&
447 test_cmp expect output
450 test_expect_success
'no arguments, but no crash' '
451 test_must_fail git config >output 2>&1 &&
452 test_i18ngrep usage output
455 cat > .git
/config
<< EOF
467 test_expect_success
'new section is partial match of another' '
469 test_cmp expect .git/config
482 test_expect_success
'new variable inserts into proper section' '
485 test_cmp expect .git/config
488 test_expect_success
'alternative --file (non-existing file should fail)' '
489 test_must_fail git config --file non-existing-config -l
492 cat > other-config
<< EOF
501 test_expect_success
'alternative GIT_CONFIG' '
502 GIT_CONFIG=other-config git config --list >output &&
503 test_cmp expect output
506 test_expect_success
'alternative GIT_CONFIG (--file)' '
507 git config --file other-config --list >output &&
508 test_cmp expect output
511 test_expect_success
'alternative GIT_CONFIG (--file=-)' '
512 git config --file - --list <other-config >output &&
513 test_cmp expect output
516 test_expect_success
'setting a value in stdin is an error' '
517 test_must_fail git config --file - some.value foo
520 test_expect_success
'editing stdin is an error' '
521 test_must_fail git config --file - --edit
524 test_expect_success
'refer config from subdirectory' '
528 echo strasse >expect &&
529 git config --get --file ../other-config ein.bahn >actual &&
530 test_cmp expect actual
535 test_expect_success
'refer config from subdirectory via --file' '
538 git config --file=../other-config --get ein.bahn >actual &&
539 test_cmp expect actual
550 test_expect_success
'--set in alternative file' '
551 git config --file=other-config anwohner.park ausweis &&
552 test_cmp expect other-config
555 cat > .git
/config
<< EOF
562 [branch "1 234 blabl/a"]
566 test_expect_success
'rename section' '
567 git config --rename-section branch.eins branch.zwei
577 [branch "1 234 blabl/a"]
581 test_expect_success
'rename succeeded' '
582 test_cmp expect .git/config
585 test_expect_success
'rename non-existing section' '
586 test_must_fail git config --rename-section \
587 branch."world domination" branch.drei
590 test_expect_success
'rename succeeded' '
591 test_cmp expect .git/config
594 test_expect_success
'rename another section' '
595 git config --rename-section branch."1 234 blabl/a" branch.drei
609 test_expect_success
'rename succeeded' '
610 test_cmp expect .git/config
613 cat >> .git
/config
<< EOF
614 [branch "vier"] z = 1
617 test_expect_success
'rename a section with a var on the same line' '
618 git config --rename-section branch.vier branch.zwei
634 test_expect_success
'rename succeeded' '
635 test_cmp expect .git/config
638 test_expect_success
'renaming empty section name is rejected' '
639 test_must_fail git config --rename-section branch.zwei ""
642 test_expect_success
'renaming to bogus section is rejected' '
643 test_must_fail git config --rename-section branch.zwei "bogus name"
646 cat >> .git
/config
<< EOF
647 [branch "zwei"] a = 1 [branch "vier"]
650 test_expect_success
'remove section' '
651 git config --remove-section branch.zwei
661 test_expect_success
'section was removed properly' '
662 test_cmp expect .git/config
668 dbname = %Ggitcvs2.%a.%m.sqlite
670 dbname = %Ggitcvs1.%a.%m.sqlite
673 test_expect_success
'section ending' '
675 git config gitcvs.enabled true &&
676 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
677 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
678 test_cmp expect .git/config
682 test_expect_success numbers
'
683 git config kilo.gram 1k &&
684 git config mega.ton 1m &&
686 echo 1048576 >>expect &&
687 git config --int --get kilo.gram >actual &&
688 git config --int --get mega.ton >>actual &&
689 test_cmp expect actual
692 test_expect_success
'--int is at least 64 bits' '
693 git config giga.watts 121g &&
694 echo 129922760704 >expect &&
695 git config --int --get giga.watts >actual &&
696 test_cmp expect actual
699 test_expect_success
'invalid unit' '
700 git config aninvalid.unit "1auto" &&
701 echo 1auto >expect &&
702 git config aninvalid.unit >actual &&
703 test_cmp expect actual &&
704 test_must_fail git config --int --get aninvalid.unit 2>actual &&
705 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
708 test_expect_success
'line number is reported correctly' '
709 printf "[bool]\n\tvar\n" >invalid &&
710 test_must_fail git config -f invalid --path bool.var 2>actual &&
711 test_i18ngrep "line 2" actual
714 test_expect_success
'invalid stdin config' '
715 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
716 test_i18ngrep "bad config line 1 in standard input" output
730 test_expect_success bool
'
732 git config bool.true1 01 &&
733 git config bool.true2 -1 &&
734 git config bool.true3 YeS &&
735 git config bool.true4 true &&
736 git config bool.false1 000 &&
737 git config bool.false2 "" &&
738 git config bool.false3 nO &&
739 git config bool.false4 FALSE &&
743 git config --bool --get bool.true$i >>result
744 git config --bool --get bool.false$i >>result
746 test_cmp expect result'
748 test_expect_success
'invalid bool (--get)' '
750 git config bool.nobool foobar &&
751 test_must_fail git config --bool --get bool.nobool'
753 test_expect_success
'invalid bool (set)' '
755 test_must_fail git config --bool bool.nobool foobar'
769 test_expect_success
'set --bool' '
772 git config --bool bool.true1 01 &&
773 git config --bool bool.true2 -1 &&
774 git config --bool bool.true3 YeS &&
775 git config --bool bool.true4 true &&
776 git config --bool bool.false1 000 &&
777 git config --bool bool.false2 "" &&
778 git config --bool bool.false3 nO &&
779 git config --bool bool.false4 FALSE &&
780 test_cmp expect .git/config'
789 test_expect_success
'set --int' '
792 git config --int int.val1 01 &&
793 git config --int int.val2 -1 &&
794 git config --int int.val3 5m &&
795 test_cmp expect .git/config
798 test_expect_success
'get --bool-or-int' '
799 cat >.git/config <<-\EOF &&
809 cat >expect <<-\EOF &&
818 git config --bool-or-int bool.true1 &&
819 git config --bool-or-int bool.true2 &&
820 git config --bool-or-int bool.false &&
821 git config --bool-or-int int.int1 &&
822 git config --bool-or-int int.int2 &&
823 git config --bool-or-int int.int3
825 test_cmp expect actual
840 test_expect_success
'set --bool-or-int' '
842 git config --bool-or-int bool.true1 true &&
843 git config --bool-or-int bool.false1 false &&
844 git config --bool-or-int bool.true2 yes &&
845 git config --bool-or-int bool.false2 no &&
846 git config --bool-or-int int.int1 0 &&
847 git config --bool-or-int int.int2 1 &&
848 git config --bool-or-int int.int3 -1 &&
849 test_cmp expect .git/config
859 test_expect_success
!MINGW
'set --path' '
861 git config --path path.home "~/" &&
862 git config --path path.normal "/dev/null" &&
863 git config --path path.trailingtilde "foo~" &&
864 test_cmp expect .git/config'
866 if test_have_prereq
!MINGW
&& test "${HOME+set}"
868 test_set_prereq HOMEVAR
877 test_expect_success HOMEVAR
'get --path' '
878 git config --get --path path.home > result &&
879 git config --get --path path.normal >> result &&
880 git config --get --path path.trailingtilde >> result &&
881 test_cmp expect result
889 test_expect_success
!MINGW
'get --path copes with unset $HOME' '
892 test_must_fail git config --get --path path.home \
894 git config --get --path path.normal >>result &&
895 git config --get --path path.trailingtilde >>result
897 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
898 test_cmp expect result
901 test_expect_success
'get --path barfs on boolean variable' '
902 echo "[path]bool" >.git/config &&
903 test_must_fail git config --get --path path.bool
906 test_expect_success
'get --expiry-date' '
907 rel="3.weeks.5.days.00:00" &&
909 cat >.git/config <<-\EOF &&
911 valid1 = "3.weeks.5.days 00:00"
912 valid2 = "Fri Jun 4 15:46:55 2010"
913 valid3 = "2017/11/11 11:11:11PM"
914 valid4 = "2017/11/10 09:08:07 PM"
918 cat >expect <<-EOF &&
919 $(test-tool date timestamp $rel)
926 echo "$rel_out $(git config --expiry-date date.valid1)"
927 git config --expiry-date date.valid2 &&
928 git config --expiry-date date.valid3 &&
929 git config --expiry-date date.valid4 &&
930 git config --expiry-date date.valid5
932 test_cmp expect actual &&
933 test_must_fail git config --expiry-date date.invalid1
936 test_expect_success
'get --type=color' '
938 git config foo.color "red" &&
939 git config --get --type=color foo.color >actual.raw &&
940 test_decode_color <actual.raw >actual &&
941 echo "<RED>" >expect &&
942 test_cmp expect actual
950 test_expect_success
'set --type=color' '
952 git config --type=color foo.color "red" &&
953 test_cmp expect .git/config
956 test_expect_success
'get --type=color barfs on non-color' '
957 echo "[foo]bar=not-a-color" >.git/config &&
958 test_must_fail git config --get --type=color foo.bar
961 test_expect_success
'set --type=color barfs on non-color' '
962 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
963 test_i18ngrep "cannot parse color" error
970 semicolon = "test;test"
973 test_expect_success
'quoting' '
975 git config quote.leading " test" &&
976 git config quote.ending "test " &&
977 git config quote.semicolon "test;test" &&
978 git config quote.hash "test#test" &&
979 test_cmp expect .git/config
982 test_expect_success
'key with newline' '
983 test_must_fail git config "key.with
986 test_expect_success
'value with newline' 'git config key.sub value.with\\\
989 cat > .git
/config
<<\EOF
994 noncont
= not continued
; \
1000 section.continued
=continued
1001 section.noncont
=not continued
1002 section.quotecont
=cont
;inued
1005 test_expect_success
'value continued on next line' '
1006 git config --list > result &&
1007 test_cmp result expect
1010 cat > .git
/config
<<\EOF
1011 [section
"sub=section"]
1020 section.sub
=section.val1
1021 foo
=barQsection.sub
=section.val2
1023 barQsection.sub
=section.val3
1026 Qsection.sub
=section.val4
1027 Qsection.sub
=section.val5Q
1029 test_expect_success
'--null --list' '
1030 git config --null --list >result.raw &&
1031 nul_to_q <result.raw >result &&
1033 test_cmp expect result
1036 test_expect_success
'--null --get-regexp' '
1037 git config --null --get-regexp "val[0-9]" >result.raw &&
1038 nul_to_q <result.raw >result &&
1040 test_cmp expect result
1043 test_expect_success
'inner whitespace kept verbatim' '
1044 git config section.val "foo bar" &&
1045 echo "foo bar" >expect &&
1046 git config section.val >actual &&
1047 test_cmp expect actual
1050 test_expect_success SYMLINKS
'symlinked configuration' '
1051 ln -s notyet myconfig &&
1052 git config --file=myconfig test.frotz nitfol &&
1055 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1056 git config --file=myconfig test.xyzzy rezrov &&
1059 cat >expect <<-\EOF &&
1064 git config --file=notyet test.frotz &&
1065 git config --file=notyet test.xyzzy
1067 test_cmp expect actual
1070 test_expect_success
'nonexistent configuration' '
1071 test_must_fail git config --file=doesnotexist --list &&
1072 test_must_fail git config --file=doesnotexist test.xyzzy
1075 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
1076 ln -s doesnotexist linktonada &&
1077 ln -s linktonada linktolinktonada &&
1078 test_must_fail git config --file=linktonada --list &&
1079 test_must_fail git config --file=linktolinktonada --list
1082 test_expect_success
'check split_cmdline return' "
1083 git config alias.split-cmdline-fix 'echo \"' &&
1084 test_must_fail git split-cmdline-fix &&
1087 git commit -m 'initial commit' &&
1088 git config branch.master.mergeoptions 'echo \"' &&
1089 test_must_fail git merge master
1092 test_expect_success
'git -c "key=value" support' '
1093 cat >expect <<-\EOF &&
1099 git -c core.name=value config core.name &&
1100 git -c foo.CamelCase=value config foo.camelcase &&
1101 git -c foo.flag config --bool foo.flag
1103 test_cmp expect actual &&
1104 test_must_fail git -c name=value config core.name
1107 # We just need a type-specifier here that cares about the
1108 # distinction internally between a NULL boolean and a real
1109 # string (because most of git's internal parsers do care).
1110 # Using "--path" works, but we do not otherwise care about
1112 test_expect_success
'git -c can represent empty string' '
1114 git -c foo.empty= config --path foo.empty >actual &&
1115 test_cmp expect actual
1118 test_expect_success
'key sanity-checking' '
1119 test_must_fail git config foo=bar &&
1120 test_must_fail git config foo=.bar &&
1121 test_must_fail git config foo.ba=r &&
1122 test_must_fail git config foo.1bar &&
1123 test_must_fail git config foo."ba
1125 test_must_fail git config . false &&
1126 test_must_fail git config .foo false &&
1127 test_must_fail git config foo. false &&
1128 test_must_fail git config .foo. false &&
1129 git config foo.bar true &&
1130 git config foo."ba =z".bar false
1133 test_expect_success
'git -c works with aliases of builtins' '
1134 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1136 git checkconfig >actual &&
1137 test_cmp expect actual
1140 test_expect_success
'aliases can be CamelCased' '
1141 test_config alias.CamelCased "rev-parse HEAD" &&
1142 git CamelCased >out &&
1143 git rev-parse HEAD >expect &&
1147 test_expect_success
'git -c does not split values on equals' '
1148 echo "value with = in it" >expect &&
1149 git -c core.foo="value with = in it" config core.foo >actual &&
1150 test_cmp expect actual
1153 test_expect_success
'git -c dies on bogus config' '
1154 test_must_fail git -c core.bare=foo rev-parse
1157 test_expect_success
'git -c complains about empty key' '
1158 test_must_fail git -c "=foo" rev-parse
1161 test_expect_success
'git -c complains about empty key and value' '
1162 test_must_fail git -c "" rev-parse
1165 test_expect_success
'multiple git -c appends config' '
1166 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1167 cat >expect <<-\EOF &&
1171 git -c x.one=1 x >actual &&
1172 test_cmp expect actual
1175 test_expect_success
'last one wins: two level vars' '
1177 # sec.var and sec.VAR are the same variable, as the first
1178 # and the last level of a configuration variable name is
1183 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1184 test_cmp expect actual &&
1185 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1186 test_cmp expect actual &&
1188 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1189 test_cmp expect actual &&
1190 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1191 test_cmp expect actual
1194 test_expect_success
'last one wins: three level vars' '
1196 # v.a.r and v.A.r are not the same variable, as the middle
1197 # level of a three-level configuration variable name is
1201 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1202 test_cmp expect actual &&
1203 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1204 test_cmp expect actual &&
1206 # v.a.r and V.a.R are the same variable, as the first
1207 # and the last level of a configuration variable name is
1211 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1212 test_cmp expect actual &&
1213 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1214 test_cmp expect actual &&
1215 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1216 test_cmp expect actual &&
1217 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1218 test_cmp expect actual
1221 test_expect_success
'old-fashioned settings are case insensitive' '
1222 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1224 cat >testConfig_actual <<-EOF &&
1228 q_to_tab >testConfig_expect <<-EOF &&
1232 git config -f testConfig_actual "v.a.r" value2 &&
1233 test_cmp testConfig_expect testConfig_actual &&
1235 cat >testConfig_actual <<-EOF &&
1239 q_to_tab >testConfig_expect <<-EOF &&
1243 git config -f testConfig_actual "V.a.R" value2 &&
1244 test_cmp testConfig_expect testConfig_actual &&
1246 cat >testConfig_actual <<-EOF &&
1250 q_to_tab >testConfig_expect <<-EOF &&
1255 git config -f testConfig_actual "V.A.r" value2 &&
1256 test_cmp testConfig_expect testConfig_actual &&
1258 cat >testConfig_actual <<-EOF &&
1262 q_to_tab >testConfig_expect <<-EOF &&
1267 git config -f testConfig_actual "v.A.r" value2 &&
1268 test_cmp testConfig_expect testConfig_actual
1271 test_expect_success
'setting different case sensitive subsections ' '
1272 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1274 cat >testConfig_actual <<-EOF &&
1284 q_to_tab >testConfig_expect <<-EOF &&
1297 git config -f testConfig_actual a.b.c v2 &&
1298 # match section and subsection, key is cased differently.
1299 git config -f testConfig_actual K.E.y v2 &&
1300 # section and key are matched case insensitive, but subsection needs
1301 # to match; When writing out new values only the key is adjusted
1302 git config -f testConfig_actual v.A.r v2 &&
1303 # subsection is not matched:
1304 git config -f testConfig_actual d.E.f v2 &&
1305 test_cmp testConfig_expect testConfig_actual
1308 for VAR
in a .a a. a
.0b a.
"b c". a.
"b c".0d
1310 test_expect_success
"git -c $VAR=VAL rejects invalid '$VAR'" '
1311 test_must_fail git -c "$VAR=VAL" config -l
1315 for VAR
in a.b a.
"b c".d
1317 test_expect_success
"git -c $VAR=VAL works with valid '$VAR'" '
1319 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1320 test_cmp expect actual
1324 test_expect_success
'git -c is not confused by empty environment' '
1325 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1329 test_expect_success
'detect bogus GIT_CONFIG_PARAMETERS' '
1330 cat >expect <<-\EOF &&
1334 GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq} ${sq}env.two=two${sq}" \
1335 git config --get-regexp "env.*" >actual &&
1336 test_cmp expect actual &&
1338 cat >expect <<-EOF &&
1342 GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq$sq$sq ${sq}env.two=two${sq}" \
1343 git config --get-regexp "env.*" >actual &&
1344 test_cmp expect actual &&
1346 test_must_fail env \
1347 GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq ${sq}env.two=two${sq}" \
1348 git config --get-regexp "env.*"
1351 test_expect_success
'git config --edit works' '
1352 git config -f tmp test.value no &&
1353 echo test.value=yes >expect &&
1354 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1355 git config -f tmp --list >actual &&
1356 test_cmp expect actual
1359 test_expect_success
'git config --edit respects core.editor' '
1360 git config -f tmp test.value no &&
1361 echo test.value=yes >expect &&
1362 test_config core.editor "echo [test]value=yes >" &&
1363 git config -f tmp --edit &&
1364 git config -f tmp --list >actual &&
1365 test_cmp expect actual
1368 # malformed configuration files
1369 test_expect_success
'barf on syntax error' '
1370 cat >.git/config <<-\EOF &&
1371 # broken section line
1375 test_must_fail git config --get section.key >actual 2>error &&
1376 test_i18ngrep " line 3 " error
1379 test_expect_success
'barf on incomplete section header' '
1380 cat >.git/config <<-\EOF &&
1381 # broken section line
1385 test_must_fail git config --get section.key >actual 2>error &&
1386 test_i18ngrep " line 2 " error
1389 test_expect_success
'barf on incomplete string' '
1390 cat >.git/config <<-\EOF &&
1391 # broken section line
1395 test_must_fail git config --get section.key >actual 2>error &&
1396 test_i18ngrep " line 3 " error
1399 test_expect_success
'urlmatch' '
1400 cat >.git/config <<-\EOF &&
1403 [http "https://weak.example.com"]
1405 cookieFile = /tmp/cookie.txt
1408 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1409 test_must_be_empty actual &&
1411 echo true >expect &&
1412 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1413 test_cmp expect actual &&
1415 echo false >expect &&
1416 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1417 test_cmp expect actual &&
1420 echo http.cookiefile /tmp/cookie.txt &&
1421 echo http.sslverify false
1423 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1424 test_cmp expect actual
1427 test_expect_success
'urlmatch favors more specific URLs' '
1428 cat >.git/config <<-\EOF &&
1429 [http "https://example.com/"]
1430 cookieFile = /tmp/root.txt
1431 [http "https://example.com/subdirectory"]
1432 cookieFile = /tmp/subdirectory.txt
1433 [http "https://user@example.com/"]
1434 cookieFile = /tmp/user.txt
1435 [http "https://averylonguser@example.com/"]
1436 cookieFile = /tmp/averylonguser.txt
1437 [http "https://preceding.example.com"]
1438 cookieFile = /tmp/preceding.txt
1439 [http "https://*.example.com"]
1440 cookieFile = /tmp/wildcard.txt
1441 [http "https://*.example.com/wildcardwithsubdomain"]
1442 cookieFile = /tmp/wildcardwithsubdomain.txt
1443 [http "https://trailing.example.com"]
1444 cookieFile = /tmp/trailing.txt
1445 [http "https://user@*.example.com/"]
1446 cookieFile = /tmp/wildcardwithuser.txt
1447 [http "https://sub.example.com/"]
1448 cookieFile = /tmp/sub.txt
1451 echo http.cookiefile /tmp/root.txt >expect &&
1452 git config --get-urlmatch HTTP https://example.com >actual &&
1453 test_cmp expect actual &&
1455 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1456 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1457 test_cmp expect actual &&
1459 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1460 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1461 test_cmp expect actual &&
1463 echo http.cookiefile /tmp/user.txt >expect &&
1464 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1465 test_cmp expect actual &&
1467 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1468 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1469 test_cmp expect actual &&
1471 echo http.cookiefile /tmp/preceding.txt >expect &&
1472 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1473 test_cmp expect actual &&
1475 echo http.cookiefile /tmp/wildcard.txt >expect &&
1476 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1477 test_cmp expect actual &&
1479 echo http.cookiefile /tmp/sub.txt >expect &&
1480 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1481 test_cmp expect actual &&
1483 echo http.cookiefile /tmp/trailing.txt >expect &&
1484 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1485 test_cmp expect actual &&
1487 echo http.cookiefile /tmp/sub.txt >expect &&
1488 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1489 test_cmp expect actual
1492 test_expect_success
'urlmatch with wildcard' '
1493 cat >.git/config <<-\EOF &&
1496 [http "https://*.example.com"]
1498 cookieFile = /tmp/cookie.txt
1501 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1502 test_must_be_empty actual &&
1504 echo true >expect &&
1505 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1506 test_cmp expect actual &&
1508 echo true >expect &&
1509 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1510 test_cmp expect actual &&
1512 echo true >expect &&
1513 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1514 test_cmp expect actual &&
1516 echo false >expect &&
1517 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1518 test_cmp expect actual &&
1521 echo http.cookiefile /tmp/cookie.txt &&
1522 echo http.sslverify false
1524 git config --get-urlmatch HTTP https://good.example.com >actual &&
1525 test_cmp expect actual &&
1527 echo http.sslverify >expect &&
1528 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1529 test_cmp expect actual
1532 # good section hygiene
1533 test_expect_success
'--unset last key removes section (except if commented)' '
1534 cat >.git/config <<-\EOF &&
1535 # some generic comment on the configuration file itself
1536 # a comment specific to this "section" section.
1538 # some intervening lines
1539 # that should also be dropped
1542 # please be careful when you update the above variable
1545 cat >expect <<-\EOF &&
1546 # some generic comment on the configuration file itself
1547 # a comment specific to this "section" section.
1549 # some intervening lines
1550 # that should also be dropped
1552 # please be careful when you update the above variable
1555 git config --unset section.key &&
1556 test_cmp expect .git/config &&
1558 cat >.git/config <<-\EOF &&
1564 cat >expect <<-\EOF &&
1568 git config --unset section.key &&
1569 test_cmp expect .git/config &&
1571 q_to_tab >.git/config <<-\EOF &&
1578 git config --unset two.key &&
1579 ! grep two .git/config &&
1581 q_to_tab >.git/config <<-\EOF &&
1588 git config --unset-all one.key &&
1589 test_line_count = 0 .git/config &&
1591 q_to_tab >.git/config <<-\EOF &&
1594 Q# a comment not at the start
1598 git config --unset two.key &&
1599 grep two .git/config &&
1601 q_to_tab >.git/config <<-\EOF &&
1603 Qkey = not [two "subsection"]
1610 git config --unset two.subsection.key &&
1611 test "not [two subsection]" = "$(git config one.key)" &&
1612 test_line_count = 3 .git/config
1615 test_expect_success
'--unset-all removes section if empty & uncommented' '
1616 cat >.git/config <<-\EOF &&
1622 git config --unset-all section.key &&
1623 test_line_count = 0 .git/config
1626 test_expect_success
'adding a key into an empty section reuses header' '
1627 cat >.git/config <<-\EOF &&
1631 q_to_tab >expect <<-\EOF &&
1636 git config section.key value &&
1637 test_cmp expect .git/config
1640 test_expect_success POSIXPERM
,PERL
'preserves existing permissions' '
1641 chmod 0600 .git/config &&
1642 git config imap.pass Hunter2 &&
1644 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1645 git config --rename-section imap pop &&
1647 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1650 ! test_have_prereq MINGW ||
1651 HOME
="$(pwd)" # convert to Windows path
1653 test_expect_success
'set up --show-origin tests' '
1654 INCLUDE_DIR="$HOME/include" &&
1655 mkdir -p "$INCLUDE_DIR" &&
1656 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1660 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1664 cat >"$HOME"/.gitconfig <<-EOF &&
1669 path = "$INCLUDE_DIR/absolute.include"
1671 cat >.git/config <<-\EOF
1676 path = ../include/relative.include
1680 test_expect_success
'--show-origin with --list' '
1681 cat >expect <<-EOF &&
1682 file:$HOME/.gitconfig user.global=true
1683 file:$HOME/.gitconfig user.override=global
1684 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1685 file:$INCLUDE_DIR/absolute.include user.absolute=include
1686 file:.git/config user.local=true
1687 file:.git/config user.override=local
1688 file:.git/config include.path=../include/relative.include
1689 file:.git/../include/relative.include user.relative=include
1690 command line: user.cmdline=true
1692 git -c user.cmdline=true config --list --show-origin >output &&
1693 test_cmp expect output
1696 test_expect_success
'--show-origin with --list --null' '
1697 cat >expect <<-EOF &&
1698 file:$HOME/.gitconfigQuser.global
1699 trueQfile:$HOME/.gitconfigQuser.override
1700 globalQfile:$HOME/.gitconfigQinclude.path
1701 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1702 includeQfile:.git/configQuser.local
1703 trueQfile:.git/configQuser.override
1704 localQfile:.git/configQinclude.path
1705 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1706 includeQcommand line:Quser.cmdline
1709 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1710 nul_to_q <output.raw >output &&
1711 # The here-doc above adds a newline that the --null output would not
1712 # include. Add it here to make the two comparable.
1714 test_cmp expect output
1717 test_expect_success
'--show-origin with single file' '
1718 cat >expect <<-\EOF &&
1719 file:.git/config user.local=true
1720 file:.git/config user.override=local
1721 file:.git/config include.path=../include/relative.include
1723 git config --local --list --show-origin >output &&
1724 test_cmp expect output
1727 test_expect_success
'--show-origin with --get-regexp' '
1728 cat >expect <<-EOF &&
1729 file:$HOME/.gitconfig user.global true
1730 file:.git/config user.local true
1732 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1733 test_cmp expect output
1736 test_expect_success
'--show-origin getting a single key' '
1737 cat >expect <<-\EOF &&
1738 file:.git/config local
1740 git config --show-origin user.override >output &&
1741 test_cmp expect output
1744 test_expect_success
'set up custom config file' '
1745 CUSTOM_CONFIG_FILE="file\" (dq) and spaces.conf" &&
1746 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1752 test_expect_success
!MINGW
'--show-origin escape special file name characters' '
1753 cat >expect <<-\EOF &&
1754 file:"file\" (dq) and spaces.conf" user.custom=true
1756 git config --file "$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1757 test_cmp expect output
1760 test_expect_success
'--show-origin stdin' '
1761 cat >expect <<-\EOF &&
1762 standard input: user.custom=true
1764 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1765 test_cmp expect output
1768 test_expect_success
'--show-origin stdin with file include' '
1769 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1773 cat >expect <<-EOF &&
1774 file:$INCLUDE_DIR/stdin.include include
1776 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" \
1777 | git config --show-origin --includes --file - user.stdin >output &&
1778 test_cmp expect output
1781 test_expect_success
!MINGW
'--show-origin blob' '
1782 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1783 cat >expect <<-EOF &&
1784 blob:$blob user.custom=true
1786 git config --blob=$blob --show-origin --list >output &&
1787 test_cmp expect output
1790 test_expect_success
!MINGW
'--show-origin blob ref' '
1791 cat >expect <<-\EOF &&
1792 blob:"master:file\" (dq) and spaces.conf" user.custom=true
1794 git add "$CUSTOM_CONFIG_FILE" &&
1795 git commit -m "new config file" &&
1796 git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1797 test_cmp expect output
1800 test_expect_success
'--local requires a repo' '
1801 # we expect 128 to ensure that we do not simply
1802 # fail to find anything and return code "1"
1803 test_expect_code 128 nongit git config --local foo.bar
1806 cat >.git
/config
<<-\EOF &&
1813 test_expect_success 'identical modern --type specifiers are allowed' '
1814 git config --type=int --type=int core.big >actual &&
1815 echo 1048576 >expect &&
1816 test_cmp expect actual
1819 test_expect_success 'identical legacy --type specifiers are allowed' '
1820 git config --int --int core.big >actual &&
1821 echo 1048576 >expect &&
1822 test_cmp expect actual
1825 test_expect_success 'identical mixed --type specifiers are allowed' '
1826 git config --int --type=int core.big >actual &&
1827 echo 1048576 >expect &&
1828 test_cmp expect actual
1831 test_expect_success 'non-identical modern --type specifiers are not allowed' '
1832 test_must_fail git config --type=int --type=bool core.big 2>error &&
1833 test_i18ngrep "only one type at a time" error
1836 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
1837 test_must_fail git config --int --bool core.big 2>error &&
1838 test_i18ngrep "only one type at a time" error
1841 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
1842 test_must_fail git config --type=int --bool core.big 2>error &&
1843 test_i18ngrep "only one type at a time" error
1846 test_expect_success '--type allows valid type specifiers' '
1847 echo "true" >expect &&
1848 git config --type=bool core.foo >actual &&
1849 test_cmp expect actual
1852 test_expect_success '--no-type unsets type specifiers' '
1853 echo "10" >expect &&
1854 git config --type=bool --no-type core.number >actual &&
1855 test_cmp expect actual
1858 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
1859 echo 1048576 >expect &&
1860 git config --type=bool --no-type --type=int core.big >actual &&
1861 test_cmp expect actual
1864 test_expect_success '--type rejects unknown specifiers' '
1865 test_must_fail git config --type=nonsense core.foo 2>error &&
1866 test_i18ngrep "unrecognized --type argument" error
1869 test_expect_success '--replace-all does not invent newlines' '
1870 q_to_tab >.git/config <<-\
EOF &&
1878 q_to_tab >expect <<-\EOF &&
1886 git config --replace-all abc.key b &&
1887 test_cmp .git/config expect