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
13 test_expect_success
'clear default config' '
21 test_expect_success
'initial' '
22 git config section.penguin "little blue" &&
23 test_cmp expect .git/config
31 test_expect_success
'mixed case' '
32 git config Section.Movie BadPhysics &&
33 test_cmp expect .git/config
43 test_expect_success
'similar section' '
44 git config Sections.WhatEver Second &&
45 test_cmp expect .git/config
56 test_expect_success
'uppercase section' '
57 git config SECTION.UPPERCASE true &&
58 test_cmp expect .git/config
61 test_expect_success
'replace with non-match' '
62 git config section.penguin kingpin !blue
65 test_expect_success
'replace with non-match (actually matching)' '
66 git config section.penguin "very blue" !kingpin
79 test_expect_success
'non-match result' 'test_cmp expect .git/config'
81 test_expect_success
'find mixed-case key by canonical name' '
82 test_cmp_config Second sections.whatever
85 test_expect_success
'find mixed-case key by non-canonical name' '
86 test_cmp_config Second SeCtIoNs.WhAtEvEr
89 test_expect_success
'subsections are not canonicalized by git-config' '
90 cat >>.git/config <<-\EOF &&
93 [section "SubSection"]
96 test_cmp_config one section.subsection.key &&
97 test_cmp_config two section.SubSection.key
100 cat > .git
/config
<<\EOF
109 test_expect_success
'unset with cont. lines' '
110 git config --unset beta.baz
120 test_expect_success
'unset with cont. lines is correct' 'test_cmp expect .git/config'
122 cat > .git
/config
<< EOF
123 [beta] ; silly comment # another comment
124 noIndent= sillyValue ; 'nother silly comment
128 haha ="beta" # last silly comment
131 [nextSection] noNewline = ouch
134 cp .git
/config .git
/config2
136 test_expect_success
'multiple unset' '
137 git config --unset-all beta.haha
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
146 [nextSection] noNewline = ouch
149 test_expect_success
'multiple unset is correct' '
150 test_cmp expect .git/config
153 cp .git
/config2 .git
/config
155 test_expect_success
'--replace-all missing value' '
156 test_must_fail git config --replace-all beta.haha &&
157 test_cmp .git/config2 .git/config
162 test_expect_success
'--replace-all' '
163 git config --replace-all beta.haha gamma
167 [beta] ; silly comment # another comment
168 noIndent= sillyValue ; 'nother silly comment
173 [nextSection] noNewline = ouch
176 test_expect_success
'all replaced' '
177 test_cmp expect .git/config
181 [beta] ; silly comment # another comment
182 noIndent= sillyValue ; 'nother silly comment
187 [nextSection] noNewline = ouch
189 test_expect_success
'really mean test' '
190 git config beta.haha alpha &&
191 test_cmp expect .git/config
195 [beta] ; silly comment # another comment
196 noIndent= sillyValue ; 'nother silly comment
204 test_expect_success
'really really mean test' '
205 git config nextsection.nonewline wow &&
206 test_cmp expect .git/config
209 test_expect_success
'get value' '
210 test_cmp_config alpha beta.haha
214 [beta] ; silly comment # another comment
215 noIndent= sillyValue ; 'nother silly comment
222 test_expect_success
'unset' '
223 git config --unset beta.haha &&
224 test_cmp expect .git/config
228 [beta] ; silly comment # another comment
229 noIndent= sillyValue ; 'nother silly comment
235 NoNewLine = wow2 for me
237 test_expect_success
'multivar' '
238 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
239 test_cmp expect .git/config
242 test_expect_success
'non-match' '
243 git config --get nextsection.nonewline !for
246 test_expect_success
'non-match value' '
247 test_cmp_config wow --get nextsection.nonewline !for
250 test_expect_success
'multi-valued get returns final one' '
251 test_cmp_config "wow2 for me" --get nextsection.nonewline
254 test_expect_success
'multi-valued get-all returns all' '
255 cat >expect <<-\EOF &&
259 git config --get-all nextsection.nonewline >actual &&
260 test_cmp expect actual
264 [beta] ; silly comment # another comment
265 noIndent= sillyValue ; 'nother silly comment
271 NoNewLine = wow2 for me
273 test_expect_success
'multivar replace' '
274 git config nextsection.nonewline "wow3" "wow$" &&
275 test_cmp expect .git/config
278 test_expect_success
'ambiguous unset' '
279 test_must_fail git config --unset nextsection.nonewline
282 test_expect_success
'invalid unset' '
283 test_must_fail git config --unset somesection.nonewline
287 [beta] ; silly comment # another comment
288 noIndent= sillyValue ; 'nother silly comment
293 NoNewLine = wow2 for me
296 test_expect_success
'multivar unset' '
297 git config --unset nextsection.nonewline "wow3$" &&
298 test_cmp expect .git/config
301 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
303 test_expect_success
'correct key' 'git config 123456.a123 987'
305 test_expect_success
'hierarchical section' '
306 git config Version.1.2.3eX.Alpha beta
310 [beta] ; silly comment # another comment
311 noIndent= sillyValue ; 'nother silly comment
316 NoNewLine = wow2 for me
323 test_expect_success
'hierarchical section value' '
324 test_cmp expect .git/config
328 beta.noindent=sillyValue
329 nextsection.nonewline=wow2 for me
331 version.1.2.3eX.alpha=beta
334 test_expect_success
'working --list' '
335 git config --list > output &&
336 test_cmp expect output
338 test_expect_success
'--list without repo produces empty output' '
339 git --git-dir=nonexistent config --list >output &&
340 test_must_be_empty output
345 nextsection.nonewline
347 version.1.2.3eX.alpha
350 test_expect_success
'--name-only --list' '
351 git config --name-only --list >output &&
352 test_cmp expect output
356 beta.noindent sillyValue
357 nextsection.nonewline wow2 for me
360 test_expect_success
'--get-regexp' '
361 git config --get-regexp in >output &&
362 test_cmp expect output
367 nextsection.nonewline
370 test_expect_success
'--name-only --get-regexp' '
371 git config --name-only --get-regexp in >output &&
372 test_cmp expect output
380 test_expect_success
'--add' '
381 git config --add nextsection.nonewline "wow4 for you" &&
382 git config --get-all nextsection.nonewline > output &&
383 test_cmp expect output
386 cat > .git
/config
<< EOF
393 test_expect_success
'get variable with no value' '
394 git config --get novalue.variable ^$
397 test_expect_success
'get variable with empty value' '
398 git config --get emptyvalue.variable ^$
401 echo novalue.variable
> expect
403 test_expect_success
'get-regexp variable with no value' '
404 git config --get-regexp novalue > output &&
405 test_cmp expect output
408 echo 'novalue.variable true' > expect
410 test_expect_success
'get-regexp --bool variable with no value' '
411 git config --bool --get-regexp novalue > output &&
412 test_cmp expect output
415 echo 'emptyvalue.variable ' > expect
417 test_expect_success
'get-regexp variable with empty value' '
418 git config --get-regexp emptyvalue > output &&
419 test_cmp expect output
424 test_expect_success
'get bool variable with no value' '
425 git config --bool novalue.variable > output &&
426 test_cmp expect output
431 test_expect_success
'get bool variable with empty value' '
432 git config --bool emptyvalue.variable > output &&
433 test_cmp expect output
436 test_expect_success
'no arguments, but no crash' '
437 test_must_fail git config >output 2>&1 &&
438 test_i18ngrep usage output
441 cat > .git
/config
<< EOF
453 test_expect_success
'new section is partial match of another' '
455 test_cmp expect .git/config
468 test_expect_success
'new variable inserts into proper section' '
471 test_cmp expect .git/config
474 test_expect_success
'alternative --file (non-existing file should fail)' '
475 test_must_fail git config --file non-existing-config -l &&
476 test_must_fail git config --file non-existing-config test.xyzzy
479 cat > other-config
<< EOF
488 test_expect_success
'alternative GIT_CONFIG' '
489 GIT_CONFIG=other-config git config --list >output &&
490 test_cmp expect output
493 test_expect_success
'alternative GIT_CONFIG (--file)' '
494 git config --file other-config --list >output &&
495 test_cmp expect output
498 test_expect_success
'alternative GIT_CONFIG (--file=-)' '
499 git config --file - --list <other-config >output &&
500 test_cmp expect output
503 test_expect_success
'setting a value in stdin is an error' '
504 test_must_fail git config --file - some.value foo
507 test_expect_success
'editing stdin is an error' '
508 test_must_fail git config --file - --edit
511 test_expect_success
'refer config from subdirectory' '
513 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
523 test_expect_success
'--set in alternative file' '
524 git config --file=other-config anwohner.park ausweis &&
525 test_cmp expect other-config
528 cat > .git
/config
<< EOF
535 [branch "1 234 blabl/a"]
539 test_expect_success
'rename section' '
540 git config --rename-section branch.eins branch.zwei
550 [branch "1 234 blabl/a"]
554 test_expect_success
'rename succeeded' '
555 test_cmp expect .git/config
558 test_expect_success
'rename non-existing section' '
559 test_must_fail git config --rename-section \
560 branch."world domination" branch.drei
563 test_expect_success
'rename succeeded' '
564 test_cmp expect .git/config
567 test_expect_success
'rename another section' '
568 git config --rename-section branch."1 234 blabl/a" branch.drei
582 test_expect_success
'rename succeeded' '
583 test_cmp expect .git/config
586 cat >> .git
/config
<< EOF
587 [branch "vier"] z = 1
590 test_expect_success
'rename a section with a var on the same line' '
591 git config --rename-section branch.vier branch.zwei
607 test_expect_success
'rename succeeded' '
608 test_cmp expect .git/config
611 test_expect_success
'renaming empty section name is rejected' '
612 test_must_fail git config --rename-section branch.zwei ""
615 test_expect_success
'renaming to bogus section is rejected' '
616 test_must_fail git config --rename-section branch.zwei "bogus name"
619 test_expect_success
'renaming a section with a long line' '
622 printf " c = d %1024s [a] e = f\\n" " " &&
623 printf "[a] g = h\\n"
625 git config -f y --rename-section a xyz &&
626 test_must_fail git config -f y b.e
629 test_expect_success
'renaming an embedded section with a long line' '
632 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
633 printf "[a] g = h\\n"
635 git config -f y --rename-section a xyz &&
636 test_must_fail git config -f y foo.e
639 test_expect_success
'renaming a section with an overly-long line' '
642 printf " c = d %525000s e" " " &&
643 printf "[a] g = h\\n"
645 test_must_fail git config -f y --rename-section a xyz 2>err &&
646 grep "refusing to work with overly long line in .y. on line 2" err
649 cat >> .git
/config
<< EOF
650 [branch "zwei"] a = 1 [branch "vier"]
653 test_expect_success
'remove section' '
654 git config --remove-section branch.zwei
664 test_expect_success
'section was removed properly' '
665 test_cmp expect .git/config
671 dbname = %Ggitcvs2.%a.%m.sqlite
673 dbname = %Ggitcvs1.%a.%m.sqlite
676 test_expect_success
'section ending' '
678 git config gitcvs.enabled true &&
679 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
680 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
681 test_cmp expect .git/config
685 test_expect_success numbers
'
686 git config kilo.gram 1k &&
687 git config mega.ton 1m &&
689 echo 1048576 >>expect &&
690 git config --int --get kilo.gram >actual &&
691 git config --int --get mega.ton >>actual &&
692 test_cmp expect actual
695 test_expect_success
'--int is at least 64 bits' '
696 git config giga.watts 121g &&
698 test_cmp_config 129922760704 --int --get giga.watts
701 test_expect_success
'invalid unit' '
702 git config aninvalid.unit "1auto" &&
703 test_cmp_config 1auto aninvalid.unit &&
704 test_must_fail git config --int --get aninvalid.unit 2>actual &&
705 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
708 test_expect_success
'invalid unit boolean' '
709 git config commit.gpgsign "1true" &&
710 test_cmp_config 1true commit.gpgsign &&
711 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
712 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
715 test_expect_success
'line number is reported correctly' '
716 printf "[bool]\n\tvar\n" >invalid &&
717 test_must_fail git config -f invalid --path bool.var 2>actual &&
718 test_i18ngrep "line 2" actual
721 test_expect_success
'invalid stdin config' '
722 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
723 test_i18ngrep "bad config line 1 in standard input" output
737 test_expect_success bool
'
739 git config bool.true1 01 &&
740 git config bool.true2 -1 &&
741 git config bool.true3 YeS &&
742 git config bool.true4 true &&
743 git config bool.false1 000 &&
744 git config bool.false2 "" &&
745 git config bool.false3 nO &&
746 git config bool.false4 FALSE &&
750 git config --bool --get bool.true$i >>result
751 git config --bool --get bool.false$i >>result
753 test_cmp expect result'
755 test_expect_success
'invalid bool (--get)' '
757 git config bool.nobool foobar &&
758 test_must_fail git config --bool --get bool.nobool'
760 test_expect_success
'invalid bool (set)' '
762 test_must_fail git config --bool bool.nobool foobar'
776 test_expect_success
'set --bool' '
779 git config --bool bool.true1 01 &&
780 git config --bool bool.true2 -1 &&
781 git config --bool bool.true3 YeS &&
782 git config --bool bool.true4 true &&
783 git config --bool bool.false1 000 &&
784 git config --bool bool.false2 "" &&
785 git config --bool bool.false3 nO &&
786 git config --bool bool.false4 FALSE &&
787 test_cmp expect .git/config'
796 test_expect_success
'set --int' '
799 git config --int int.val1 01 &&
800 git config --int int.val2 -1 &&
801 git config --int int.val3 5m &&
802 test_cmp expect .git/config
805 test_expect_success
'get --bool-or-int' '
806 cat >.git/config <<-\EOF &&
816 cat >expect <<-\EOF &&
825 git config --bool-or-int bool.true1 &&
826 git config --bool-or-int bool.true2 &&
827 git config --bool-or-int bool.false &&
828 git config --bool-or-int int.int1 &&
829 git config --bool-or-int int.int2 &&
830 git config --bool-or-int int.int3
832 test_cmp expect actual
847 test_expect_success
'set --bool-or-int' '
849 git config --bool-or-int bool.true1 true &&
850 git config --bool-or-int bool.false1 false &&
851 git config --bool-or-int bool.true2 yes &&
852 git config --bool-or-int bool.false2 no &&
853 git config --bool-or-int int.int1 0 &&
854 git config --bool-or-int int.int2 1 &&
855 git config --bool-or-int int.int3 -1 &&
856 test_cmp expect .git/config
866 test_expect_success
!MINGW
'set --path' '
868 git config --path path.home "~/" &&
869 git config --path path.normal "/dev/null" &&
870 git config --path path.trailingtilde "foo~" &&
871 test_cmp expect .git/config'
873 if test_have_prereq
!MINGW
&& test "${HOME+set}"
875 test_set_prereq HOMEVAR
884 test_expect_success HOMEVAR
'get --path' '
885 git config --get --path path.home > result &&
886 git config --get --path path.normal >> result &&
887 git config --get --path path.trailingtilde >> result &&
888 test_cmp expect result
896 test_expect_success
!MINGW
'get --path copes with unset $HOME' '
899 test_must_fail git config --get --path path.home \
901 git config --get --path path.normal >>result &&
902 git config --get --path path.trailingtilde >>result
904 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
905 test_cmp expect result
908 test_expect_success
'get --path barfs on boolean variable' '
909 echo "[path]bool" >.git/config &&
910 test_must_fail git config --get --path path.bool
913 test_expect_success
'get --expiry-date' '
914 rel="3.weeks.5.days.00:00" &&
916 cat >.git/config <<-\EOF &&
918 valid1 = "3.weeks.5.days 00:00"
919 valid2 = "Fri Jun 4 15:46:55 2010"
920 valid3 = "2017/11/11 11:11:11PM"
921 valid4 = "2017/11/10 09:08:07 PM"
925 cat >expect <<-EOF &&
926 $(test-tool date timestamp $rel)
932 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
934 echo "$rel_out $(git config --expiry-date date.valid1)"
935 git config --expiry-date date.valid2 &&
936 git config --expiry-date date.valid3 &&
937 git config --expiry-date date.valid4 &&
938 git config --expiry-date date.valid5
940 test_cmp expect actual &&
941 test_must_fail git config --expiry-date date.invalid1
944 test_expect_success
'get --type=color' '
946 git config foo.color "red" &&
947 git config --get --type=color foo.color >actual.raw &&
948 test_decode_color <actual.raw >actual &&
949 echo "<RED>" >expect &&
950 test_cmp expect actual
958 test_expect_success
'set --type=color' '
960 git config --type=color foo.color "red" &&
961 test_cmp expect .git/config
964 test_expect_success
'get --type=color barfs on non-color' '
965 echo "[foo]bar=not-a-color" >.git/config &&
966 test_must_fail git config --get --type=color foo.bar
969 test_expect_success
'set --type=color barfs on non-color' '
970 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
971 test_i18ngrep "cannot parse color" error
978 semicolon = "test;test"
981 test_expect_success
'quoting' '
983 git config quote.leading " test" &&
984 git config quote.ending "test " &&
985 git config quote.semicolon "test;test" &&
986 git config quote.hash "test#test" &&
987 test_cmp expect .git/config
990 test_expect_success
'key with newline' '
991 test_must_fail git config "key.with
994 test_expect_success
'value with newline' 'git config key.sub value.with\\\
997 cat > .git
/config
<<\EOF
1002 noncont
= not continued
; \
1008 section.continued
=continued
1009 section.noncont
=not continued
1010 section.quotecont
=cont
;inued
1013 test_expect_success
'value continued on next line' '
1014 git config --list > result &&
1015 test_cmp expect result
1018 cat > .git
/config
<<\EOF
1019 [section
"sub=section"]
1028 section.sub
=section.val1
1029 foo
=barQsection.sub
=section.val2
1031 barQsection.sub
=section.val3
1034 Qsection.sub
=section.val4
1035 Qsection.sub
=section.val5Q
1037 test_expect_success
'--null --list' '
1038 git config --null --list >result.raw &&
1039 nul_to_q <result.raw >result &&
1041 test_cmp expect result
1044 test_expect_success
'--null --get-regexp' '
1045 git config --null --get-regexp "val[0-9]" >result.raw &&
1046 nul_to_q <result.raw >result &&
1048 test_cmp expect result
1051 test_expect_success
'inner whitespace kept verbatim' '
1052 git config section.val "foo bar" &&
1053 test_cmp_config "foo bar" section.val
1056 test_expect_success SYMLINKS
'symlinked configuration' '
1057 ln -s notyet myconfig &&
1058 git config --file=myconfig test.frotz nitfol &&
1061 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1062 git config --file=myconfig test.xyzzy rezrov &&
1065 cat >expect <<-\EOF &&
1070 git config --file=notyet test.frotz &&
1071 git config --file=notyet test.xyzzy
1073 test_cmp expect actual
1076 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
1077 ln -s doesnotexist linktonada &&
1078 ln -s linktonada linktolinktonada &&
1079 test_must_fail git config --file=linktonada --list &&
1080 test_must_fail git config --file=linktolinktonada --list
1083 test_expect_success
'check split_cmdline return' "
1084 git config alias.split-cmdline-fix 'echo \"' &&
1085 test_must_fail git split-cmdline-fix &&
1088 git commit -m 'initial commit' &&
1089 git config branch.main.mergeoptions 'echo \"' &&
1090 test_must_fail git merge main
1093 test_expect_success
'git -c "key=value" support' '
1094 cat >expect <<-\EOF &&
1100 git -c section.name=value config section.name &&
1101 git -c foo.CamelCase=value config foo.camelcase &&
1102 git -c foo.flag config --bool foo.flag
1104 test_cmp expect actual &&
1105 test_must_fail git -c name=value config section.name
1108 # We just need a type-specifier here that cares about the
1109 # distinction internally between a NULL boolean and a real
1110 # string (because most of git's internal parsers do care).
1111 # Using "--path" works, but we do not otherwise care about
1113 test_expect_success
'git -c can represent empty string' '
1115 git -c foo.empty= config --path foo.empty >actual &&
1116 test_cmp expect actual
1119 test_expect_success
'key sanity-checking' '
1120 test_must_fail git config foo=bar &&
1121 test_must_fail git config foo=.bar &&
1122 test_must_fail git config foo.ba=r &&
1123 test_must_fail git config foo.1bar &&
1124 test_must_fail git config foo."ba
1126 test_must_fail git config . false &&
1127 test_must_fail git config .foo false &&
1128 test_must_fail git config foo. false &&
1129 test_must_fail git config .foo. false &&
1130 git config foo.bar true &&
1131 git config foo."ba =z".bar false
1134 test_expect_success
'git -c works with aliases of builtins' '
1135 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1137 git checkconfig >actual &&
1138 test_cmp expect actual
1141 test_expect_success
'aliases can be CamelCased' '
1142 test_config alias.CamelCased "rev-parse HEAD" &&
1143 git CamelCased >out &&
1144 git rev-parse HEAD >expect &&
1148 test_expect_success
'git -c does not split values on equals' '
1149 echo "value with = in it" >expect &&
1150 git -c section.foo="value with = in it" config section.foo >actual &&
1151 test_cmp expect actual
1154 test_expect_success
'git -c dies on bogus config' '
1155 test_must_fail git -c core.bare=foo rev-parse
1158 test_expect_success
'git -c complains about empty key' '
1159 test_must_fail git -c "=foo" rev-parse
1162 test_expect_success
'git -c complains about empty key and value' '
1163 test_must_fail git -c "" rev-parse
1166 test_expect_success
'multiple git -c appends config' '
1167 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1168 cat >expect <<-\EOF &&
1172 git -c x.one=1 x >actual &&
1173 test_cmp expect actual
1176 test_expect_success
'last one wins: two level vars' '
1178 # sec.var and sec.VAR are the same variable, as the first
1179 # and the last level of a configuration variable name is
1184 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1185 test_cmp expect actual &&
1186 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1187 test_cmp expect actual &&
1189 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1190 test_cmp expect actual &&
1191 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1192 test_cmp expect actual
1195 test_expect_success
'last one wins: three level vars' '
1197 # v.a.r and v.A.r are not the same variable, as the middle
1198 # level of a three-level configuration variable name is
1202 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1203 test_cmp expect actual &&
1204 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1205 test_cmp expect actual &&
1207 # v.a.r and V.a.R are the same variable, as the first
1208 # and the last level of a configuration variable name is
1212 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1213 test_cmp expect actual &&
1214 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1215 test_cmp expect actual &&
1216 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1217 test_cmp expect actual &&
1218 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1219 test_cmp expect actual
1222 test_expect_success
'old-fashioned settings are case insensitive' '
1223 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1225 cat >testConfig_actual <<-EOF &&
1229 q_to_tab >testConfig_expect <<-EOF &&
1233 git config -f testConfig_actual "v.a.r" value2 &&
1234 test_cmp testConfig_expect testConfig_actual &&
1236 cat >testConfig_actual <<-EOF &&
1240 q_to_tab >testConfig_expect <<-EOF &&
1244 git config -f testConfig_actual "V.a.R" value2 &&
1245 test_cmp testConfig_expect testConfig_actual &&
1247 cat >testConfig_actual <<-EOF &&
1251 q_to_tab >testConfig_expect <<-EOF &&
1256 git config -f testConfig_actual "V.A.r" value2 &&
1257 test_cmp testConfig_expect testConfig_actual &&
1259 cat >testConfig_actual <<-EOF &&
1263 q_to_tab >testConfig_expect <<-EOF &&
1268 git config -f testConfig_actual "v.A.r" value2 &&
1269 test_cmp testConfig_expect testConfig_actual
1272 test_expect_success
'setting different case sensitive subsections ' '
1273 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1275 cat >testConfig_actual <<-EOF &&
1285 q_to_tab >testConfig_expect <<-EOF &&
1298 git config -f testConfig_actual a.b.c v2 &&
1299 # match section and subsection, key is cased differently.
1300 git config -f testConfig_actual K.E.y v2 &&
1301 # section and key are matched case insensitive, but subsection needs
1302 # to match; When writing out new values only the key is adjusted
1303 git config -f testConfig_actual v.A.r v2 &&
1304 # subsection is not matched:
1305 git config -f testConfig_actual d.E.f v2 &&
1306 test_cmp testConfig_expect testConfig_actual
1309 for VAR
in a .a a. a
.0b a.
"b c". a.
"b c".0d
1311 test_expect_success
"git -c $VAR=VAL rejects invalid '$VAR'" '
1312 test_must_fail git -c "$VAR=VAL" config -l
1316 for VAR
in a.b a.
"b c".d
1318 test_expect_success
"git -c $VAR=VAL works with valid '$VAR'" '
1320 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1321 test_cmp expect actual
1325 test_expect_success
'git -c is not confused by empty environment' '
1326 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1329 test_expect_success
'GIT_CONFIG_PARAMETERS handles old-style entries' '
1330 v="${SQ}key.one=foo${SQ}" &&
1331 v="$v ${SQ}key.two=bar${SQ}" &&
1332 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1333 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1334 cat >expect <<-EOF &&
1337 key.ambiguous section.whatever=value
1339 test_cmp expect actual
1342 test_expect_success
'GIT_CONFIG_PARAMETERS handles new-style entries' '
1343 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1344 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1345 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1346 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1347 cat >expect <<-EOF &&
1350 key.ambiguous=section.whatever value
1352 test_cmp expect actual
1355 test_expect_success
'old and new-style entries can mix' '
1356 v="${SQ}key.oldone=oldfoo${SQ}" &&
1357 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1358 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1359 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1360 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1361 cat >expect <<-EOF &&
1367 test_cmp expect actual
1370 test_expect_success
'old and new bools with ambiguous subsection' '
1371 v="${SQ}key.with=equals.oldbool${SQ}" &&
1372 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1373 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1374 cat >expect <<-EOF &&
1375 key.with equals.oldbool
1376 key.with=equals.newbool
1378 test_cmp expect actual
1381 test_expect_success
'detect bogus GIT_CONFIG_PARAMETERS' '
1382 cat >expect <<-\EOF &&
1386 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1387 git config --get-regexp "env.*" >actual &&
1388 test_cmp expect actual &&
1390 cat >expect <<-EOF &&
1394 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1395 git config --get-regexp "env.*" >actual &&
1396 test_cmp expect actual &&
1398 test_must_fail env \
1399 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1400 git config --get-regexp "env.*"
1403 test_expect_success
'git --config-env=key=envvar support' '
1404 cat >expect <<-\EOF &&
1413 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1414 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1415 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1416 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1417 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1418 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1420 test_cmp expect actual
1423 test_expect_success
'git --config-env with missing value' '
1424 test_must_fail env ENVVAR=value git --config-env 2>error &&
1425 grep "no config key given for --config-env" error &&
1426 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1427 grep "invalid config format: config" error
1430 test_expect_success
'git --config-env fails with invalid parameters' '
1431 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1432 test_i18ngrep "invalid config format: foo.flag" error &&
1433 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1434 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1435 sane_unset NONEXISTENT &&
1436 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1437 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1440 test_expect_success
'git -c and --config-env work together' '
1441 cat >expect <<-\EOF &&
1445 ENVVAR=env-value git \
1446 -c bar.cmd=cmd-value \
1447 --config-env=bar.env=ENVVAR \
1448 config --get-regexp "^bar.*" >actual &&
1449 test_cmp expect actual
1452 test_expect_success
'git -c and --config-env override each other' '
1453 cat >expect <<-\EOF &&
1458 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1459 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1461 test_cmp expect actual
1464 test_expect_success
'--config-env handles keys with equals' '
1465 echo value=with=equals >expect &&
1466 ENVVAR=value=with=equals git \
1467 --config-env=section.subsection=with=equals.key=ENVVAR \
1468 config section.subsection=with=equals.key >actual &&
1469 test_cmp expect actual
1472 test_expect_success
'git config handles environment config pairs' '
1473 GIT_CONFIG_COUNT=2 \
1474 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1475 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1476 git config --get-regexp "pair.*" >actual &&
1477 cat >expect <<-EOF &&
1481 test_cmp expect actual
1484 test_expect_success
'git config ignores pairs without count' '
1485 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1486 git config pair.one 2>error &&
1487 test_must_be_empty error
1490 test_expect_success
'git config ignores pairs with zero count' '
1491 test_must_fail env \
1492 GIT_CONFIG_COUNT=0 \
1493 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1497 test_expect_success
'git config ignores pairs exceeding count' '
1498 GIT_CONFIG_COUNT=1 \
1499 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1500 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1501 git config --get-regexp "pair.*" >actual &&
1502 cat >expect <<-EOF &&
1505 test_cmp expect actual
1508 test_expect_success
'git config ignores pairs with zero count' '
1509 test_must_fail env \
1510 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1511 git config pair.one >error &&
1512 test_must_be_empty error
1515 test_expect_success
'git config ignores pairs with empty count' '
1516 test_must_fail env \
1517 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1518 git config pair.one >error &&
1519 test_must_be_empty error
1522 test_expect_success
'git config fails with invalid count' '
1523 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1524 test_i18ngrep "bogus count" error &&
1525 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1526 test_i18ngrep "too many entries" error
1529 test_expect_success
'git config fails with missing config key' '
1530 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1531 git config --list 2>error &&
1532 test_i18ngrep "missing config key" error
1535 test_expect_success
'git config fails with missing config value' '
1536 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1537 git config --list 2>error &&
1538 test_i18ngrep "missing config value" error
1541 test_expect_success
'git config fails with invalid config pair key' '
1542 test_must_fail env GIT_CONFIG_COUNT=1 \
1543 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1544 git config --list &&
1545 test_must_fail env GIT_CONFIG_COUNT=1 \
1546 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1550 test_expect_success
'environment overrides config file' '
1551 test_when_finished "rm -f .git/config" &&
1552 cat >.git/config <<-EOF &&
1556 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1557 git config pair.one >actual &&
1558 cat >expect <<-EOF &&
1561 test_cmp expect actual
1564 test_expect_success
'GIT_CONFIG_PARAMETERS overrides environment config' '
1565 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1566 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1567 git config pair.one >actual &&
1568 cat >expect <<-EOF &&
1571 test_cmp expect actual
1574 test_expect_success
'command line overrides environment config' '
1575 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1576 git -c pair.one=override config pair.one >actual &&
1577 cat >expect <<-EOF &&
1580 test_cmp expect actual
1583 test_expect_success
'git config --edit works' '
1584 git config -f tmp test.value no &&
1585 echo test.value=yes >expect &&
1586 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1587 git config -f tmp --list >actual &&
1588 test_cmp expect actual
1591 test_expect_success
'git config --edit respects core.editor' '
1592 git config -f tmp test.value no &&
1593 echo test.value=yes >expect &&
1594 test_config core.editor "echo [test]value=yes >" &&
1595 git config -f tmp --edit &&
1596 git config -f tmp --list >actual &&
1597 test_cmp expect actual
1600 # malformed configuration files
1601 test_expect_success
'barf on syntax error' '
1602 cat >.git/config <<-\EOF &&
1603 # broken section line
1607 test_must_fail git config --get section.key >actual 2>error &&
1608 test_i18ngrep " line 3 " error
1611 test_expect_success
'barf on incomplete section header' '
1612 cat >.git/config <<-\EOF &&
1613 # broken section line
1617 test_must_fail git config --get section.key >actual 2>error &&
1618 test_i18ngrep " line 2 " error
1621 test_expect_success
'barf on incomplete string' '
1622 cat >.git/config <<-\EOF &&
1623 # broken section line
1627 test_must_fail git config --get section.key >actual 2>error &&
1628 test_i18ngrep " line 3 " error
1631 test_expect_success
'urlmatch' '
1632 cat >.git/config <<-\EOF &&
1635 [http "https://weak.example.com"]
1637 cookieFile = /tmp/cookie.txt
1640 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1641 test_must_be_empty actual &&
1643 echo true >expect &&
1644 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1645 test_cmp expect actual &&
1647 echo false >expect &&
1648 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1649 test_cmp expect actual &&
1652 echo http.cookiefile /tmp/cookie.txt &&
1653 echo http.sslverify false
1655 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1656 test_cmp expect actual
1659 test_expect_success
'urlmatch favors more specific URLs' '
1660 cat >.git/config <<-\EOF &&
1661 [http "https://example.com/"]
1662 cookieFile = /tmp/root.txt
1663 [http "https://example.com/subdirectory"]
1664 cookieFile = /tmp/subdirectory.txt
1665 [http "https://user@example.com/"]
1666 cookieFile = /tmp/user.txt
1667 [http "https://averylonguser@example.com/"]
1668 cookieFile = /tmp/averylonguser.txt
1669 [http "https://preceding.example.com"]
1670 cookieFile = /tmp/preceding.txt
1671 [http "https://*.example.com"]
1672 cookieFile = /tmp/wildcard.txt
1673 [http "https://*.example.com/wildcardwithsubdomain"]
1674 cookieFile = /tmp/wildcardwithsubdomain.txt
1675 [http "https://*.example.*"]
1676 cookieFile = /tmp/multiwildcard.txt
1677 [http "https://trailing.example.com"]
1678 cookieFile = /tmp/trailing.txt
1679 [http "https://user@*.example.com/"]
1680 cookieFile = /tmp/wildcardwithuser.txt
1681 [http "https://sub.example.com/"]
1682 cookieFile = /tmp/sub.txt
1685 echo http.cookiefile /tmp/root.txt >expect &&
1686 git config --get-urlmatch HTTP https://example.com >actual &&
1687 test_cmp expect actual &&
1689 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1690 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1691 test_cmp expect actual &&
1693 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1694 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1695 test_cmp expect actual &&
1697 echo http.cookiefile /tmp/user.txt >expect &&
1698 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1699 test_cmp expect actual &&
1701 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1702 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1703 test_cmp expect actual &&
1705 echo http.cookiefile /tmp/preceding.txt >expect &&
1706 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1707 test_cmp expect actual &&
1709 echo http.cookiefile /tmp/wildcard.txt >expect &&
1710 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1711 test_cmp expect actual &&
1713 echo http.cookiefile /tmp/sub.txt >expect &&
1714 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1715 test_cmp expect actual &&
1717 echo http.cookiefile /tmp/trailing.txt >expect &&
1718 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1719 test_cmp expect actual &&
1721 echo http.cookiefile /tmp/sub.txt >expect &&
1722 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1723 test_cmp expect actual &&
1725 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1726 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1727 test_cmp expect actual
1730 test_expect_success
'urlmatch with wildcard' '
1731 cat >.git/config <<-\EOF &&
1734 [http "https://*.example.com"]
1736 cookieFile = /tmp/cookie.txt
1739 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1740 test_must_be_empty actual &&
1742 echo true >expect &&
1743 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1744 test_cmp expect actual &&
1746 echo true >expect &&
1747 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1748 test_cmp expect actual &&
1750 echo true >expect &&
1751 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1752 test_cmp expect actual &&
1754 echo false >expect &&
1755 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1756 test_cmp expect actual &&
1759 echo http.cookiefile /tmp/cookie.txt &&
1760 echo http.sslverify false
1762 git config --get-urlmatch HTTP https://good.example.com >actual &&
1763 test_cmp expect actual &&
1765 echo http.sslverify >expect &&
1766 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1767 test_cmp expect actual
1770 # good section hygiene
1771 test_expect_success
'--unset last key removes section (except if commented)' '
1772 cat >.git/config <<-\EOF &&
1773 # some generic comment on the configuration file itself
1774 # a comment specific to this "section" section.
1776 # some intervening lines
1777 # that should also be dropped
1780 # please be careful when you update the above variable
1783 cat >expect <<-\EOF &&
1784 # some generic comment on the configuration file itself
1785 # a comment specific to this "section" section.
1787 # some intervening lines
1788 # that should also be dropped
1790 # please be careful when you update the above variable
1793 git config --unset section.key &&
1794 test_cmp expect .git/config &&
1796 cat >.git/config <<-\EOF &&
1802 cat >expect <<-\EOF &&
1806 git config --unset section.key &&
1807 test_cmp expect .git/config &&
1809 q_to_tab >.git/config <<-\EOF &&
1816 git config --unset two.key &&
1817 ! grep two .git/config &&
1819 q_to_tab >.git/config <<-\EOF &&
1826 git config --unset-all one.key &&
1827 test_line_count = 0 .git/config &&
1829 q_to_tab >.git/config <<-\EOF &&
1832 Q# a comment not at the start
1836 git config --unset two.key &&
1837 grep two .git/config &&
1839 q_to_tab >.git/config <<-\EOF &&
1841 Qkey = not [two "subsection"]
1848 git config --unset two.subsection.key &&
1849 test "not [two subsection]" = "$(git config one.key)" &&
1850 test_line_count = 3 .git/config
1853 test_expect_success
'--unset-all removes section if empty & uncommented' '
1854 cat >.git/config <<-\EOF &&
1860 git config --unset-all section.key &&
1861 test_line_count = 0 .git/config
1864 test_expect_success
'adding a key into an empty section reuses header' '
1865 cat >.git/config <<-\EOF &&
1869 q_to_tab >expect <<-\EOF &&
1874 git config section.key value &&
1875 test_cmp expect .git/config
1878 test_expect_success POSIXPERM
,PERL
'preserves existing permissions' '
1879 chmod 0600 .git/config &&
1880 git config imap.pass Hunter2 &&
1882 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1883 git config --rename-section imap pop &&
1885 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1888 ! test_have_prereq MINGW ||
1889 HOME
="$(pwd)" # convert to Windows path
1891 test_expect_success
'set up --show-origin tests' '
1892 INCLUDE_DIR="$HOME/include" &&
1893 mkdir -p "$INCLUDE_DIR" &&
1894 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1898 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1902 cat >"$HOME"/.gitconfig <<-EOF &&
1907 path = "$INCLUDE_DIR/absolute.include"
1909 cat >.git/config <<-\EOF
1914 path = ../include/relative.include
1918 test_expect_success
'--show-origin with --list' '
1919 cat >expect <<-EOF &&
1920 file:$HOME/.gitconfig user.global=true
1921 file:$HOME/.gitconfig user.override=global
1922 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1923 file:$INCLUDE_DIR/absolute.include user.absolute=include
1924 file:.git/config user.local=true
1925 file:.git/config user.override=local
1926 file:.git/config include.path=../include/relative.include
1927 file:.git/../include/relative.include user.relative=include
1928 command line: user.environ=true
1929 command line: user.cmdline=true
1931 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1932 git -c user.cmdline=true config --list --show-origin >output &&
1933 test_cmp expect output
1936 test_expect_success
'--show-origin with --list --null' '
1937 cat >expect <<-EOF &&
1938 file:$HOME/.gitconfigQuser.global
1939 trueQfile:$HOME/.gitconfigQuser.override
1940 globalQfile:$HOME/.gitconfigQinclude.path
1941 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1942 includeQfile:.git/configQuser.local
1943 trueQfile:.git/configQuser.override
1944 localQfile:.git/configQinclude.path
1945 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1946 includeQcommand line:Quser.cmdline
1949 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1950 nul_to_q <output.raw >output &&
1951 # The here-doc above adds a newline that the --null output would not
1952 # include. Add it here to make the two comparable.
1954 test_cmp expect output
1957 test_expect_success
'--show-origin with single file' '
1958 cat >expect <<-\EOF &&
1959 file:.git/config user.local=true
1960 file:.git/config user.override=local
1961 file:.git/config include.path=../include/relative.include
1963 git config --local --list --show-origin >output &&
1964 test_cmp expect output
1967 test_expect_success
'--show-origin with --get-regexp' '
1968 cat >expect <<-EOF &&
1969 file:$HOME/.gitconfig user.global true
1970 file:.git/config user.local true
1972 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1973 test_cmp expect output
1976 test_expect_success
'--show-origin getting a single key' '
1977 cat >expect <<-\EOF &&
1978 file:.git/config local
1980 git config --show-origin user.override >output &&
1981 test_cmp expect output
1984 test_expect_success
'set up custom config file' '
1985 CUSTOM_CONFIG_FILE="custom.conf" &&
1986 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1992 test_expect_success
!MINGW
'set up custom config file with special name characters' '
1993 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
1994 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
1997 test_expect_success
!MINGW
'--show-origin escape special file name characters' '
1998 cat >expect <<-\EOF &&
1999 file:"file\" (dq) and spaces.conf" user.custom=true
2001 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2002 test_cmp expect output
2005 test_expect_success
'--show-origin stdin' '
2006 cat >expect <<-\EOF &&
2007 standard input: user.custom=true
2009 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2010 test_cmp expect output
2013 test_expect_success
'--show-origin stdin with file include' '
2014 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2018 cat >expect <<-EOF &&
2019 file:$INCLUDE_DIR/stdin.include include
2021 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2022 git config --show-origin --includes --file - user.stdin >output &&
2024 test_cmp expect output
2027 test_expect_success
'--show-origin blob' '
2028 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2029 cat >expect <<-EOF &&
2030 blob:$blob user.custom=true
2032 git config --blob=$blob --show-origin --list >output &&
2033 test_cmp expect output
2036 test_expect_success
'--show-origin blob ref' '
2037 cat >expect <<-\EOF &&
2038 blob:main:custom.conf user.custom=true
2040 git add "$CUSTOM_CONFIG_FILE" &&
2041 git commit -m "new config file" &&
2042 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2043 test_cmp expect output
2046 test_expect_success
'--show-scope with --list' '
2047 cat >expect <<-EOF &&
2048 global user.global=true
2049 global user.override=global
2050 global include.path=$INCLUDE_DIR/absolute.include
2051 global user.absolute=include
2052 local user.local=true
2053 local user.override=local
2054 local include.path=../include/relative.include
2055 local user.relative=include
2056 command user.cmdline=true
2058 git -c user.cmdline=true config --list --show-scope >output &&
2059 test_cmp expect output
2062 test_expect_success
!MINGW
'--show-scope with --blob' '
2063 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2064 cat >expect <<-EOF &&
2065 command user.custom=true
2067 git config --blob=$blob --show-scope --list >output &&
2068 test_cmp expect output
2071 test_expect_success
'--show-scope with --local' '
2072 cat >expect <<-\EOF &&
2073 local user.local=true
2074 local user.override=local
2075 local include.path=../include/relative.include
2077 git config --local --list --show-scope >output &&
2078 test_cmp expect output
2081 test_expect_success
'--show-scope getting a single value' '
2082 cat >expect <<-\EOF &&
2085 git config --show-scope --get user.local >output &&
2086 test_cmp expect output
2089 test_expect_success
'--show-scope with --show-origin' '
2090 cat >expect <<-EOF &&
2091 global file:$HOME/.gitconfig user.global=true
2092 global file:$HOME/.gitconfig user.override=global
2093 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2094 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2095 local file:.git/config user.local=true
2096 local file:.git/config user.override=local
2097 local file:.git/config include.path=../include/relative.include
2098 local file:.git/../include/relative.include user.relative=include
2099 command command line: user.cmdline=true
2101 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2102 test_cmp expect output
2105 test_expect_success
'override global and system config' '
2106 test_when_finished rm -f "$HOME"/.config/git &&
2108 cat >"$HOME"/.gitconfig <<-EOF &&
2112 mkdir -p "$HOME"/.config/git &&
2113 cat >"$HOME"/.config/git/config <<-EOF &&
2117 cat >.git/config <<-EOF &&
2121 cat >custom-global-config <<-EOF &&
2125 cat >custom-system-config <<-EOF &&
2130 cat >expect <<-EOF &&
2131 global xdg.config=true
2132 global home.config=true
2133 local local.config=true
2135 git config --show-scope --list >output &&
2136 test_cmp expect output &&
2138 cat >expect <<-EOF &&
2139 system system.config=true
2140 global global.config=true
2141 local local.config=true
2143 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2144 git config --show-scope --list >output &&
2145 test_cmp expect output &&
2147 cat >expect <<-EOF &&
2148 local local.config=true
2150 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2151 git config --show-scope --list >output &&
2152 test_cmp expect output
2155 test_expect_success
'override global and system config with missing file' '
2156 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2157 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2158 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2161 test_expect_success
'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2162 # `git config --system` has different semantics compared to other
2163 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2164 # variable has an effect via a different proxy.
2165 cat >alias-config <<-EOF &&
2167 hello-world = !echo "hello world"
2169 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2171 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2172 git hello-world >actual &&
2173 echo "hello world" >expect &&
2174 test_cmp expect actual
2177 test_expect_success
'write to overridden global and system config' '
2178 cat >expect <<EOF &&
2183 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2184 test_cmp expect write-to-global &&
2186 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2187 test_cmp expect write-to-system
2190 for opt
in --local --worktree
2192 test_expect_success
"$opt requires a repo" '
2193 # we expect 128 to ensure that we do not simply
2194 # fail to find anything and return code "1"
2195 test_expect_code 128 nongit git config $opt foo.bar
2199 cat >.git
/config
<<-\EOF &&
2206 test_expect_success 'identical modern --type specifiers are allowed' '
2207 test_cmp_config 1048576 --type=int --type=int section.big
2210 test_expect_success 'identical legacy --type specifiers are allowed' '
2211 test_cmp_config 1048576 --int --int section.big
2214 test_expect_success 'identical mixed --type specifiers are allowed' '
2215 test_cmp_config 1048576 --int --type=int section.big
2218 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2219 test_must_fail git config --type=int --type=bool section.big 2>error &&
2220 test_i18ngrep "only one type at a time" error
2223 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2224 test_must_fail git config --int --bool section.big 2>error &&
2225 test_i18ngrep "only one type at a time" error
2228 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2229 test_must_fail git config --type=int --bool section.big 2>error &&
2230 test_i18ngrep "only one type at a time" error
2233 test_expect_success '--type allows valid type specifiers' '
2234 test_cmp_config true --type=bool section.foo
2237 test_expect_success '--no-type unsets type specifiers' '
2238 test_cmp_config 10 --type=bool --no-type section.number
2241 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2242 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2245 test_expect_success '--type rejects unknown specifiers' '
2246 test_must_fail git config --type=nonsense section.foo 2>error &&
2247 test_i18ngrep "unrecognized --type argument" error
2250 test_expect_success '--replace-all does not invent newlines' '
2251 q_to_tab >.git/config <<-\
EOF &&
2259 q_to_tab >expect <<-\EOF &&
2267 git config --replace-all abc.key b &&
2268 test_cmp expect .git/config
2271 test_expect_success 'set all config with value-pattern' '
2272 test_when_finished rm -f config initial &&
2273 git config --file=initial abc.key one &&
2275 # no match => add new entry
2276 cp initial config &&
2277 git config --file=config abc.key two a+ &&
2278 git config --file=config --list >actual &&
2279 cat >expect <<-\EOF &&
2283 test_cmp expect actual &&
2285 # multiple matches => failure
2286 test_must_fail git config --file=config abc.key three o+ 2>err &&
2287 test_i18ngrep "has multiple values" err &&
2289 # multiple values, no match => add
2290 git config --file=config abc.key three a+ &&
2291 git config --file=config --list >actual &&
2292 cat >expect <<-\EOF &&
2297 test_cmp expect actual &&
2299 # single match => replace
2300 git config --file=config abc.key four h+ &&
2301 git config --file=config --list >actual &&
2302 cat >expect <<-\EOF &&
2307 test_cmp expect actual
2310 test_expect_success '--replace-all and value-pattern' '
2311 test_when_finished rm -f config &&
2312 git config --file=config --add abc.key one &&
2313 git config --file=config --add abc.key two &&
2314 git config --file=config --add abc.key three &&
2315 git config --file=config --replace-all abc.key four "o+" &&
2316 git config --file=config --list >actual &&
2317 cat >expect <<-\EOF &&
2321 test_cmp expect actual
2324 test_expect_success 'refuse --fixed-value for incompatible actions' '
2325 test_when_finished rm -f config &&
2326 git config --file=config dev.null bogus &&
2328 # These modes do not allow --fixed-value at all
2329 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2330 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2331 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2332 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2333 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2334 test_must_fail git config --file=config --fixed-value --list &&
2335 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2336 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2338 # These modes complain when --fixed-value has no value-pattern
2339 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2340 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2341 test_must_fail git config --file=config --fixed-value --get dev.null &&
2342 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2343 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2344 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2345 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2348 test_expect_success '--fixed-value uses exact string matching' '
2349 test_when_finished rm -f config initial &&
2350 META="a+b*c?d[e]f.g" &&
2351 git config --file=initial fixed.test "$META" &&
2353 cp initial config &&
2354 git config --file=config fixed.test bogus "$META" &&
2355 git config --file=config --list >actual &&
2356 cat >expect <<-EOF &&
2360 test_cmp expect actual &&
2362 cp initial config &&
2363 git config --file=config --fixed-value fixed.test bogus "$META" &&
2364 git config --file=config --list >actual &&
2365 cat >expect <<-\EOF &&
2368 test_cmp expect actual &&
2370 cp initial config &&
2371 test_must_fail git config --file=config --unset fixed.test "$META" &&
2372 git config --file=config --fixed-value --unset fixed.test "$META" &&
2373 test_must_fail git config --file=config fixed.test &&
2375 cp initial config &&
2376 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2377 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2378 test_must_fail git config --file=config fixed.test &&
2380 cp initial config &&
2381 git config --file=config --replace-all fixed.test bogus "$META" &&
2382 git config --file=config --list >actual &&
2383 cat >expect <<-EOF &&
2387 test_cmp expect actual &&
2389 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2390 git config --file=config --list >actual &&
2391 cat >expect <<-EOF &&
2395 test_cmp expect actual
2398 test_expect_success '--get and --get-all with --fixed-value' '
2399 test_when_finished rm -f config &&
2400 META="a+b*c?d[e]f.g" &&
2401 git config --file=config fixed.test bogus &&
2402 git config --file=config --add fixed.test "$META" &&
2404 git config --file=config --get fixed.test bogus &&
2405 test_must_fail git config --file=config --get fixed.test "$META" &&
2406 git config --file=config --get --fixed-value fixed.test "$META" &&
2407 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2409 git config --file=config --get-all fixed.test bogus &&
2410 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2411 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2412 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2414 git config --file=config --get-regexp fixed+ bogus &&
2415 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2416 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2417 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent