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
80 test_expect_success
'non-match result' 'test_cmp expect .git/config'
82 test_expect_success
'find mixed-case key by canonical name' '
83 test_cmp_config Second sections.whatever
86 test_expect_success
'find mixed-case key by non-canonical name' '
87 test_cmp_config Second SeCtIoNs.WhAtEvEr
90 test_expect_success
'subsections are not canonicalized by git-config' '
91 cat >>.git/config <<-\EOF &&
94 [section "SubSection"]
97 test_cmp_config one section.subsection.key &&
98 test_cmp_config two section.SubSection.key
101 test_missing_key
() {
104 test_expect_success
"value for $title is not printed" '
105 test_must_fail git config "$key" >out 2>err &&
106 test_must_be_empty out &&
107 test_must_be_empty err
111 test_missing_key
'missingsection.missingkey' 'missing section and missing key'
112 test_missing_key
'missingsection.penguin' 'missing section and existing key'
113 test_missing_key
'section.missingkey' 'existing section and missing key'
114 test_missing_key
'section.MissingSubSection.missingkey' 'missing subsection and missing key'
115 test_missing_key
'section.SubSection.missingkey' 'existing subsection and missing key'
116 test_missing_key
'section.MissingSubSection.key' 'missing subsection and existing key'
118 cat > .git
/config
<<\EOF
127 test_expect_success
'unset with cont. lines' '
128 git config --unset beta.baz
138 test_expect_success
'unset with cont. lines is correct' 'test_cmp expect .git/config'
140 cat > .git
/config
<< EOF
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
146 haha ="beta" # last silly comment
149 [nextSection] noNewline = ouch
152 cp .git
/config .git
/config2
154 test_expect_success
'multiple unset' '
155 git config --unset-all beta.haha
159 [beta] ; silly comment # another comment
160 noIndent= sillyValue ; 'nother silly comment
164 [nextSection] noNewline = ouch
167 test_expect_success
'multiple unset is correct' '
168 test_cmp expect .git/config
171 cp .git
/config2 .git
/config
173 test_expect_success
'--replace-all missing value' '
174 test_must_fail git config --replace-all beta.haha &&
175 test_cmp .git/config2 .git/config
180 test_expect_success
'--replace-all' '
181 git config --replace-all beta.haha gamma
185 [beta] ; silly comment # another comment
186 noIndent= sillyValue ; 'nother silly comment
191 [nextSection] noNewline = ouch
194 test_expect_success
'all replaced' '
195 test_cmp expect .git/config
199 [beta] ; silly comment # another comment
200 noIndent= sillyValue ; 'nother silly comment
205 [nextSection] noNewline = ouch
207 test_expect_success
'really mean test' '
208 git config beta.haha alpha &&
209 test_cmp expect .git/config
213 [beta] ; silly comment # another comment
214 noIndent= sillyValue ; 'nother silly comment
222 test_expect_success
'really really mean test' '
223 git config nextsection.nonewline wow &&
224 test_cmp expect .git/config
227 test_expect_success
'get value' '
228 test_cmp_config alpha beta.haha
232 [beta] ; silly comment # another comment
233 noIndent= sillyValue ; 'nother silly comment
240 test_expect_success
'unset' '
241 git config --unset beta.haha &&
242 test_cmp expect .git/config
246 [beta] ; silly comment # another comment
247 noIndent= sillyValue ; 'nother silly comment
253 NoNewLine = wow2 for me
255 test_expect_success
'multivar' '
256 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
257 test_cmp expect .git/config
260 test_expect_success
'non-match' '
261 git config --get nextsection.nonewline !for
264 test_expect_success
'non-match value' '
265 test_cmp_config wow --get nextsection.nonewline !for
268 test_expect_success
'multi-valued get returns final one' '
269 test_cmp_config "wow2 for me" --get nextsection.nonewline
272 test_expect_success
'multi-valued get-all returns all' '
273 cat >expect <<-\EOF &&
277 git config --get-all nextsection.nonewline >actual &&
278 test_cmp expect actual
282 [beta] ; silly comment # another comment
283 noIndent= sillyValue ; 'nother silly comment
289 NoNewLine = wow2 for me
291 test_expect_success
'multivar replace' '
292 git config nextsection.nonewline "wow3" "wow$" &&
293 test_cmp expect .git/config
296 test_expect_success
'ambiguous unset' '
297 test_must_fail git config --unset nextsection.nonewline
300 test_expect_success
'invalid unset' '
301 test_must_fail git config --unset somesection.nonewline
305 [beta] ; silly comment # another comment
306 noIndent= sillyValue ; 'nother silly comment
311 NoNewLine = wow2 for me
314 test_expect_success
'multivar unset' '
315 git config --unset nextsection.nonewline "wow3$" &&
316 test_cmp expect .git/config
319 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
321 test_expect_success
'correct key' 'git config 123456.a123 987'
323 test_expect_success
'hierarchical section' '
324 git config Version.1.2.3eX.Alpha beta
328 [beta] ; silly comment # another comment
329 noIndent= sillyValue ; 'nother silly comment
334 NoNewLine = wow2 for me
341 test_expect_success
'hierarchical section value' '
342 test_cmp expect .git/config
346 beta.noindent=sillyValue
347 nextsection.nonewline=wow2 for me
349 version.1.2.3eX.alpha=beta
352 test_expect_success
'working --list' '
353 git config --list > output &&
354 test_cmp expect output
356 test_expect_success
'--list without repo produces empty output' '
357 git --git-dir=nonexistent config --list >output &&
358 test_must_be_empty output
363 nextsection.nonewline
365 version.1.2.3eX.alpha
368 test_expect_success
'--name-only --list' '
369 git config --name-only --list >output &&
370 test_cmp expect output
374 beta.noindent sillyValue
375 nextsection.nonewline wow2 for me
378 test_expect_success
'--get-regexp' '
379 git config --get-regexp in >output &&
380 test_cmp expect output
385 nextsection.nonewline
388 test_expect_success
'--name-only --get-regexp' '
389 git config --name-only --get-regexp in >output &&
390 test_cmp expect output
398 test_expect_success
'--add' '
399 git config --add nextsection.nonewline "wow4 for you" &&
400 git config --get-all nextsection.nonewline > output &&
401 test_cmp expect output
404 cat > .git
/config
<< EOF
411 test_expect_success
'get variable with no value' '
412 git config --get novalue.variable ^$
415 test_expect_success
'get variable with empty value' '
416 git config --get emptyvalue.variable ^$
419 echo novalue.variable
> expect
421 test_expect_success
'get-regexp variable with no value' '
422 git config --get-regexp novalue > output &&
423 test_cmp expect output
426 echo 'novalue.variable true' > expect
428 test_expect_success
'get-regexp --bool variable with no value' '
429 git config --bool --get-regexp novalue > output &&
430 test_cmp expect output
433 echo 'emptyvalue.variable ' > expect
435 test_expect_success
'get-regexp variable with empty value' '
436 git config --get-regexp emptyvalue > output &&
437 test_cmp expect output
442 test_expect_success
'get bool variable with no value' '
443 git config --bool novalue.variable > output &&
444 test_cmp expect output
449 test_expect_success
'get bool variable with empty value' '
450 git config --bool emptyvalue.variable > output &&
451 test_cmp expect output
454 test_expect_success
'no arguments, but no crash' '
455 test_must_fail git config >output 2>&1 &&
456 test_i18ngrep usage output
459 cat > .git
/config
<< EOF
471 test_expect_success
'new section is partial match of another' '
473 test_cmp expect .git/config
486 test_expect_success
'new variable inserts into proper section' '
489 test_cmp expect .git/config
492 test_expect_success
'alternative --file (non-existing file should fail)' '
493 test_must_fail git config --file non-existing-config -l &&
494 test_must_fail git config --file non-existing-config test.xyzzy
497 cat > other-config
<< EOF
506 test_expect_success
'alternative GIT_CONFIG' '
507 GIT_CONFIG=other-config git config --list >output &&
508 test_cmp expect output
511 test_expect_success
'alternative GIT_CONFIG (--file)' '
512 git config --file other-config --list >output &&
513 test_cmp expect output
516 test_expect_success
'alternative GIT_CONFIG (--file=-)' '
517 git config --file - --list <other-config >output &&
518 test_cmp expect output
521 test_expect_success
'setting a value in stdin is an error' '
522 test_must_fail git config --file - some.value foo
525 test_expect_success
'editing stdin is an error' '
526 test_must_fail git config --file - --edit
529 test_expect_success
'refer config from subdirectory' '
531 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
541 test_expect_success
'--set in alternative file' '
542 git config --file=other-config anwohner.park ausweis &&
543 test_cmp expect other-config
546 cat > .git
/config
<< EOF
553 [branch "1 234 blabl/a"]
557 test_expect_success
'rename section' '
558 git config --rename-section branch.eins branch.zwei
568 [branch "1 234 blabl/a"]
572 test_expect_success
'rename succeeded' '
573 test_cmp expect .git/config
576 test_expect_success
'rename non-existing section' '
577 test_must_fail git config --rename-section \
578 branch."world domination" branch.drei
581 test_expect_success
'rename succeeded' '
582 test_cmp expect .git/config
585 test_expect_success
'rename another section' '
586 git config --rename-section branch."1 234 blabl/a" branch.drei
600 test_expect_success
'rename succeeded' '
601 test_cmp expect .git/config
604 cat >> .git
/config
<< EOF
605 [branch "vier"] z = 1
608 test_expect_success
'rename a section with a var on the same line' '
609 git config --rename-section branch.vier branch.zwei
625 test_expect_success
'rename succeeded' '
626 test_cmp expect .git/config
629 test_expect_success
'renaming empty section name is rejected' '
630 test_must_fail git config --rename-section branch.zwei ""
633 test_expect_success
'renaming to bogus section is rejected' '
634 test_must_fail git config --rename-section branch.zwei "bogus name"
637 test_expect_success
'renaming a section with a long line' '
640 printf " c = d %1024s [a] e = f\\n" " " &&
641 printf "[a] g = h\\n"
643 git config -f y --rename-section a xyz &&
644 test_must_fail git config -f y b.e
647 test_expect_success
'renaming an embedded section with a long line' '
650 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
651 printf "[a] g = h\\n"
653 git config -f y --rename-section a xyz &&
654 test_must_fail git config -f y foo.e
657 test_expect_success
'renaming a section with an overly-long line' '
660 printf " c = d %525000s e" " " &&
661 printf "[a] g = h\\n"
663 test_must_fail git config -f y --rename-section a xyz 2>err &&
664 grep "refusing to work with overly long line in .y. on line 2" err
667 cat >> .git
/config
<< EOF
668 [branch "zwei"] a = 1 [branch "vier"]
671 test_expect_success
'remove section' '
672 git config --remove-section branch.zwei
682 test_expect_success
'section was removed properly' '
683 test_cmp expect .git/config
689 dbname = %Ggitcvs2.%a.%m.sqlite
691 dbname = %Ggitcvs1.%a.%m.sqlite
694 test_expect_success
'section ending' '
696 git config gitcvs.enabled true &&
697 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
698 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
699 test_cmp expect .git/config
703 test_expect_success numbers
'
704 git config kilo.gram 1k &&
705 git config mega.ton 1m &&
707 echo 1048576 >>expect &&
708 git config --int --get kilo.gram >actual &&
709 git config --int --get mega.ton >>actual &&
710 test_cmp expect actual
713 test_expect_success
'--int is at least 64 bits' '
714 git config giga.watts 121g &&
716 test_cmp_config 129922760704 --int --get giga.watts
719 test_expect_success
'invalid unit' '
720 git config aninvalid.unit "1auto" &&
721 test_cmp_config 1auto aninvalid.unit &&
722 test_must_fail git config --int --get aninvalid.unit 2>actual &&
723 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
726 test_expect_success
'invalid unit boolean' '
727 git config commit.gpgsign "1true" &&
728 test_cmp_config 1true commit.gpgsign &&
729 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
730 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
733 test_expect_success
'line number is reported correctly' '
734 printf "[bool]\n\tvar\n" >invalid &&
735 test_must_fail git config -f invalid --path bool.var 2>actual &&
736 test_i18ngrep "line 2" actual
739 test_expect_success
'invalid stdin config' '
740 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
741 test_i18ngrep "bad config line 1 in standard input" output
755 test_expect_success bool
'
757 git config bool.true1 01 &&
758 git config bool.true2 -1 &&
759 git config bool.true3 YeS &&
760 git config bool.true4 true &&
761 git config bool.false1 000 &&
762 git config bool.false2 "" &&
763 git config bool.false3 nO &&
764 git config bool.false4 FALSE &&
768 git config --bool --get bool.true$i >>result &&
769 git config --bool --get bool.false$i >>result || return 1
771 test_cmp expect result'
773 test_expect_success
'invalid bool (--get)' '
775 git config bool.nobool foobar &&
776 test_must_fail git config --bool --get bool.nobool'
778 test_expect_success
'invalid bool (set)' '
780 test_must_fail git config --bool bool.nobool foobar'
794 test_expect_success
'set --bool' '
797 git config --bool bool.true1 01 &&
798 git config --bool bool.true2 -1 &&
799 git config --bool bool.true3 YeS &&
800 git config --bool bool.true4 true &&
801 git config --bool bool.false1 000 &&
802 git config --bool bool.false2 "" &&
803 git config --bool bool.false3 nO &&
804 git config --bool bool.false4 FALSE &&
805 test_cmp expect .git/config'
814 test_expect_success
'set --int' '
817 git config --int int.val1 01 &&
818 git config --int int.val2 -1 &&
819 git config --int int.val3 5m &&
820 test_cmp expect .git/config
823 test_expect_success
'get --bool-or-int' '
824 cat >.git/config <<-\EOF &&
834 cat >expect <<-\EOF &&
843 git config --bool-or-int bool.true1 &&
844 git config --bool-or-int bool.true2 &&
845 git config --bool-or-int bool.false &&
846 git config --bool-or-int int.int1 &&
847 git config --bool-or-int int.int2 &&
848 git config --bool-or-int int.int3
850 test_cmp expect actual
865 test_expect_success
'set --bool-or-int' '
867 git config --bool-or-int bool.true1 true &&
868 git config --bool-or-int bool.false1 false &&
869 git config --bool-or-int bool.true2 yes &&
870 git config --bool-or-int bool.false2 no &&
871 git config --bool-or-int int.int1 0 &&
872 git config --bool-or-int int.int2 1 &&
873 git config --bool-or-int int.int3 -1 &&
874 test_cmp expect .git/config
884 test_expect_success
!MINGW
'set --path' '
886 git config --path path.home "~/" &&
887 git config --path path.normal "/dev/null" &&
888 git config --path path.trailingtilde "foo~" &&
889 test_cmp expect .git/config'
891 if test_have_prereq
!MINGW
&& test "${HOME+set}"
893 test_set_prereq HOMEVAR
902 test_expect_success HOMEVAR
'get --path' '
903 git config --get --path path.home > result &&
904 git config --get --path path.normal >> result &&
905 git config --get --path path.trailingtilde >> result &&
906 test_cmp expect result
914 test_expect_success
!MINGW
'get --path copes with unset $HOME' '
917 test_must_fail git config --get --path path.home \
919 git config --get --path path.normal >>result &&
920 git config --get --path path.trailingtilde >>result
922 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
923 test_cmp expect result
926 test_expect_success
'get --path barfs on boolean variable' '
927 echo "[path]bool" >.git/config &&
928 test_must_fail git config --get --path path.bool
931 test_expect_success
'get --expiry-date' '
932 rel="3.weeks.5.days.00:00" &&
934 cat >.git/config <<-\EOF &&
936 valid1 = "3.weeks.5.days 00:00"
937 valid2 = "Fri Jun 4 15:46:55 2010"
938 valid3 = "2017/11/11 11:11:11PM"
939 valid4 = "2017/11/10 09:08:07 PM"
943 cat >expect <<-EOF &&
944 $(test-tool date timestamp $rel)
950 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
952 echo "$rel_out $(git config --expiry-date date.valid1)" &&
953 git config --expiry-date date.valid2 &&
954 git config --expiry-date date.valid3 &&
955 git config --expiry-date date.valid4 &&
956 git config --expiry-date date.valid5
958 test_cmp expect actual &&
959 test_must_fail git config --expiry-date date.invalid1
962 test_expect_success
'get --type=color' '
964 git config foo.color "red" &&
965 git config --get --type=color foo.color >actual.raw &&
966 test_decode_color <actual.raw >actual &&
967 echo "<RED>" >expect &&
968 test_cmp expect actual
976 test_expect_success
'set --type=color' '
978 git config --type=color foo.color "red" &&
979 test_cmp expect .git/config
982 test_expect_success
'get --type=color barfs on non-color' '
983 echo "[foo]bar=not-a-color" >.git/config &&
984 test_must_fail git config --get --type=color foo.bar
987 test_expect_success
'set --type=color barfs on non-color' '
988 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
989 test_i18ngrep "cannot parse color" error
996 semicolon = "test;test"
999 test_expect_success
'quoting' '
1000 rm -f .git/config &&
1001 git config quote.leading " test" &&
1002 git config quote.ending "test " &&
1003 git config quote.semicolon "test;test" &&
1004 git config quote.hash "test#test" &&
1005 test_cmp expect .git/config
1008 test_expect_success
'key with newline' '
1009 test_must_fail git config "key.with
1012 test_expect_success
'value with newline' 'git config key.sub value.with\\\
1015 cat > .git
/config
<<\EOF
1020 noncont
= not continued
; \
1026 section.continued
=continued
1027 section.noncont
=not continued
1028 section.quotecont
=cont
;inued
1031 test_expect_success
'value continued on next line' '
1032 git config --list > result &&
1033 test_cmp expect result
1036 cat > .git
/config
<<\EOF
1037 [section
"sub=section"]
1046 section.sub
=section.val1
1047 foo
=barQsection.sub
=section.val2
1049 barQsection.sub
=section.val3
1052 Qsection.sub
=section.val4
1053 Qsection.sub
=section.val5Q
1055 test_expect_success
'--null --list' '
1056 git config --null --list >result.raw &&
1057 nul_to_q <result.raw >result &&
1059 test_cmp expect result
1062 test_expect_success
'--null --get-regexp' '
1063 git config --null --get-regexp "val[0-9]" >result.raw &&
1064 nul_to_q <result.raw >result &&
1066 test_cmp expect result
1069 test_expect_success
'inner whitespace kept verbatim' '
1070 git config section.val "foo bar" &&
1071 test_cmp_config "foo bar" section.val
1074 test_expect_success SYMLINKS
'symlinked configuration' '
1075 ln -s notyet myconfig &&
1076 git config --file=myconfig test.frotz nitfol &&
1079 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1080 git config --file=myconfig test.xyzzy rezrov &&
1083 cat >expect <<-\EOF &&
1088 git config --file=notyet test.frotz &&
1089 git config --file=notyet test.xyzzy
1091 test_cmp expect actual
1094 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
1095 ln -s doesnotexist linktonada &&
1096 ln -s linktonada linktolinktonada &&
1097 test_must_fail git config --file=linktonada --list &&
1098 test_must_fail git config --file=linktolinktonada --list
1101 test_expect_success
'check split_cmdline return' "
1102 git config alias.split-cmdline-fix 'echo \"' &&
1103 test_must_fail git split-cmdline-fix &&
1106 git commit -m 'initial commit' &&
1107 git config branch.main.mergeoptions 'echo \"' &&
1108 test_must_fail git merge main
1111 test_expect_success
'git -c "key=value" support' '
1112 cat >expect <<-\EOF &&
1118 git -c section.name=value config section.name &&
1119 git -c foo.CamelCase=value config foo.camelcase &&
1120 git -c foo.flag config --bool foo.flag
1122 test_cmp expect actual &&
1123 test_must_fail git -c name=value config section.name
1126 # We just need a type-specifier here that cares about the
1127 # distinction internally between a NULL boolean and a real
1128 # string (because most of git's internal parsers do care).
1129 # Using "--path" works, but we do not otherwise care about
1131 test_expect_success
'git -c can represent empty string' '
1133 git -c foo.empty= config --path foo.empty >actual &&
1134 test_cmp expect actual
1137 test_expect_success
'key sanity-checking' '
1138 test_must_fail git config foo=bar &&
1139 test_must_fail git config foo=.bar &&
1140 test_must_fail git config foo.ba=r &&
1141 test_must_fail git config foo.1bar &&
1142 test_must_fail git config foo."ba
1144 test_must_fail git config . false &&
1145 test_must_fail git config .foo false &&
1146 test_must_fail git config foo. false &&
1147 test_must_fail git config .foo. false &&
1148 git config foo.bar true &&
1149 git config foo."ba =z".bar false
1152 test_expect_success
'git -c works with aliases of builtins' '
1153 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1155 git checkconfig >actual &&
1156 test_cmp expect actual
1159 test_expect_success
'aliases can be CamelCased' '
1160 test_config alias.CamelCased "rev-parse HEAD" &&
1161 git CamelCased >out &&
1162 git rev-parse HEAD >expect &&
1166 test_expect_success
'git -c does not split values on equals' '
1167 echo "value with = in it" >expect &&
1168 git -c section.foo="value with = in it" config section.foo >actual &&
1169 test_cmp expect actual
1172 test_expect_success
'git -c dies on bogus config' '
1173 test_must_fail git -c core.bare=foo rev-parse
1176 test_expect_success
'git -c complains about empty key' '
1177 test_must_fail git -c "=foo" rev-parse
1180 test_expect_success
'git -c complains about empty key and value' '
1181 test_must_fail git -c "" rev-parse
1184 test_expect_success
'multiple git -c appends config' '
1185 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1186 cat >expect <<-\EOF &&
1190 git -c x.one=1 x >actual &&
1191 test_cmp expect actual
1194 test_expect_success
'last one wins: two level vars' '
1196 # sec.var and sec.VAR are the same variable, as the first
1197 # and the last level of a configuration variable name is
1202 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1203 test_cmp expect actual &&
1204 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1205 test_cmp expect actual &&
1207 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1208 test_cmp expect actual &&
1209 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1210 test_cmp expect actual
1213 test_expect_success
'last one wins: three level vars' '
1215 # v.a.r and v.A.r are not the same variable, as the middle
1216 # level of a three-level configuration variable name is
1220 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1221 test_cmp expect actual &&
1222 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1223 test_cmp expect actual &&
1225 # v.a.r and V.a.R are the same variable, as the first
1226 # and the last level of a configuration variable name is
1230 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1231 test_cmp expect actual &&
1232 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1233 test_cmp expect actual &&
1234 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1235 test_cmp expect actual &&
1236 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1237 test_cmp expect actual
1240 test_expect_success
'old-fashioned settings are case insensitive' '
1241 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1243 cat >testConfig_actual <<-EOF &&
1247 q_to_tab >testConfig_expect <<-EOF &&
1251 git config -f testConfig_actual "v.a.r" value2 &&
1252 test_cmp testConfig_expect testConfig_actual &&
1254 cat >testConfig_actual <<-EOF &&
1258 q_to_tab >testConfig_expect <<-EOF &&
1262 git config -f testConfig_actual "V.a.R" value2 &&
1263 test_cmp testConfig_expect testConfig_actual &&
1265 cat >testConfig_actual <<-EOF &&
1269 q_to_tab >testConfig_expect <<-EOF &&
1274 git config -f testConfig_actual "V.A.r" value2 &&
1275 test_cmp testConfig_expect testConfig_actual &&
1277 cat >testConfig_actual <<-EOF &&
1281 q_to_tab >testConfig_expect <<-EOF &&
1286 git config -f testConfig_actual "v.A.r" value2 &&
1287 test_cmp testConfig_expect testConfig_actual
1290 test_expect_success
'setting different case sensitive subsections ' '
1291 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1293 cat >testConfig_actual <<-EOF &&
1303 q_to_tab >testConfig_expect <<-EOF &&
1316 git config -f testConfig_actual a.b.c v2 &&
1317 # match section and subsection, key is cased differently.
1318 git config -f testConfig_actual K.E.y v2 &&
1319 # section and key are matched case insensitive, but subsection needs
1320 # to match; When writing out new values only the key is adjusted
1321 git config -f testConfig_actual v.A.r v2 &&
1322 # subsection is not matched:
1323 git config -f testConfig_actual d.E.f v2 &&
1324 test_cmp testConfig_expect testConfig_actual
1327 for VAR
in a .a a. a
.0b a.
"b c". a.
"b c".0d
1329 test_expect_success
"git -c $VAR=VAL rejects invalid '$VAR'" '
1330 test_must_fail git -c "$VAR=VAL" config -l
1334 for VAR
in a.b a.
"b c".d
1336 test_expect_success
"git -c $VAR=VAL works with valid '$VAR'" '
1338 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1339 test_cmp expect actual
1343 test_expect_success
'git -c is not confused by empty environment' '
1344 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1347 test_expect_success
'GIT_CONFIG_PARAMETERS handles old-style entries' '
1348 v="${SQ}key.one=foo${SQ}" &&
1349 v="$v ${SQ}key.two=bar${SQ}" &&
1350 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1351 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1352 cat >expect <<-EOF &&
1355 key.ambiguous section.whatever=value
1357 test_cmp expect actual
1360 test_expect_success
'GIT_CONFIG_PARAMETERS handles new-style entries' '
1361 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1362 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1363 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1364 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1365 cat >expect <<-EOF &&
1368 key.ambiguous=section.whatever value
1370 test_cmp expect actual
1373 test_expect_success
'old and new-style entries can mix' '
1374 v="${SQ}key.oldone=oldfoo${SQ}" &&
1375 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1376 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1377 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1378 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1379 cat >expect <<-EOF &&
1385 test_cmp expect actual
1388 test_expect_success
'old and new bools with ambiguous subsection' '
1389 v="${SQ}key.with=equals.oldbool${SQ}" &&
1390 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1391 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1392 cat >expect <<-EOF &&
1393 key.with equals.oldbool
1394 key.with=equals.newbool
1396 test_cmp expect actual
1399 test_expect_success
'detect bogus GIT_CONFIG_PARAMETERS' '
1400 cat >expect <<-\EOF &&
1404 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1405 git config --get-regexp "env.*" >actual &&
1406 test_cmp expect actual &&
1408 cat >expect <<-EOF &&
1412 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1413 git config --get-regexp "env.*" >actual &&
1414 test_cmp expect actual &&
1416 test_must_fail env \
1417 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1418 git config --get-regexp "env.*"
1421 test_expect_success
'git --config-env=key=envvar support' '
1422 cat >expect <<-\EOF &&
1431 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1432 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1433 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1434 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1435 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1436 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1438 test_cmp expect actual
1441 test_expect_success
'git --config-env with missing value' '
1442 test_must_fail env ENVVAR=value git --config-env 2>error &&
1443 grep "no config key given for --config-env" error &&
1444 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1445 grep "invalid config format: config" error
1448 test_expect_success
'git --config-env fails with invalid parameters' '
1449 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1450 test_i18ngrep "invalid config format: foo.flag" error &&
1451 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1452 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1453 sane_unset NONEXISTENT &&
1454 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1455 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1458 test_expect_success
'git -c and --config-env work together' '
1459 cat >expect <<-\EOF &&
1463 ENVVAR=env-value git \
1464 -c bar.cmd=cmd-value \
1465 --config-env=bar.env=ENVVAR \
1466 config --get-regexp "^bar.*" >actual &&
1467 test_cmp expect actual
1470 test_expect_success
'git -c and --config-env override each other' '
1471 cat >expect <<-\EOF &&
1476 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1477 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1479 test_cmp expect actual
1482 test_expect_success
'--config-env handles keys with equals' '
1483 echo value=with=equals >expect &&
1484 ENVVAR=value=with=equals git \
1485 --config-env=section.subsection=with=equals.key=ENVVAR \
1486 config section.subsection=with=equals.key >actual &&
1487 test_cmp expect actual
1490 test_expect_success
'git config handles environment config pairs' '
1491 GIT_CONFIG_COUNT=2 \
1492 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1493 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1494 git config --get-regexp "pair.*" >actual &&
1495 cat >expect <<-EOF &&
1499 test_cmp expect actual
1502 test_expect_success
'git config ignores pairs without count' '
1503 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1504 git config pair.one 2>error &&
1505 test_must_be_empty error
1508 test_expect_success
'git config ignores pairs exceeding count' '
1509 GIT_CONFIG_COUNT=1 \
1510 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1511 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1512 git config --get-regexp "pair.*" >actual 2>error &&
1513 cat >expect <<-EOF &&
1516 test_cmp expect actual &&
1517 test_must_be_empty error
1520 test_expect_success
'git config ignores pairs with zero count' '
1521 test_must_fail env \
1522 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1523 git config pair.one 2>error &&
1524 test_must_be_empty error
1527 test_expect_success
'git config ignores pairs with empty count' '
1528 test_must_fail env \
1529 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1530 git config pair.one 2>error &&
1531 test_must_be_empty error
1534 test_expect_success
'git config fails with invalid count' '
1535 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1536 test_i18ngrep "bogus count" error &&
1537 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1538 test_i18ngrep "too many entries" error
1541 test_expect_success
'git config fails with missing config key' '
1542 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1543 git config --list 2>error &&
1544 test_i18ngrep "missing config key" error
1547 test_expect_success
'git config fails with missing config value' '
1548 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1549 git config --list 2>error &&
1550 test_i18ngrep "missing config value" error
1553 test_expect_success
'git config fails with invalid config pair key' '
1554 test_must_fail env GIT_CONFIG_COUNT=1 \
1555 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1556 git config --list &&
1557 test_must_fail env GIT_CONFIG_COUNT=1 \
1558 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1562 test_expect_success
'environment overrides config file' '
1563 test_when_finished "rm -f .git/config" &&
1564 cat >.git/config <<-EOF &&
1568 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1569 git config pair.one >actual &&
1570 cat >expect <<-EOF &&
1573 test_cmp expect actual
1576 test_expect_success
'GIT_CONFIG_PARAMETERS overrides environment config' '
1577 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1578 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1579 git config pair.one >actual &&
1580 cat >expect <<-EOF &&
1583 test_cmp expect actual
1586 test_expect_success
'command line overrides environment config' '
1587 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1588 git -c pair.one=override config pair.one >actual &&
1589 cat >expect <<-EOF &&
1592 test_cmp expect actual
1595 test_expect_success
'git config --edit works' '
1596 git config -f tmp test.value no &&
1597 echo test.value=yes >expect &&
1598 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1599 git config -f tmp --list >actual &&
1600 test_cmp expect actual
1603 test_expect_success
'git config --edit respects core.editor' '
1604 git config -f tmp test.value no &&
1605 echo test.value=yes >expect &&
1606 test_config core.editor "echo [test]value=yes >" &&
1607 git config -f tmp --edit &&
1608 git config -f tmp --list >actual &&
1609 test_cmp expect actual
1612 # malformed configuration files
1613 test_expect_success
'barf on syntax error' '
1614 cat >.git/config <<-\EOF &&
1619 test_must_fail git config --get section.key 2>error &&
1620 test_i18ngrep " line 3 " error
1623 test_expect_success
'barf on incomplete section header' '
1624 cat >.git/config <<-\EOF &&
1625 # broken section line
1629 test_must_fail git config --get section.key 2>error &&
1630 test_i18ngrep " line 2 " error
1633 test_expect_success
'barf on incomplete string' '
1634 cat >.git/config <<-\EOF &&
1635 # broken value string
1639 test_must_fail git config --get section.key 2>error &&
1640 test_i18ngrep " line 3 " error
1643 test_expect_success
'urlmatch' '
1644 cat >.git/config <<-\EOF &&
1647 [http "https://weak.example.com"]
1649 cookieFile = /tmp/cookie.txt
1652 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1653 test_must_be_empty actual &&
1655 echo true >expect &&
1656 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1657 test_cmp expect actual &&
1659 echo false >expect &&
1660 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1661 test_cmp expect actual &&
1664 echo http.cookiefile /tmp/cookie.txt &&
1665 echo http.sslverify false
1667 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1668 test_cmp expect actual
1671 test_expect_success
'urlmatch with --show-scope' '
1672 cat >.git/config <<-\EOF &&
1673 [http "https://weak.example.com"]
1675 cookieFile = /tmp/cookie.txt
1678 cat >expect <<-EOF &&
1679 local http.cookiefile /tmp/cookie.txt
1680 local http.sslverify false
1682 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1683 test_cmp expect actual
1686 test_expect_success
'urlmatch favors more specific URLs' '
1687 cat >.git/config <<-\EOF &&
1688 [http "https://example.com/"]
1689 cookieFile = /tmp/root.txt
1690 [http "https://example.com/subdirectory"]
1691 cookieFile = /tmp/subdirectory.txt
1692 [http "https://user@example.com/"]
1693 cookieFile = /tmp/user.txt
1694 [http "https://averylonguser@example.com/"]
1695 cookieFile = /tmp/averylonguser.txt
1696 [http "https://preceding.example.com"]
1697 cookieFile = /tmp/preceding.txt
1698 [http "https://*.example.com"]
1699 cookieFile = /tmp/wildcard.txt
1700 [http "https://*.example.com/wildcardwithsubdomain"]
1701 cookieFile = /tmp/wildcardwithsubdomain.txt
1702 [http "https://*.example.*"]
1703 cookieFile = /tmp/multiwildcard.txt
1704 [http "https://trailing.example.com"]
1705 cookieFile = /tmp/trailing.txt
1706 [http "https://user@*.example.com/"]
1707 cookieFile = /tmp/wildcardwithuser.txt
1708 [http "https://sub.example.com/"]
1709 cookieFile = /tmp/sub.txt
1712 echo http.cookiefile /tmp/root.txt >expect &&
1713 git config --get-urlmatch HTTP https://example.com >actual &&
1714 test_cmp expect actual &&
1716 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1717 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1718 test_cmp expect actual &&
1720 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1721 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1722 test_cmp expect actual &&
1724 echo http.cookiefile /tmp/user.txt >expect &&
1725 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1726 test_cmp expect actual &&
1728 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1729 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1730 test_cmp expect actual &&
1732 echo http.cookiefile /tmp/preceding.txt >expect &&
1733 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1734 test_cmp expect actual &&
1736 echo http.cookiefile /tmp/wildcard.txt >expect &&
1737 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1738 test_cmp expect actual &&
1740 echo http.cookiefile /tmp/sub.txt >expect &&
1741 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1742 test_cmp expect actual &&
1744 echo http.cookiefile /tmp/trailing.txt >expect &&
1745 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1746 test_cmp expect actual &&
1748 echo http.cookiefile /tmp/sub.txt >expect &&
1749 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1750 test_cmp expect actual &&
1752 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1753 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1754 test_cmp expect actual
1757 test_expect_success
'urlmatch with wildcard' '
1758 cat >.git/config <<-\EOF &&
1761 [http "https://*.example.com"]
1763 cookieFile = /tmp/cookie.txt
1766 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1767 test_must_be_empty actual &&
1769 echo true >expect &&
1770 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1771 test_cmp expect actual &&
1773 echo true >expect &&
1774 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1775 test_cmp expect actual &&
1777 echo true >expect &&
1778 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1779 test_cmp expect actual &&
1781 echo false >expect &&
1782 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1783 test_cmp expect actual &&
1786 echo http.cookiefile /tmp/cookie.txt &&
1787 echo http.sslverify false
1789 git config --get-urlmatch HTTP https://good.example.com >actual &&
1790 test_cmp expect actual &&
1792 echo http.sslverify >expect &&
1793 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1794 test_cmp expect actual
1797 # good section hygiene
1798 test_expect_success
'--unset last key removes section (except if commented)' '
1799 cat >.git/config <<-\EOF &&
1800 # some generic comment on the configuration file itself
1801 # a comment specific to this "section" section.
1803 # some intervening lines
1804 # that should also be dropped
1807 # please be careful when you update the above variable
1810 cat >expect <<-\EOF &&
1811 # some generic comment on the configuration file itself
1812 # a comment specific to this "section" section.
1814 # some intervening lines
1815 # that should also be dropped
1817 # please be careful when you update the above variable
1820 git config --unset section.key &&
1821 test_cmp expect .git/config &&
1823 cat >.git/config <<-\EOF &&
1829 cat >expect <<-\EOF &&
1833 git config --unset section.key &&
1834 test_cmp expect .git/config &&
1836 q_to_tab >.git/config <<-\EOF &&
1843 git config --unset two.key &&
1844 ! grep two .git/config &&
1846 q_to_tab >.git/config <<-\EOF &&
1853 git config --unset-all one.key &&
1854 test_line_count = 0 .git/config &&
1856 q_to_tab >.git/config <<-\EOF &&
1859 Q# a comment not at the start
1863 git config --unset two.key &&
1864 grep two .git/config &&
1866 q_to_tab >.git/config <<-\EOF &&
1868 Qkey = not [two "subsection"]
1875 git config --unset two.subsection.key &&
1876 test "not [two subsection]" = "$(git config one.key)" &&
1877 test_line_count = 3 .git/config
1880 test_expect_success
'--unset-all removes section if empty & uncommented' '
1881 cat >.git/config <<-\EOF &&
1887 git config --unset-all section.key &&
1888 test_line_count = 0 .git/config
1891 test_expect_success
'adding a key into an empty section reuses header' '
1892 cat >.git/config <<-\EOF &&
1896 q_to_tab >expect <<-\EOF &&
1901 git config section.key value &&
1902 test_cmp expect .git/config
1905 test_expect_success POSIXPERM
,PERL
'preserves existing permissions' '
1906 chmod 0600 .git/config &&
1907 git config imap.pass Hunter2 &&
1909 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1910 git config --rename-section imap pop &&
1912 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1915 ! test_have_prereq MINGW ||
1916 HOME
="$(pwd)" # convert to Windows path
1918 test_expect_success
'set up --show-origin tests' '
1919 INCLUDE_DIR="$HOME/include" &&
1920 mkdir -p "$INCLUDE_DIR" &&
1921 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1925 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1929 cat >"$HOME"/.gitconfig <<-EOF &&
1934 path = "$INCLUDE_DIR/absolute.include"
1936 cat >.git/config <<-\EOF
1941 path = ../include/relative.include
1945 test_expect_success
'--show-origin with --list' '
1946 cat >expect <<-EOF &&
1947 file:$HOME/.gitconfig user.global=true
1948 file:$HOME/.gitconfig user.override=global
1949 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1950 file:$INCLUDE_DIR/absolute.include user.absolute=include
1951 file:.git/config user.local=true
1952 file:.git/config user.override=local
1953 file:.git/config include.path=../include/relative.include
1954 file:.git/../include/relative.include user.relative=include
1955 command line: user.environ=true
1956 command line: user.cmdline=true
1958 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1959 git -c user.cmdline=true config --list --show-origin >output &&
1960 test_cmp expect output
1963 test_expect_success
'--show-origin with --list --null' '
1964 cat >expect <<-EOF &&
1965 file:$HOME/.gitconfigQuser.global
1966 trueQfile:$HOME/.gitconfigQuser.override
1967 globalQfile:$HOME/.gitconfigQinclude.path
1968 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1969 includeQfile:.git/configQuser.local
1970 trueQfile:.git/configQuser.override
1971 localQfile:.git/configQinclude.path
1972 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1973 includeQcommand line:Quser.cmdline
1976 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1977 nul_to_q <output.raw >output &&
1978 # The here-doc above adds a newline that the --null output would not
1979 # include. Add it here to make the two comparable.
1981 test_cmp expect output
1984 test_expect_success
'--show-origin with single file' '
1985 cat >expect <<-\EOF &&
1986 file:.git/config user.local=true
1987 file:.git/config user.override=local
1988 file:.git/config include.path=../include/relative.include
1990 git config --local --list --show-origin >output &&
1991 test_cmp expect output
1994 test_expect_success
'--show-origin with --get-regexp' '
1995 cat >expect <<-EOF &&
1996 file:$HOME/.gitconfig user.global true
1997 file:.git/config user.local true
1999 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
2000 test_cmp expect output
2003 test_expect_success
'--show-origin getting a single key' '
2004 cat >expect <<-\EOF &&
2005 file:.git/config local
2007 git config --show-origin user.override >output &&
2008 test_cmp expect output
2011 test_expect_success
'set up custom config file' '
2012 CUSTOM_CONFIG_FILE="custom.conf" &&
2013 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
2019 test_expect_success
!MINGW
'set up custom config file with special name characters' '
2020 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2021 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2024 test_expect_success
!MINGW
'--show-origin escape special file name characters' '
2025 cat >expect <<-\EOF &&
2026 file:"file\" (dq) and spaces.conf" user.custom=true
2028 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2029 test_cmp expect output
2032 test_expect_success
'--show-origin stdin' '
2033 cat >expect <<-\EOF &&
2034 standard input: user.custom=true
2036 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2037 test_cmp expect output
2040 test_expect_success
'--show-origin stdin with file include' '
2041 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2045 cat >expect <<-EOF &&
2046 file:$INCLUDE_DIR/stdin.include include
2048 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2049 git config --show-origin --includes --file - user.stdin >output &&
2051 test_cmp expect output
2054 test_expect_success
'--show-origin blob' '
2055 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2056 cat >expect <<-EOF &&
2057 blob:$blob user.custom=true
2059 git config --blob=$blob --show-origin --list >output &&
2060 test_cmp expect output
2063 test_expect_success
'--show-origin blob ref' '
2064 cat >expect <<-\EOF &&
2065 blob:main:custom.conf user.custom=true
2067 git add "$CUSTOM_CONFIG_FILE" &&
2068 git commit -m "new config file" &&
2069 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2070 test_cmp expect output
2073 test_expect_success
'--show-origin with --default' '
2074 git config --show-origin --default foo some.key >actual &&
2075 echo "command line: foo" >expect &&
2076 test_cmp expect actual
2079 test_expect_success
'--show-scope with --list' '
2080 cat >expect <<-EOF &&
2081 global user.global=true
2082 global user.override=global
2083 global include.path=$INCLUDE_DIR/absolute.include
2084 global user.absolute=include
2085 local user.local=true
2086 local user.override=local
2087 local include.path=../include/relative.include
2088 local user.relative=include
2089 local core.repositoryformatversion=1
2090 local extensions.worktreeconfig=true
2091 worktree user.worktree=true
2092 command user.cmdline=true
2094 git worktree add wt1 &&
2095 # We need these to test for worktree scope, but outside of this
2096 # test, this is just noise
2097 test_config core.repositoryformatversion 1 &&
2098 test_config extensions.worktreeConfig true &&
2099 git config --worktree user.worktree true &&
2100 git -c user.cmdline=true config --list --show-scope >output &&
2101 test_cmp expect output
2104 test_expect_success
!MINGW
'--show-scope with --blob' '
2105 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2106 cat >expect <<-EOF &&
2107 command user.custom=true
2109 git config --blob=$blob --show-scope --list >output &&
2110 test_cmp expect output
2113 test_expect_success
'--show-scope with --local' '
2114 cat >expect <<-\EOF &&
2115 local user.local=true
2116 local user.override=local
2117 local include.path=../include/relative.include
2119 git config --local --list --show-scope >output &&
2120 test_cmp expect output
2123 test_expect_success
'--show-scope getting a single value' '
2124 cat >expect <<-\EOF &&
2127 git config --show-scope --get user.local >output &&
2128 test_cmp expect output
2131 test_expect_success
'--show-scope with --show-origin' '
2132 cat >expect <<-EOF &&
2133 global file:$HOME/.gitconfig user.global=true
2134 global file:$HOME/.gitconfig user.override=global
2135 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2136 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2137 local file:.git/config user.local=true
2138 local file:.git/config user.override=local
2139 local file:.git/config include.path=../include/relative.include
2140 local file:.git/../include/relative.include user.relative=include
2141 command command line: user.cmdline=true
2143 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2144 test_cmp expect output
2147 test_expect_success
'--show-scope with --default' '
2148 git config --show-scope --default foo some.key >actual &&
2149 echo "command foo" >expect &&
2150 test_cmp expect actual
2153 test_expect_success
'override global and system config' '
2154 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2155 cat >"$HOME"/.gitconfig <<-EOF &&
2160 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2161 mkdir -p "$HOME"/.config/git &&
2162 cat >"$HOME"/.config/git/config <<-EOF &&
2166 cat >.git/config <<-EOF &&
2170 cat >custom-global-config <<-EOF &&
2174 cat >custom-system-config <<-EOF &&
2179 cat >expect <<-EOF &&
2180 global xdg.config=true
2181 global home.config=true
2182 local local.config=true
2184 git config --show-scope --list >output &&
2185 test_cmp expect output &&
2187 cat >expect <<-EOF &&
2188 system system.config=true
2189 global global.config=true
2190 local local.config=true
2192 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2193 git config --show-scope --list >output &&
2194 test_cmp expect output &&
2196 cat >expect <<-EOF &&
2197 local local.config=true
2199 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2200 git config --show-scope --list >output &&
2201 test_cmp expect output
2204 test_expect_success
'override global and system config with missing file' '
2205 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2206 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2207 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2210 test_expect_success
'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2211 # `git config --system` has different semantics compared to other
2212 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2213 # variable has an effect via a different proxy.
2214 cat >alias-config <<-EOF &&
2216 hello-world = !echo "hello world"
2218 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2220 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2221 git hello-world >actual &&
2222 echo "hello world" >expect &&
2223 test_cmp expect actual
2226 test_expect_success
'write to overridden global and system config' '
2227 cat >expect <<EOF &&
2232 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2233 test_cmp expect write-to-global &&
2235 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2236 test_cmp expect write-to-system
2239 for opt
in --local --worktree
2241 test_expect_success
"$opt requires a repo" '
2242 # we expect 128 to ensure that we do not simply
2243 # fail to find anything and return code "1"
2244 test_expect_code 128 nongit git config $opt foo.bar
2248 cat >.git
/config
<<-\EOF &&
2255 test_expect_success 'identical modern --type specifiers are allowed' '
2256 test_cmp_config 1048576 --type=int --type=int section.big
2259 test_expect_success 'identical legacy --type specifiers are allowed' '
2260 test_cmp_config 1048576 --int --int section.big
2263 test_expect_success 'identical mixed --type specifiers are allowed' '
2264 test_cmp_config 1048576 --int --type=int section.big
2267 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2268 test_must_fail git config --type=int --type=bool section.big 2>error &&
2269 test_i18ngrep "only one type at a time" error
2272 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2273 test_must_fail git config --int --bool section.big 2>error &&
2274 test_i18ngrep "only one type at a time" error
2277 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2278 test_must_fail git config --type=int --bool section.big 2>error &&
2279 test_i18ngrep "only one type at a time" error
2282 test_expect_success '--type allows valid type specifiers' '
2283 test_cmp_config true --type=bool section.foo
2286 test_expect_success '--no-type unsets type specifiers' '
2287 test_cmp_config 10 --type=bool --no-type section.number
2290 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2291 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2294 test_expect_success '--type rejects unknown specifiers' '
2295 test_must_fail git config --type=nonsense section.foo 2>error &&
2296 test_i18ngrep "unrecognized --type argument" error
2299 test_expect_success '--type=int requires at least one digit' '
2300 test_must_fail git config --type int --default m some.key >out 2>error &&
2301 grep "bad numeric config value" error &&
2302 test_must_be_empty out
2305 test_expect_success '--replace-all does not invent newlines' '
2306 q_to_tab >.git/config <<-\
EOF &&
2314 q_to_tab >expect <<-\EOF &&
2322 git config --replace-all abc.key b &&
2323 test_cmp expect .git/config
2326 test_expect_success 'set all config with value-pattern' '
2327 test_when_finished rm -f config initial &&
2328 git config --file=initial abc.key one &&
2330 # no match => add new entry
2331 cp initial config &&
2332 git config --file=config abc.key two a+ &&
2333 git config --file=config --list >actual &&
2334 cat >expect <<-\EOF &&
2338 test_cmp expect actual &&
2340 # multiple matches => failure
2341 test_must_fail git config --file=config abc.key three o+ 2>err &&
2342 test_i18ngrep "has multiple values" err &&
2344 # multiple values, no match => add
2345 git config --file=config abc.key three a+ &&
2346 git config --file=config --list >actual &&
2347 cat >expect <<-\EOF &&
2352 test_cmp expect actual &&
2354 # single match => replace
2355 git config --file=config abc.key four h+ &&
2356 git config --file=config --list >actual &&
2357 cat >expect <<-\EOF &&
2362 test_cmp expect actual
2365 test_expect_success '--replace-all and value-pattern' '
2366 test_when_finished rm -f config &&
2367 git config --file=config --add abc.key one &&
2368 git config --file=config --add abc.key two &&
2369 git config --file=config --add abc.key three &&
2370 git config --file=config --replace-all abc.key four "o+" &&
2371 git config --file=config --list >actual &&
2372 cat >expect <<-\EOF &&
2376 test_cmp expect actual
2379 test_expect_success 'refuse --fixed-value for incompatible actions' '
2380 test_when_finished rm -f config &&
2381 git config --file=config dev.null bogus &&
2383 # These modes do not allow --fixed-value at all
2384 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2385 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2386 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2387 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2388 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2389 test_must_fail git config --file=config --fixed-value --list &&
2390 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2391 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2393 # These modes complain when --fixed-value has no value-pattern
2394 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2395 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2396 test_must_fail git config --file=config --fixed-value --get dev.null &&
2397 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2398 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2399 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2400 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2403 test_expect_success '--fixed-value uses exact string matching' '
2404 test_when_finished rm -f config initial &&
2405 META="a+b*c?d[e]f.g" &&
2406 git config --file=initial fixed.test "$META" &&
2408 cp initial config &&
2409 git config --file=config fixed.test bogus "$META" &&
2410 git config --file=config --list >actual &&
2411 cat >expect <<-EOF &&
2415 test_cmp expect actual &&
2417 cp initial config &&
2418 git config --file=config --fixed-value fixed.test bogus "$META" &&
2419 git config --file=config --list >actual &&
2420 cat >expect <<-\EOF &&
2423 test_cmp expect actual &&
2425 cp initial config &&
2426 test_must_fail git config --file=config --unset fixed.test "$META" &&
2427 git config --file=config --fixed-value --unset fixed.test "$META" &&
2428 test_must_fail git config --file=config fixed.test &&
2430 cp initial config &&
2431 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2432 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2433 test_must_fail git config --file=config fixed.test &&
2435 cp initial config &&
2436 git config --file=config --replace-all fixed.test bogus "$META" &&
2437 git config --file=config --list >actual &&
2438 cat >expect <<-EOF &&
2442 test_cmp expect actual &&
2444 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2445 git config --file=config --list >actual &&
2446 cat >expect <<-EOF &&
2450 test_cmp expect actual
2453 test_expect_success '--get and --get-all with --fixed-value' '
2454 test_when_finished rm -f config &&
2455 META="a+b*c?d[e]f.g" &&
2456 git config --file=config fixed.test bogus &&
2457 git config --file=config --add fixed.test "$META" &&
2459 git config --file=config --get fixed.test bogus &&
2460 test_must_fail git config --file=config --get fixed.test "$META" &&
2461 git config --file=config --get --fixed-value fixed.test "$META" &&
2462 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2464 git config --file=config --get-all fixed.test bogus &&
2465 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2466 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2467 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2469 git config --file=config --get-regexp fixed+ bogus &&
2470 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2471 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2472 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2475 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2476 git init hasremoteurlTest &&
2477 test_when_finished "rm -rf hasremoteurlTest" &&
2479 cat >include-this <<-\EOF &&
2481 this = this-is-included
2483 cat >dont-include-that <<-\EOF &&
2485 that = that-is-not-included
2487 cat >>hasremoteurlTest/.git/config <<-EOF &&
2488 [includeIf "hasconfig:remote.*.url:foourl"]
2489 path = "$(pwd)/include-this"
2490 [includeIf "hasconfig:remote.*.url:barurl"]
2491 path = "$(pwd)/dont-include-that"
2496 echo this-is-included >expect-this &&
2497 git -C hasremoteurlTest config --get user.this >actual-this &&
2498 test_cmp expect-this actual-this &&
2500 test_must_fail git -C hasremoteurlTest config --get user.that
2503 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2504 git init hasremoteurlTest &&
2505 test_when_finished "rm -rf hasremoteurlTest" &&
2507 cat >include-two-three <<-\EOF &&
2509 two = included-config
2510 three = included-config
2512 cat >>hasremoteurlTest/.git/config <<-EOF &&
2518 [includeIf "hasconfig:remote.*.url:foourl"]
2519 path = "$(pwd)/include-two-three"
2524 echo main-config >expect-main-config &&
2525 echo included-config >expect-included-config &&
2527 git -C hasremoteurlTest config --get user.one >actual &&
2528 test_cmp expect-main-config actual &&
2530 git -C hasremoteurlTest config --get user.two >actual &&
2531 test_cmp expect-included-config actual &&
2533 git -C hasremoteurlTest config --get user.three >actual &&
2534 test_cmp expect-main-config actual
2537 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2538 git init hasremoteurlTest &&
2539 test_when_finished "rm -rf hasremoteurlTest" &&
2541 printf "[user]\ndss = yes\n" >double-star-start &&
2542 printf "[user]\ndse = yes\n" >double-star-end &&
2543 printf "[user]\ndsm = yes\n" >double-star-middle &&
2544 printf "[user]\nssm = yes\n" >single-star-middle &&
2545 printf "[user]\nno = no\n" >no &&
2547 cat >>hasremoteurlTest/.git/config <<-EOF &&
2549 url = https://foo/bar/baz
2550 [includeIf "hasconfig:remote.*.url:**/baz"]
2551 path = "$(pwd)/double-star-start"
2552 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2554 [includeIf "hasconfig:remote.*.url:https:/**"]
2555 path = "$(pwd)/double-star-end"
2556 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2558 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2559 path = "$(pwd)/double-star-middle"
2560 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2562 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2563 path = "$(pwd)/single-star-middle"
2564 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2568 git -C hasremoteurlTest config --get user.dss &&
2569 git -C hasremoteurlTest config --get user.dse &&
2570 git -C hasremoteurlTest config --get user.dsm &&
2571 git -C hasremoteurlTest config --get user.ssm &&
2572 test_must_fail git -C hasremoteurlTest config --get user.no
2575 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2576 git init hasremoteurlTest &&
2577 test_when_finished "rm -rf hasremoteurlTest" &&
2579 cat >include-with-url <<-\EOF &&
2583 cat >>hasremoteurlTest/.git/config <<-EOF &&
2584 [includeIf "hasconfig:remote.*.url:foourl"]
2585 path = "$(pwd)/include-with-url"
2588 # test with any Git command
2589 test_must_fail git -C hasremoteurlTest status 2>err &&
2590 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err