3 # Copyright (c) 2005 Johannes Schindelin
6 test_description
='Test git config in different settings'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
14 test_expect_success
'clear default config' '
22 test_expect_success
'initial' '
23 git config section.penguin "little blue" &&
24 test_cmp expect .git/config
32 test_expect_success
'mixed case' '
33 git config Section.Movie BadPhysics &&
34 test_cmp expect .git/config
44 test_expect_success
'similar section' '
45 git config Sections.WhatEver Second &&
46 test_cmp expect .git/config
57 test_expect_success
'uppercase section' '
58 git config SECTION.UPPERCASE true &&
59 test_cmp expect .git/config
62 test_expect_success
'replace with non-match' '
63 git config section.penguin kingpin !blue
66 test_expect_success
'replace with non-match (actually matching)' '
67 git config section.penguin "very blue" !kingpin
74 penguin = gentoo #Pygoscelis papua
75 disposition = peckish #find fish
80 test_expect_success
'append comments' '
81 git config --replace-all --comment="Pygoscelis papua" section.penguin gentoo &&
82 git config --comment="find fish" section.disposition peckish &&
83 git config --comment="# abc" section.foo bar &&
84 test_cmp expect .git/config
87 test_expect_success
'Prohibited LF in comment' '
88 test_must_fail git config --comment="a${LF}b" section.k v
91 test_expect_success
'non-match result' 'test_cmp expect .git/config'
93 test_expect_success
'find mixed-case key by canonical name' '
94 test_cmp_config Second sections.whatever
97 test_expect_success
'find mixed-case key by non-canonical name' '
98 test_cmp_config Second SeCtIoNs.WhAtEvEr
101 test_expect_success
'subsections are not canonicalized by git-config' '
102 cat >>.git/config <<-\EOF &&
105 [section "SubSection"]
108 test_cmp_config one section.subsection.key &&
109 test_cmp_config two section.SubSection.key
112 test_missing_key
() {
115 test_expect_success
"value for $title is not printed" '
116 test_must_fail git config "$key" >out 2>err &&
117 test_must_be_empty out &&
118 test_must_be_empty err
122 test_missing_key
'missingsection.missingkey' 'missing section and missing key'
123 test_missing_key
'missingsection.penguin' 'missing section and existing key'
124 test_missing_key
'section.missingkey' 'existing section and missing key'
125 test_missing_key
'section.MissingSubSection.missingkey' 'missing subsection and missing key'
126 test_missing_key
'section.SubSection.missingkey' 'existing subsection and missing key'
127 test_missing_key
'section.MissingSubSection.key' 'missing subsection and existing key'
129 cat > .git
/config
<<\EOF
138 test_expect_success
'unset with cont. lines' '
139 git config --unset beta.baz
149 test_expect_success
'unset with cont. lines is correct' 'test_cmp expect .git/config'
151 cat > .git
/config
<< EOF
152 [beta] ; silly comment # another comment
153 noIndent= sillyValue ; 'nother silly comment
157 haha ="beta" # last silly comment
160 [nextSection] noNewline = ouch
163 cp .git
/config .git
/config2
165 test_expect_success
'multiple unset' '
166 git config --unset-all beta.haha
170 [beta] ; silly comment # another comment
171 noIndent= sillyValue ; 'nother silly comment
175 [nextSection] noNewline = ouch
178 test_expect_success
'multiple unset is correct' '
179 test_cmp expect .git/config
182 cp .git
/config2 .git
/config
184 test_expect_success
'--replace-all missing value' '
185 test_must_fail git config --replace-all beta.haha &&
186 test_cmp .git/config2 .git/config
191 test_expect_success
'--replace-all' '
192 git config --replace-all beta.haha gamma
196 [beta] ; silly comment # another comment
197 noIndent= sillyValue ; 'nother silly comment
202 [nextSection] noNewline = ouch
205 test_expect_success
'all replaced' '
206 test_cmp expect .git/config
210 [beta] ; silly comment # another comment
211 noIndent= sillyValue ; 'nother silly comment
216 [nextSection] noNewline = ouch
218 test_expect_success
'really mean test' '
219 git config beta.haha alpha &&
220 test_cmp expect .git/config
224 [beta] ; silly comment # another comment
225 noIndent= sillyValue ; 'nother silly comment
233 test_expect_success
'really really mean test' '
234 git config nextsection.nonewline wow &&
235 test_cmp expect .git/config
238 test_expect_success
'get value' '
239 test_cmp_config alpha beta.haha
243 [beta] ; silly comment # another comment
244 noIndent= sillyValue ; 'nother silly comment
251 test_expect_success
'unset' '
252 git config --unset beta.haha &&
253 test_cmp expect .git/config
257 [beta] ; silly comment # another comment
258 noIndent= sillyValue ; 'nother silly comment
264 NoNewLine = wow2 for me
266 test_expect_success
'multivar' '
267 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
268 test_cmp expect .git/config
271 test_expect_success
'non-match' '
272 git config --get nextsection.nonewline !for
275 test_expect_success
'non-match value' '
276 test_cmp_config wow --get nextsection.nonewline !for
279 test_expect_success
'multi-valued get returns final one' '
280 test_cmp_config "wow2 for me" --get nextsection.nonewline
283 test_expect_success
'multi-valued get-all returns all' '
284 cat >expect <<-\EOF &&
288 git config --get-all nextsection.nonewline >actual &&
289 test_cmp expect actual
293 [beta] ; silly comment # another comment
294 noIndent= sillyValue ; 'nother silly comment
300 NoNewLine = wow2 for me
302 test_expect_success
'multivar replace' '
303 git config nextsection.nonewline "wow3" "wow$" &&
304 test_cmp expect .git/config
307 test_expect_success
'ambiguous unset' '
308 test_must_fail git config --unset nextsection.nonewline
311 test_expect_success
'invalid unset' '
312 test_must_fail git config --unset somesection.nonewline
316 [beta] ; silly comment # another comment
317 noIndent= sillyValue ; 'nother silly comment
322 NoNewLine = wow2 for me
325 test_expect_success
'multivar unset' '
326 git config --unset nextsection.nonewline "wow3$" &&
327 test_cmp expect .git/config
330 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
332 test_expect_success
'correct key' 'git config 123456.a123 987'
334 test_expect_success
'hierarchical section' '
335 git config Version.1.2.3eX.Alpha beta
339 [beta] ; silly comment # another comment
340 noIndent= sillyValue ; 'nother silly comment
345 NoNewLine = wow2 for me
352 test_expect_success
'hierarchical section value' '
353 test_cmp expect .git/config
357 beta.noindent=sillyValue
358 nextsection.nonewline=wow2 for me
360 version.1.2.3eX.alpha=beta
363 test_expect_success
'working --list' '
364 git config --list > output &&
365 test_cmp expect output
367 test_expect_success
'--list without repo produces empty output' '
368 git --git-dir=nonexistent config --list >output &&
369 test_must_be_empty output
374 nextsection.nonewline
376 version.1.2.3eX.alpha
379 test_expect_success
'--name-only --list' '
380 git config --name-only --list >output &&
381 test_cmp expect output
385 beta.noindent sillyValue
386 nextsection.nonewline wow2 for me
389 test_expect_success
'--get-regexp' '
390 git config --get-regexp in >output &&
391 test_cmp expect output
396 nextsection.nonewline
399 test_expect_success
'--name-only --get-regexp' '
400 git config --name-only --get-regexp in >output &&
401 test_cmp expect output
409 test_expect_success
'--add' '
410 git config --add nextsection.nonewline "wow4 for you" &&
411 git config --get-all nextsection.nonewline > output &&
412 test_cmp expect output
415 cat > .git
/config
<< EOF
422 test_expect_success
'get variable with no value' '
423 git config --get novalue.variable ^$
426 test_expect_success
'get variable with empty value' '
427 git config --get emptyvalue.variable ^$
430 echo novalue.variable
> expect
432 test_expect_success
'get-regexp variable with no value' '
433 git config --get-regexp novalue > output &&
434 test_cmp expect output
437 echo 'novalue.variable true' > expect
439 test_expect_success
'get-regexp --bool variable with no value' '
440 git config --bool --get-regexp novalue > output &&
441 test_cmp expect output
444 echo 'emptyvalue.variable ' > expect
446 test_expect_success
'get-regexp variable with empty value' '
447 git config --get-regexp emptyvalue > output &&
448 test_cmp expect output
453 test_expect_success
'get bool variable with no value' '
454 git config --bool novalue.variable > output &&
455 test_cmp expect output
460 test_expect_success
'get bool variable with empty value' '
461 git config --bool emptyvalue.variable > output &&
462 test_cmp expect output
465 test_expect_success
'no arguments, but no crash' '
466 test_must_fail git config >output 2>&1 &&
467 test_grep usage output
470 cat > .git
/config
<< EOF
482 test_expect_success
'new section is partial match of another' '
484 test_cmp expect .git/config
497 test_expect_success
'new variable inserts into proper section' '
500 test_cmp expect .git/config
503 test_expect_success
'alternative --file (non-existing file should fail)' '
504 test_must_fail git config --file non-existing-config -l &&
505 test_must_fail git config --file non-existing-config test.xyzzy
508 cat > other-config
<< EOF
517 test_expect_success
'alternative GIT_CONFIG' '
518 GIT_CONFIG=other-config git config --list >output &&
519 test_cmp expect output
522 test_expect_success
'alternative GIT_CONFIG (--file)' '
523 git config --file other-config --list >output &&
524 test_cmp expect output
527 test_expect_success
'alternative GIT_CONFIG (--file=-)' '
528 git config --file - --list <other-config >output &&
529 test_cmp expect output
532 test_expect_success
'setting a value in stdin is an error' '
533 test_must_fail git config --file - some.value foo
536 test_expect_success
'editing stdin is an error' '
537 test_must_fail git config --file - --edit
540 test_expect_success
'refer config from subdirectory' '
542 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
552 test_expect_success
'--set in alternative file' '
553 git config --file=other-config anwohner.park ausweis &&
554 test_cmp expect other-config
557 cat > .git
/config
<< EOF
564 [branch "1 234 blabl/a"]
568 test_expect_success
'rename section' '
569 git config --rename-section branch.eins branch.zwei
579 [branch "1 234 blabl/a"]
583 test_expect_success
'rename succeeded' '
584 test_cmp expect .git/config
587 test_expect_success
'rename non-existing section' '
588 test_must_fail git config --rename-section \
589 branch."world domination" branch.drei
592 test_expect_success
'rename succeeded' '
593 test_cmp expect .git/config
596 test_expect_success
'rename another section' '
597 git config --rename-section branch."1 234 blabl/a" branch.drei
611 test_expect_success
'rename succeeded' '
612 test_cmp expect .git/config
615 cat >> .git
/config
<< EOF
616 [branch "vier"] z = 1
619 test_expect_success
'rename a section with a var on the same line' '
620 git config --rename-section branch.vier branch.zwei
636 test_expect_success
'rename succeeded' '
637 test_cmp expect .git/config
640 test_expect_success
'renaming empty section name is rejected' '
641 test_must_fail git config --rename-section branch.zwei ""
644 test_expect_success
'renaming to bogus section is rejected' '
645 test_must_fail git config --rename-section branch.zwei "bogus name"
648 test_expect_success
'renaming a section with a long line' '
651 printf " c = d %1024s [a] e = f\\n" " " &&
652 printf "[a] g = h\\n"
654 git config -f y --rename-section a xyz &&
655 test_must_fail git config -f y b.e
658 test_expect_success
'renaming an embedded section with a long line' '
661 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
662 printf "[a] g = h\\n"
664 git config -f y --rename-section a xyz &&
665 test_must_fail git config -f y foo.e
668 test_expect_success
'renaming a section with an overly-long line' '
671 printf " c = d %525000s e" " " &&
672 printf "[a] g = h\\n"
674 test_must_fail git config -f y --rename-section a xyz 2>err &&
675 grep "refusing to work with overly long line in .y. on line 2" err
678 cat >> .git
/config
<< EOF
679 [branch "zwei"] a = 1 [branch "vier"]
682 test_expect_success
'remove section' '
683 git config --remove-section branch.zwei
693 test_expect_success
'section was removed properly' '
694 test_cmp expect .git/config
700 dbname = %Ggitcvs2.%a.%m.sqlite
702 dbname = %Ggitcvs1.%a.%m.sqlite
705 test_expect_success
'section ending' '
707 git config gitcvs.enabled true &&
708 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
709 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
710 test_cmp expect .git/config
714 test_expect_success numbers
'
715 git config kilo.gram 1k &&
716 git config mega.ton 1m &&
718 echo 1048576 >>expect &&
719 git config --int --get kilo.gram >actual &&
720 git config --int --get mega.ton >>actual &&
721 test_cmp expect actual
724 test_expect_success
'--int is at least 64 bits' '
725 git config giga.watts 121g &&
727 test_cmp_config 129922760704 --int --get giga.watts
730 test_expect_success
'invalid unit' '
731 git config aninvalid.unit "1auto" &&
732 test_cmp_config 1auto aninvalid.unit &&
733 test_must_fail git config --int --get aninvalid.unit 2>actual &&
734 test_grep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
737 test_expect_success
'invalid unit boolean' '
738 git config commit.gpgsign "1true" &&
739 test_cmp_config 1true commit.gpgsign &&
740 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
741 test_grep "bad boolean config value .1true. for .commit.gpgsign." actual
744 test_expect_success
'line number is reported correctly' '
745 printf "[bool]\n\tvar\n" >invalid &&
746 test_must_fail git config -f invalid --path bool.var 2>actual &&
747 test_grep "line 2" actual
750 test_expect_success
'invalid stdin config' '
751 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
752 test_grep "bad config line 1 in standard input" output
766 test_expect_success bool
'
768 git config bool.true1 01 &&
769 git config bool.true2 -1 &&
770 git config bool.true3 YeS &&
771 git config bool.true4 true &&
772 git config bool.false1 000 &&
773 git config bool.false2 "" &&
774 git config bool.false3 nO &&
775 git config bool.false4 FALSE &&
779 git config --bool --get bool.true$i >>result &&
780 git config --bool --get bool.false$i >>result || return 1
782 test_cmp expect result'
784 test_expect_success
'invalid bool (--get)' '
786 git config bool.nobool foobar &&
787 test_must_fail git config --bool --get bool.nobool'
789 test_expect_success
'invalid bool (set)' '
791 test_must_fail git config --bool bool.nobool foobar'
805 test_expect_success
'set --bool' '
808 git config --bool bool.true1 01 &&
809 git config --bool bool.true2 -1 &&
810 git config --bool bool.true3 YeS &&
811 git config --bool bool.true4 true &&
812 git config --bool bool.false1 000 &&
813 git config --bool bool.false2 "" &&
814 git config --bool bool.false3 nO &&
815 git config --bool bool.false4 FALSE &&
816 test_cmp expect .git/config'
825 test_expect_success
'set --int' '
828 git config --int int.val1 01 &&
829 git config --int int.val2 -1 &&
830 git config --int int.val3 5m &&
831 test_cmp expect .git/config
834 test_expect_success
'get --bool-or-int' '
835 cat >.git/config <<-\EOF &&
845 cat >expect <<-\EOF &&
854 git config --bool-or-int bool.true1 &&
855 git config --bool-or-int bool.true2 &&
856 git config --bool-or-int bool.false &&
857 git config --bool-or-int int.int1 &&
858 git config --bool-or-int int.int2 &&
859 git config --bool-or-int int.int3
861 test_cmp expect actual
876 test_expect_success
'set --bool-or-int' '
878 git config --bool-or-int bool.true1 true &&
879 git config --bool-or-int bool.false1 false &&
880 git config --bool-or-int bool.true2 yes &&
881 git config --bool-or-int bool.false2 no &&
882 git config --bool-or-int int.int1 0 &&
883 git config --bool-or-int int.int2 1 &&
884 git config --bool-or-int int.int3 -1 &&
885 test_cmp expect .git/config
895 test_expect_success
!MINGW
'set --path' '
897 git config --path path.home "~/" &&
898 git config --path path.normal "/dev/null" &&
899 git config --path path.trailingtilde "foo~" &&
900 test_cmp expect .git/config'
902 if test_have_prereq
!MINGW
&& test "${HOME+set}"
904 test_set_prereq HOMEVAR
913 test_expect_success HOMEVAR
'get --path' '
914 git config --get --path path.home > result &&
915 git config --get --path path.normal >> result &&
916 git config --get --path path.trailingtilde >> result &&
917 test_cmp expect result
925 test_expect_success
!MINGW
'get --path copes with unset $HOME' '
928 test_must_fail git config --get --path path.home \
930 git config --get --path path.normal >>result &&
931 git config --get --path path.trailingtilde >>result
933 test_grep "[Ff]ailed to expand.*~/" msg &&
934 test_cmp expect result
937 test_expect_success
'get --path barfs on boolean variable' '
938 echo "[path]bool" >.git/config &&
939 test_must_fail git config --get --path path.bool
942 test_expect_success
'get --expiry-date' '
943 rel="3.weeks.5.days.00:00" &&
945 cat >.git/config <<-\EOF &&
947 valid1 = "3.weeks.5.days 00:00"
948 valid2 = "Fri Jun 4 15:46:55 2010"
949 valid3 = "2017/11/11 11:11:11PM"
950 valid4 = "2017/11/10 09:08:07 PM"
954 cat >expect <<-EOF &&
955 $(test-tool date timestamp $rel)
961 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
963 echo "$rel_out $(git config --expiry-date date.valid1)" &&
964 git config --expiry-date date.valid2 &&
965 git config --expiry-date date.valid3 &&
966 git config --expiry-date date.valid4 &&
967 git config --expiry-date date.valid5
969 test_cmp expect actual &&
970 test_must_fail git config --expiry-date date.invalid1
973 test_expect_success
'get --type=color' '
975 git config foo.color "red" &&
976 git config --get --type=color foo.color >actual.raw &&
977 test_decode_color <actual.raw >actual &&
978 echo "<RED>" >expect &&
979 test_cmp expect actual
987 test_expect_success
'set --type=color' '
989 git config --type=color foo.color "red" &&
990 test_cmp expect .git/config
993 test_expect_success
'get --type=color barfs on non-color' '
994 echo "[foo]bar=not-a-color" >.git/config &&
995 test_must_fail git config --get --type=color foo.bar
998 test_expect_success
'set --type=color barfs on non-color' '
999 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
1000 test_grep "cannot parse color" error
1007 semicolon = "test;test"
1010 test_expect_success
'quoting' '
1011 rm -f .git/config &&
1012 git config quote.leading " test" &&
1013 git config quote.ending "test " &&
1014 git config quote.semicolon "test;test" &&
1015 git config quote.hash "test#test" &&
1016 test_cmp expect .git/config
1019 test_expect_success
'key with newline' '
1020 test_must_fail git config "key.with
1023 test_expect_success
'value with newline' 'git config key.sub value.with\\\
1026 cat > .git
/config
<<\EOF
1031 noncont
= not continued
; \
1037 section.continued
=continued
1038 section.noncont
=not continued
1039 section.quotecont
=cont
;inued
1042 test_expect_success
'value continued on next line' '
1043 git config --list > result &&
1044 test_cmp expect result
1047 cat > .git
/config
<<\EOF
1048 [section
"sub=section"]
1057 section.sub
=section.val1
1058 foo
=barQsection.sub
=section.val2
1060 barQsection.sub
=section.val3
1063 Qsection.sub
=section.val4
1064 Qsection.sub
=section.val5Q
1066 test_expect_success
'--null --list' '
1067 git config --null --list >result.raw &&
1068 nul_to_q <result.raw >result &&
1070 test_cmp expect result
1073 test_expect_success
'--null --get-regexp' '
1074 git config --null --get-regexp "val[0-9]" >result.raw &&
1075 nul_to_q <result.raw >result &&
1077 test_cmp expect result
1080 test_expect_success
'inner whitespace kept verbatim' '
1081 git config section.val "foo bar" &&
1082 test_cmp_config "foo bar" section.val
1085 test_expect_success SYMLINKS
'symlinked configuration' '
1086 ln -s notyet myconfig &&
1087 git config --file=myconfig test.frotz nitfol &&
1090 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1091 git config --file=myconfig test.xyzzy rezrov &&
1094 cat >expect <<-\EOF &&
1099 git config --file=notyet test.frotz &&
1100 git config --file=notyet test.xyzzy
1102 test_cmp expect actual
1105 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
1106 ln -s doesnotexist linktonada &&
1107 ln -s linktonada linktolinktonada &&
1108 test_must_fail git config --file=linktonada --list &&
1109 test_must_fail git config --file=linktolinktonada --list
1112 test_expect_success
'check split_cmdline return' '
1113 test_when_finished "rm -rf repo" &&
1117 git config alias.split-cmdline-fix "echo \"" &&
1118 test_must_fail git split-cmdline-fix &&
1121 git commit -m "initial commit" &&
1122 git config branch.main.mergeoptions "echo \"" &&
1123 test_must_fail git merge main
1127 test_expect_success
'git -c "key=value" support' '
1128 cat >expect <<-\EOF &&
1134 git -c section.name=value config section.name &&
1135 git -c foo.CamelCase=value config foo.camelcase &&
1136 git -c foo.flag config --bool foo.flag
1138 test_cmp expect actual &&
1139 test_must_fail git -c name=value config section.name
1142 # We just need a type-specifier here that cares about the
1143 # distinction internally between a NULL boolean and a real
1144 # string (because most of git's internal parsers do care).
1145 # Using "--path" works, but we do not otherwise care about
1147 test_expect_success
'git -c can represent empty string' '
1149 git -c foo.empty= config --path foo.empty >actual &&
1150 test_cmp expect actual
1153 test_expect_success
'key sanity-checking' '
1154 test_must_fail git config foo=bar &&
1155 test_must_fail git config foo=.bar &&
1156 test_must_fail git config foo.ba=r &&
1157 test_must_fail git config foo.1bar &&
1158 test_must_fail git config foo."ba
1160 test_must_fail git config . false &&
1161 test_must_fail git config .foo false &&
1162 test_must_fail git config foo. false &&
1163 test_must_fail git config .foo. false &&
1164 git config foo.bar true &&
1165 git config foo."ba =z".bar false
1168 test_expect_success
'git -c works with aliases of builtins' '
1169 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1171 git checkconfig >actual &&
1172 test_cmp expect actual
1175 test_expect_success
'aliases can be CamelCased' '
1176 test_when_finished "rm -rf repo" &&
1181 git config alias.CamelCased "rev-parse HEAD" &&
1182 git CamelCased >out &&
1183 git rev-parse HEAD >expect &&
1188 test_expect_success
'git -c does not split values on equals' '
1189 echo "value with = in it" >expect &&
1190 git -c section.foo="value with = in it" config section.foo >actual &&
1191 test_cmp expect actual
1194 test_expect_success
'git -c dies on bogus config' '
1195 test_must_fail git -c core.bare=foo rev-parse
1198 test_expect_success
'git -c complains about empty key' '
1199 test_must_fail git -c "=foo" rev-parse
1202 test_expect_success
'git -c complains about empty key and value' '
1203 test_must_fail git -c "" rev-parse
1206 test_expect_success
'multiple git -c appends config' '
1207 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1208 cat >expect <<-\EOF &&
1212 git -c x.one=1 x >actual &&
1213 test_cmp expect actual
1216 test_expect_success
'last one wins: two level vars' '
1218 # sec.var and sec.VAR are the same variable, as the first
1219 # and the last level of a configuration variable name is
1224 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1225 test_cmp expect actual &&
1226 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1227 test_cmp expect actual &&
1229 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1230 test_cmp expect actual &&
1231 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1232 test_cmp expect actual
1235 test_expect_success
'last one wins: three level vars' '
1237 # v.a.r and v.A.r are not the same variable, as the middle
1238 # level of a three-level configuration variable name is
1242 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1243 test_cmp expect actual &&
1244 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1245 test_cmp expect actual &&
1247 # v.a.r and V.a.R are the same variable, as the first
1248 # and the last level of a configuration variable name is
1252 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1253 test_cmp expect actual &&
1254 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1255 test_cmp expect actual &&
1256 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1257 test_cmp expect actual &&
1258 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1259 test_cmp expect actual
1262 test_expect_success
'old-fashioned settings are case insensitive' '
1263 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1265 cat >testConfig_actual <<-EOF &&
1269 q_to_tab >testConfig_expect <<-EOF &&
1273 git config -f testConfig_actual "v.a.r" value2 &&
1274 test_cmp testConfig_expect testConfig_actual &&
1276 cat >testConfig_actual <<-EOF &&
1280 q_to_tab >testConfig_expect <<-EOF &&
1284 git config -f testConfig_actual "V.a.R" value2 &&
1285 test_cmp testConfig_expect testConfig_actual &&
1287 cat >testConfig_actual <<-EOF &&
1291 q_to_tab >testConfig_expect <<-EOF &&
1296 git config -f testConfig_actual "V.A.r" value2 &&
1297 test_cmp testConfig_expect testConfig_actual &&
1299 cat >testConfig_actual <<-EOF &&
1303 q_to_tab >testConfig_expect <<-EOF &&
1308 git config -f testConfig_actual "v.A.r" value2 &&
1309 test_cmp testConfig_expect testConfig_actual
1312 test_expect_success
'setting different case sensitive subsections ' '
1313 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1315 cat >testConfig_actual <<-EOF &&
1325 q_to_tab >testConfig_expect <<-EOF &&
1338 git config -f testConfig_actual a.b.c v2 &&
1339 # match section and subsection, key is cased differently.
1340 git config -f testConfig_actual K.E.y v2 &&
1341 # section and key are matched case insensitive, but subsection needs
1342 # to match; When writing out new values only the key is adjusted
1343 git config -f testConfig_actual v.A.r v2 &&
1344 # subsection is not matched:
1345 git config -f testConfig_actual d.E.f v2 &&
1346 test_cmp testConfig_expect testConfig_actual
1349 for VAR
in a .a a. a
.0b a.
"b c". a.
"b c".0d
1351 test_expect_success
"git -c $VAR=VAL rejects invalid '$VAR'" '
1352 test_must_fail git -c "$VAR=VAL" config -l
1356 for VAR
in a.b a.
"b c".d
1358 test_expect_success
"git -c $VAR=VAL works with valid '$VAR'" '
1360 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1361 test_cmp expect actual
1365 test_expect_success
'git -c is not confused by empty environment' '
1366 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1369 test_expect_success
'GIT_CONFIG_PARAMETERS handles old-style entries' '
1370 v="${SQ}key.one=foo${SQ}" &&
1371 v="$v ${SQ}key.two=bar${SQ}" &&
1372 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1373 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1374 cat >expect <<-EOF &&
1377 key.ambiguous section.whatever=value
1379 test_cmp expect actual
1382 test_expect_success
'GIT_CONFIG_PARAMETERS handles new-style entries' '
1383 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1384 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1385 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1386 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1387 cat >expect <<-EOF &&
1390 key.ambiguous=section.whatever value
1392 test_cmp expect actual
1395 test_expect_success
'old and new-style entries can mix' '
1396 v="${SQ}key.oldone=oldfoo${SQ}" &&
1397 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1398 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1399 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1400 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1401 cat >expect <<-EOF &&
1407 test_cmp expect actual
1410 test_expect_success
'old and new bools with ambiguous subsection' '
1411 v="${SQ}key.with=equals.oldbool${SQ}" &&
1412 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1413 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1414 cat >expect <<-EOF &&
1415 key.with equals.oldbool
1416 key.with=equals.newbool
1418 test_cmp expect actual
1421 test_expect_success
'detect bogus GIT_CONFIG_PARAMETERS' '
1422 cat >expect <<-\EOF &&
1426 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1427 git config --get-regexp "env.*" >actual &&
1428 test_cmp expect actual &&
1430 cat >expect <<-EOF &&
1434 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1435 git config --get-regexp "env.*" >actual &&
1436 test_cmp expect actual &&
1438 test_must_fail env \
1439 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1440 git config --get-regexp "env.*"
1443 test_expect_success
'git --config-env=key=envvar support' '
1444 cat >expect <<-\EOF &&
1453 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1454 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1455 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1456 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1457 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1458 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1460 test_cmp expect actual
1463 test_expect_success
'git --config-env with missing value' '
1464 test_must_fail env ENVVAR=value git --config-env 2>error &&
1465 grep "no config key given for --config-env" error &&
1466 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1467 grep "invalid config format: config" error
1470 test_expect_success
'git --config-env fails with invalid parameters' '
1471 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1472 test_grep "invalid config format: foo.flag" error &&
1473 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1474 test_grep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1475 sane_unset NONEXISTENT &&
1476 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1477 test_grep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1480 test_expect_success
'git -c and --config-env work together' '
1481 cat >expect <<-\EOF &&
1485 ENVVAR=env-value git \
1486 -c bar.cmd=cmd-value \
1487 --config-env=bar.env=ENVVAR \
1488 config --get-regexp "^bar.*" >actual &&
1489 test_cmp expect actual
1492 test_expect_success
'git -c and --config-env override each other' '
1493 cat >expect <<-\EOF &&
1498 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1499 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1501 test_cmp expect actual
1504 test_expect_success
'--config-env handles keys with equals' '
1505 echo value=with=equals >expect &&
1506 ENVVAR=value=with=equals git \
1507 --config-env=section.subsection=with=equals.key=ENVVAR \
1508 config section.subsection=with=equals.key >actual &&
1509 test_cmp expect actual
1512 test_expect_success
'git config handles environment config pairs' '
1513 GIT_CONFIG_COUNT=2 \
1514 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1515 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1516 git config --get-regexp "pair.*" >actual &&
1517 cat >expect <<-EOF &&
1521 test_cmp expect actual
1524 test_expect_success
'git config ignores pairs without count' '
1525 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1526 git config pair.one 2>error &&
1527 test_must_be_empty error
1530 test_expect_success
'git config ignores pairs exceeding count' '
1531 GIT_CONFIG_COUNT=1 \
1532 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1533 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1534 git config --get-regexp "pair.*" >actual 2>error &&
1535 cat >expect <<-EOF &&
1538 test_cmp expect actual &&
1539 test_must_be_empty error
1542 test_expect_success
'git config ignores pairs with zero count' '
1543 test_must_fail env \
1544 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1545 git config pair.one 2>error &&
1546 test_must_be_empty error
1549 test_expect_success
'git config ignores pairs with empty count' '
1550 test_must_fail env \
1551 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1552 git config pair.one 2>error &&
1553 test_must_be_empty error
1556 test_expect_success
'git config fails with invalid count' '
1557 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1558 test_grep "bogus count" error &&
1559 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1560 test_grep "too many entries" error
1563 test_expect_success
'git config fails with missing config key' '
1564 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1565 git config --list 2>error &&
1566 test_grep "missing config key" error
1569 test_expect_success
'git config fails with missing config value' '
1570 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1571 git config --list 2>error &&
1572 test_grep "missing config value" error
1575 test_expect_success
'git config fails with invalid config pair key' '
1576 test_must_fail env GIT_CONFIG_COUNT=1 \
1577 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1578 git config --list &&
1579 test_must_fail env GIT_CONFIG_COUNT=1 \
1580 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1584 test_expect_success
'environment overrides config file' '
1585 test_when_finished "rm -f .git/config" &&
1586 cat >.git/config <<-EOF &&
1590 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1591 git config pair.one >actual &&
1592 cat >expect <<-EOF &&
1595 test_cmp expect actual
1598 test_expect_success
'GIT_CONFIG_PARAMETERS overrides environment config' '
1599 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1600 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1601 git config pair.one >actual &&
1602 cat >expect <<-EOF &&
1605 test_cmp expect actual
1608 test_expect_success
'command line overrides environment config' '
1609 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1610 git -c pair.one=override config pair.one >actual &&
1611 cat >expect <<-EOF &&
1614 test_cmp expect actual
1617 test_expect_success
'git config --edit works' '
1618 git config -f tmp test.value no &&
1619 echo test.value=yes >expect &&
1620 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1621 git config -f tmp --list >actual &&
1622 test_cmp expect actual
1625 test_expect_success
'git config --edit respects core.editor' '
1626 git config -f tmp test.value no &&
1627 echo test.value=yes >expect &&
1628 test_config core.editor "echo [test]value=yes >" &&
1629 git config -f tmp --edit &&
1630 git config -f tmp --list >actual &&
1631 test_cmp expect actual
1634 # malformed configuration files
1635 test_expect_success
'barf on syntax error' '
1636 cat >.git/config <<-\EOF &&
1641 test_must_fail git config --get section.key 2>error &&
1642 test_grep " line 3 " error
1645 test_expect_success
'barf on incomplete section header' '
1646 cat >.git/config <<-\EOF &&
1647 # broken section line
1651 test_must_fail git config --get section.key 2>error &&
1652 test_grep " line 2 " error
1655 test_expect_success
'barf on incomplete string' '
1656 cat >.git/config <<-\EOF &&
1657 # broken value string
1661 test_must_fail git config --get section.key 2>error &&
1662 test_grep " line 3 " error
1665 test_expect_success
'urlmatch' '
1666 cat >.git/config <<-\EOF &&
1669 [http "https://weak.example.com"]
1671 cookieFile = /tmp/cookie.txt
1674 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1675 test_must_be_empty actual &&
1677 echo true >expect &&
1678 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1679 test_cmp expect actual &&
1681 echo false >expect &&
1682 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1683 test_cmp expect actual &&
1686 echo http.cookiefile /tmp/cookie.txt &&
1687 echo http.sslverify false
1689 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1690 test_cmp expect actual
1693 test_expect_success
'urlmatch with --show-scope' '
1694 cat >.git/config <<-\EOF &&
1695 [http "https://weak.example.com"]
1697 cookieFile = /tmp/cookie.txt
1700 cat >expect <<-EOF &&
1701 local http.cookiefile /tmp/cookie.txt
1702 local http.sslverify false
1704 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1705 test_cmp expect actual
1708 test_expect_success
'urlmatch favors more specific URLs' '
1709 cat >.git/config <<-\EOF &&
1710 [http "https://example.com/"]
1711 cookieFile = /tmp/root.txt
1712 [http "https://example.com/subdirectory"]
1713 cookieFile = /tmp/subdirectory.txt
1714 [http "https://user@example.com/"]
1715 cookieFile = /tmp/user.txt
1716 [http "https://averylonguser@example.com/"]
1717 cookieFile = /tmp/averylonguser.txt
1718 [http "https://preceding.example.com"]
1719 cookieFile = /tmp/preceding.txt
1720 [http "https://*.example.com"]
1721 cookieFile = /tmp/wildcard.txt
1722 [http "https://*.example.com/wildcardwithsubdomain"]
1723 cookieFile = /tmp/wildcardwithsubdomain.txt
1724 [http "https://*.example.*"]
1725 cookieFile = /tmp/multiwildcard.txt
1726 [http "https://trailing.example.com"]
1727 cookieFile = /tmp/trailing.txt
1728 [http "https://user@*.example.com/"]
1729 cookieFile = /tmp/wildcardwithuser.txt
1730 [http "https://sub.example.com/"]
1731 cookieFile = /tmp/sub.txt
1734 echo http.cookiefile /tmp/root.txt >expect &&
1735 git config --get-urlmatch HTTP https://example.com >actual &&
1736 test_cmp expect actual &&
1738 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1739 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1740 test_cmp expect actual &&
1742 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1743 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1744 test_cmp expect actual &&
1746 echo http.cookiefile /tmp/user.txt >expect &&
1747 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1748 test_cmp expect actual &&
1750 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1751 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1752 test_cmp expect actual &&
1754 echo http.cookiefile /tmp/preceding.txt >expect &&
1755 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1756 test_cmp expect actual &&
1758 echo http.cookiefile /tmp/wildcard.txt >expect &&
1759 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1760 test_cmp expect actual &&
1762 echo http.cookiefile /tmp/sub.txt >expect &&
1763 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1764 test_cmp expect actual &&
1766 echo http.cookiefile /tmp/trailing.txt >expect &&
1767 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1768 test_cmp expect actual &&
1770 echo http.cookiefile /tmp/sub.txt >expect &&
1771 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1772 test_cmp expect actual &&
1774 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1775 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1776 test_cmp expect actual
1779 test_expect_success
'urlmatch with wildcard' '
1780 cat >.git/config <<-\EOF &&
1783 [http "https://*.example.com"]
1785 cookieFile = /tmp/cookie.txt
1788 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1789 test_must_be_empty actual &&
1791 echo true >expect &&
1792 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1793 test_cmp expect actual &&
1795 echo true >expect &&
1796 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1797 test_cmp expect actual &&
1799 echo true >expect &&
1800 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1801 test_cmp expect actual &&
1803 echo false >expect &&
1804 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1805 test_cmp expect actual &&
1808 echo http.cookiefile /tmp/cookie.txt &&
1809 echo http.sslverify false
1811 git config --get-urlmatch HTTP https://good.example.com >actual &&
1812 test_cmp expect actual &&
1814 echo http.sslverify >expect &&
1815 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1816 test_cmp expect actual
1819 # good section hygiene
1820 test_expect_success
'--unset last key removes section (except if commented)' '
1821 cat >.git/config <<-\EOF &&
1822 # some generic comment on the configuration file itself
1823 # a comment specific to this "section" section.
1825 # some intervening lines
1826 # that should also be dropped
1829 # please be careful when you update the above variable
1832 cat >expect <<-\EOF &&
1833 # some generic comment on the configuration file itself
1834 # a comment specific to this "section" section.
1836 # some intervening lines
1837 # that should also be dropped
1839 # please be careful when you update the above variable
1842 git config --unset section.key &&
1843 test_cmp expect .git/config &&
1845 cat >.git/config <<-\EOF &&
1851 cat >expect <<-\EOF &&
1855 git config --unset section.key &&
1856 test_cmp expect .git/config &&
1858 q_to_tab >.git/config <<-\EOF &&
1865 git config --unset two.key &&
1866 ! grep two .git/config &&
1868 q_to_tab >.git/config <<-\EOF &&
1875 git config --unset-all one.key &&
1876 test_line_count = 0 .git/config &&
1878 q_to_tab >.git/config <<-\EOF &&
1881 Q# a comment not at the start
1885 git config --unset two.key &&
1886 grep two .git/config &&
1888 q_to_tab >.git/config <<-\EOF &&
1890 Qkey = not [two "subsection"]
1897 git config --unset two.subsection.key &&
1898 test "not [two subsection]" = "$(git config one.key)" &&
1899 test_line_count = 3 .git/config
1902 test_expect_success
'--unset-all removes section if empty & uncommented' '
1903 cat >.git/config <<-\EOF &&
1909 git config --unset-all section.key &&
1910 test_line_count = 0 .git/config
1913 test_expect_success
'adding a key into an empty section reuses header' '
1914 cat >.git/config <<-\EOF &&
1918 q_to_tab >expect <<-\EOF &&
1923 git config section.key value &&
1924 test_cmp expect .git/config
1927 test_expect_success POSIXPERM
,PERL
'preserves existing permissions' '
1928 chmod 0600 .git/config &&
1929 git config imap.pass Hunter2 &&
1931 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1932 git config --rename-section imap pop &&
1934 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1937 ! test_have_prereq MINGW ||
1938 HOME
="$(pwd)" # convert to Windows path
1940 test_expect_success
'set up --show-origin tests' '
1941 INCLUDE_DIR="$HOME/include" &&
1942 mkdir -p "$INCLUDE_DIR" &&
1943 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1947 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1951 cat >"$HOME"/.gitconfig <<-EOF &&
1956 path = "$INCLUDE_DIR/absolute.include"
1958 cat >.git/config <<-\EOF
1963 path = ../include/relative.include
1967 test_expect_success
'--show-origin with --list' '
1968 cat >expect <<-EOF &&
1969 file:$HOME/.gitconfig user.global=true
1970 file:$HOME/.gitconfig user.override=global
1971 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1972 file:$INCLUDE_DIR/absolute.include user.absolute=include
1973 file:.git/config user.local=true
1974 file:.git/config user.override=local
1975 file:.git/config include.path=../include/relative.include
1976 file:.git/../include/relative.include user.relative=include
1977 command line: user.environ=true
1978 command line: user.cmdline=true
1980 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1981 git -c user.cmdline=true config --list --show-origin >output &&
1982 test_cmp expect output
1985 test_expect_success
'--show-origin with --list --null' '
1986 cat >expect <<-EOF &&
1987 file:$HOME/.gitconfigQuser.global
1988 trueQfile:$HOME/.gitconfigQuser.override
1989 globalQfile:$HOME/.gitconfigQinclude.path
1990 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1991 includeQfile:.git/configQuser.local
1992 trueQfile:.git/configQuser.override
1993 localQfile:.git/configQinclude.path
1994 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1995 includeQcommand line:Quser.cmdline
1998 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1999 nul_to_q <output.raw >output &&
2000 # The here-doc above adds a newline that the --null output would not
2001 # include. Add it here to make the two comparable.
2003 test_cmp expect output
2006 test_expect_success
'--show-origin with single file' '
2007 cat >expect <<-\EOF &&
2008 file:.git/config user.local=true
2009 file:.git/config user.override=local
2010 file:.git/config include.path=../include/relative.include
2012 git config --local --list --show-origin >output &&
2013 test_cmp expect output
2016 test_expect_success
'--show-origin with --get-regexp' '
2017 cat >expect <<-EOF &&
2018 file:$HOME/.gitconfig user.global true
2019 file:.git/config user.local true
2021 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
2022 test_cmp expect output
2025 test_expect_success
'--show-origin getting a single key' '
2026 cat >expect <<-\EOF &&
2027 file:.git/config local
2029 git config --show-origin user.override >output &&
2030 test_cmp expect output
2033 test_expect_success
'set up custom config file' '
2034 cat >"custom.conf" <<-\EOF &&
2038 CUSTOM_CONFIG_FILE="$(test-tool path-utils real_path custom.conf)"
2041 test_expect_success
!MINGW
'set up custom config file with special name characters' '
2042 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2043 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2046 test_expect_success
!MINGW
'--show-origin escape special file name characters' '
2047 cat >expect <<-\EOF &&
2048 file:"file\" (dq) and spaces.conf" user.custom=true
2050 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2051 test_cmp expect output
2054 test_expect_success
'--show-origin stdin' '
2055 cat >expect <<-\EOF &&
2056 standard input: user.custom=true
2058 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2059 test_cmp expect output
2062 test_expect_success
'--show-origin stdin with file include' '
2063 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2067 cat >expect <<-EOF &&
2068 file:$INCLUDE_DIR/stdin.include include
2070 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2071 git config --show-origin --includes --file - user.stdin >output &&
2073 test_cmp expect output
2076 test_expect_success
'--show-origin blob' '
2077 test_when_finished "rm -rf repo" &&
2081 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2082 cat >expect <<-EOF &&
2083 blob:$blob user.custom=true
2085 git config --blob=$blob --show-origin --list >output &&
2086 test_cmp expect output
2090 test_expect_success
'--show-origin blob ref' '
2091 test_when_finished "rm -rf repo" &&
2095 cat >expect <<-\EOF &&
2096 blob:main:custom.conf user.custom=true
2098 cp "$CUSTOM_CONFIG_FILE" custom.conf &&
2099 git add custom.conf &&
2100 git commit -m "new config file" &&
2101 git config --blob=main:custom.conf --show-origin --list >output &&
2102 test_cmp expect output
2106 test_expect_success
'--show-origin with --default' '
2107 git config --show-origin --default foo some.key >actual &&
2108 echo "command line: foo" >expect &&
2109 test_cmp expect actual
2112 test_expect_success
'--show-scope with --list' '
2113 cat >expect <<-EOF &&
2114 global user.global=true
2115 global user.override=global
2116 global include.path=$INCLUDE_DIR/absolute.include
2117 global user.absolute=include
2118 local user.local=true
2119 local user.override=local
2120 local include.path=../include/relative.include
2121 local user.relative=include
2122 local core.repositoryformatversion=1
2123 local extensions.worktreeconfig=true
2124 worktree user.worktree=true
2125 command user.cmdline=true
2127 git worktree add wt1 &&
2128 # We need these to test for worktree scope, but outside of this
2129 # test, this is just noise
2130 test_config core.repositoryformatversion 1 &&
2131 test_config extensions.worktreeConfig true &&
2132 git config --worktree user.worktree true &&
2133 git -c user.cmdline=true config --list --show-scope >output &&
2134 test_cmp expect output
2137 test_expect_success
!MINGW
'--show-scope with --blob' '
2138 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2139 cat >expect <<-EOF &&
2140 command user.custom=true
2142 git config --blob=$blob --show-scope --list >output &&
2143 test_cmp expect output
2146 test_expect_success
'--show-scope with --local' '
2147 cat >expect <<-\EOF &&
2148 local user.local=true
2149 local user.override=local
2150 local include.path=../include/relative.include
2152 git config --local --list --show-scope >output &&
2153 test_cmp expect output
2156 test_expect_success
'--show-scope getting a single value' '
2157 cat >expect <<-\EOF &&
2160 git config --show-scope --get user.local >output &&
2161 test_cmp expect output
2164 test_expect_success
'--show-scope with --show-origin' '
2165 cat >expect <<-EOF &&
2166 global file:$HOME/.gitconfig user.global=true
2167 global file:$HOME/.gitconfig user.override=global
2168 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2169 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2170 local file:.git/config user.local=true
2171 local file:.git/config user.override=local
2172 local file:.git/config include.path=../include/relative.include
2173 local file:.git/../include/relative.include user.relative=include
2174 command command line: user.cmdline=true
2176 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2177 test_cmp expect output
2180 test_expect_success
'--show-scope with --default' '
2181 git config --show-scope --default foo some.key >actual &&
2182 echo "command foo" >expect &&
2183 test_cmp expect actual
2186 test_expect_success
'override global and system config' '
2187 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2188 cat >"$HOME"/.gitconfig <<-EOF &&
2193 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2194 mkdir -p "$HOME"/.config/git &&
2195 cat >"$HOME"/.config/git/config <<-EOF &&
2199 cat >.git/config <<-EOF &&
2203 cat >custom-global-config <<-EOF &&
2207 cat >custom-system-config <<-EOF &&
2212 cat >expect <<-EOF &&
2213 global xdg.config=true
2214 global home.config=true
2215 local local.config=true
2217 git config --show-scope --list >output &&
2218 test_cmp expect output &&
2220 cat >expect <<-EOF &&
2221 system system.config=true
2222 global global.config=true
2223 local local.config=true
2225 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2226 git config --show-scope --list >output &&
2227 test_cmp expect output &&
2229 cat >expect <<-EOF &&
2230 local local.config=true
2232 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2233 git config --show-scope --list >output &&
2234 test_cmp expect output
2237 test_expect_success
'override global and system config with missing file' '
2238 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2239 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2240 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2243 test_expect_success
'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2244 # `git config --system` has different semantics compared to other
2245 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2246 # variable has an effect via a different proxy.
2247 cat >alias-config <<-EOF &&
2249 hello-world = !echo "hello world"
2251 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2253 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2254 git hello-world >actual &&
2255 echo "hello world" >expect &&
2256 test_cmp expect actual
2259 test_expect_success
'write to overridden global and system config' '
2260 cat >expect <<EOF &&
2265 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2266 test_cmp expect write-to-global &&
2268 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2269 test_cmp expect write-to-system
2272 for opt
in --local --worktree
2274 test_expect_success
"$opt requires a repo" '
2275 # we expect 128 to ensure that we do not simply
2276 # fail to find anything and return code "1"
2277 test_expect_code 128 nongit git config $opt foo.bar
2281 cat >.git
/config
<<-\EOF &&
2288 test_expect_success 'identical modern --type specifiers are allowed' '
2289 test_cmp_config 1048576 --type=int --type=int section.big
2292 test_expect_success 'identical legacy --type specifiers are allowed' '
2293 test_cmp_config 1048576 --int --int section.big
2296 test_expect_success 'identical mixed --type specifiers are allowed' '
2297 test_cmp_config 1048576 --int --type=int section.big
2300 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2301 test_must_fail git config --type=int --type=bool section.big 2>error &&
2302 test_grep "only one type at a time" error
2305 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2306 test_must_fail git config --int --bool section.big 2>error &&
2307 test_grep "only one type at a time" error
2310 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2311 test_must_fail git config --type=int --bool section.big 2>error &&
2312 test_grep "only one type at a time" error
2315 test_expect_success '--type allows valid type specifiers' '
2316 test_cmp_config true --type=bool section.foo
2319 test_expect_success '--no-type unsets type specifiers' '
2320 test_cmp_config 10 --type=bool --no-type section.number
2323 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2324 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2327 test_expect_success '--type rejects unknown specifiers' '
2328 test_must_fail git config --type=nonsense section.foo 2>error &&
2329 test_grep "unrecognized --type argument" error
2332 test_expect_success '--type=int requires at least one digit' '
2333 test_must_fail git config --type int --default m some.key >out 2>error &&
2334 grep "bad numeric config value" error &&
2335 test_must_be_empty out
2338 test_expect_success '--replace-all does not invent newlines' '
2339 q_to_tab >.git/config <<-\
EOF &&
2347 q_to_tab >expect <<-\EOF &&
2355 git config --replace-all abc.key b &&
2356 test_cmp expect .git/config
2359 test_expect_success 'set all config with value-pattern' '
2360 test_when_finished rm -f config initial &&
2361 git config --file=initial abc.key one &&
2363 # no match => add new entry
2364 cp initial config &&
2365 git config --file=config abc.key two a+ &&
2366 git config --file=config --list >actual &&
2367 cat >expect <<-\EOF &&
2371 test_cmp expect actual &&
2373 # multiple matches => failure
2374 test_must_fail git config --file=config abc.key three o+ 2>err &&
2375 test_grep "has multiple values" err &&
2377 # multiple values, no match => add
2378 git config --file=config abc.key three a+ &&
2379 git config --file=config --list >actual &&
2380 cat >expect <<-\EOF &&
2385 test_cmp expect actual &&
2387 # single match => replace
2388 git config --file=config abc.key four h+ &&
2389 git config --file=config --list >actual &&
2390 cat >expect <<-\EOF &&
2395 test_cmp expect actual
2398 test_expect_success '--replace-all and value-pattern' '
2399 test_when_finished rm -f config &&
2400 git config --file=config --add abc.key one &&
2401 git config --file=config --add abc.key two &&
2402 git config --file=config --add abc.key three &&
2403 git config --file=config --replace-all abc.key four "o+" &&
2404 git config --file=config --list >actual &&
2405 cat >expect <<-\EOF &&
2409 test_cmp expect actual
2412 test_expect_success 'refuse --fixed-value for incompatible actions' '
2413 test_when_finished rm -f config &&
2414 git config --file=config dev.null bogus &&
2416 # These modes do not allow --fixed-value at all
2417 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2418 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2419 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2420 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2421 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2422 test_must_fail git config --file=config --fixed-value --list &&
2423 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2424 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2426 # These modes complain when --fixed-value has no value-pattern
2427 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2428 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2429 test_must_fail git config --file=config --fixed-value --get dev.null &&
2430 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2431 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2432 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2433 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2436 test_expect_success '--fixed-value uses exact string matching' '
2437 test_when_finished rm -f config initial &&
2438 META="a+b*c?d[e]f.g" &&
2439 git config --file=initial fixed.test "$META" &&
2441 cp initial config &&
2442 git config --file=config fixed.test bogus "$META" &&
2443 git config --file=config --list >actual &&
2444 cat >expect <<-EOF &&
2448 test_cmp expect actual &&
2450 cp initial config &&
2451 git config --file=config --fixed-value fixed.test bogus "$META" &&
2452 git config --file=config --list >actual &&
2453 cat >expect <<-\EOF &&
2456 test_cmp expect actual &&
2458 cp initial config &&
2459 test_must_fail git config --file=config --unset fixed.test "$META" &&
2460 git config --file=config --fixed-value --unset fixed.test "$META" &&
2461 test_must_fail git config --file=config fixed.test &&
2463 cp initial config &&
2464 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2465 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2466 test_must_fail git config --file=config fixed.test &&
2468 cp initial config &&
2469 git config --file=config --replace-all fixed.test bogus "$META" &&
2470 git config --file=config --list >actual &&
2471 cat >expect <<-EOF &&
2475 test_cmp expect actual &&
2477 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2478 git config --file=config --list >actual &&
2479 cat >expect <<-EOF &&
2483 test_cmp expect actual
2486 test_expect_success '--get and --get-all with --fixed-value' '
2487 test_when_finished rm -f config &&
2488 META="a+b*c?d[e]f.g" &&
2489 git config --file=config fixed.test bogus &&
2490 git config --file=config --add fixed.test "$META" &&
2492 git config --file=config --get fixed.test bogus &&
2493 test_must_fail git config --file=config --get fixed.test "$META" &&
2494 git config --file=config --get --fixed-value fixed.test "$META" &&
2495 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2497 git config --file=config --get-all fixed.test bogus &&
2498 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2499 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2500 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2502 git config --file=config --get-regexp fixed+ bogus &&
2503 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2504 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2505 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2508 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2509 git init hasremoteurlTest &&
2510 test_when_finished "rm -rf hasremoteurlTest" &&
2512 cat >include-this <<-\EOF &&
2514 this = this-is-included
2516 cat >dont-include-that <<-\EOF &&
2518 that = that-is-not-included
2520 cat >>hasremoteurlTest/.git/config <<-EOF &&
2521 [includeIf "hasconfig:remote.*.url:foourl"]
2522 path = "$(pwd)/include-this"
2523 [includeIf "hasconfig:remote.*.url:barurl"]
2524 path = "$(pwd)/dont-include-that"
2529 echo this-is-included >expect-this &&
2530 git -C hasremoteurlTest config --get user.this >actual-this &&
2531 test_cmp expect-this actual-this &&
2533 test_must_fail git -C hasremoteurlTest config --get user.that
2536 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2537 git init hasremoteurlTest &&
2538 test_when_finished "rm -rf hasremoteurlTest" &&
2540 cat >include-two-three <<-\EOF &&
2542 two = included-config
2543 three = included-config
2545 cat >>hasremoteurlTest/.git/config <<-EOF &&
2551 [includeIf "hasconfig:remote.*.url:foourl"]
2552 path = "$(pwd)/include-two-three"
2557 echo main-config >expect-main-config &&
2558 echo included-config >expect-included-config &&
2560 git -C hasremoteurlTest config --get user.one >actual &&
2561 test_cmp expect-main-config actual &&
2563 git -C hasremoteurlTest config --get user.two >actual &&
2564 test_cmp expect-included-config actual &&
2566 git -C hasremoteurlTest config --get user.three >actual &&
2567 test_cmp expect-main-config actual
2570 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2571 git init hasremoteurlTest &&
2572 test_when_finished "rm -rf hasremoteurlTest" &&
2574 printf "[user]\ndss = yes\n" >double-star-start &&
2575 printf "[user]\ndse = yes\n" >double-star-end &&
2576 printf "[user]\ndsm = yes\n" >double-star-middle &&
2577 printf "[user]\nssm = yes\n" >single-star-middle &&
2578 printf "[user]\nno = no\n" >no &&
2580 cat >>hasremoteurlTest/.git/config <<-EOF &&
2582 url = https://foo/bar/baz
2583 [includeIf "hasconfig:remote.*.url:**/baz"]
2584 path = "$(pwd)/double-star-start"
2585 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2587 [includeIf "hasconfig:remote.*.url:https:/**"]
2588 path = "$(pwd)/double-star-end"
2589 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2591 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2592 path = "$(pwd)/double-star-middle"
2593 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2595 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2596 path = "$(pwd)/single-star-middle"
2597 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2601 git -C hasremoteurlTest config --get user.dss &&
2602 git -C hasremoteurlTest config --get user.dse &&
2603 git -C hasremoteurlTest config --get user.dsm &&
2604 git -C hasremoteurlTest config --get user.ssm &&
2605 test_must_fail git -C hasremoteurlTest config --get user.no
2608 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2609 git init hasremoteurlTest &&
2610 test_when_finished "rm -rf hasremoteurlTest" &&
2612 cat >include-with-url <<-\EOF &&
2616 cat >>hasremoteurlTest/.git/config <<-EOF &&
2617 [includeIf "hasconfig:remote.*.url:foourl"]
2618 path = "$(pwd)/include-with-url"
2621 # test with any Git command
2622 test_must_fail git -C hasremoteurlTest status 2>err &&
2623 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err