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 cat > .git
/config
<<\EOF
110 test_expect_success
'unset with cont. lines' '
111 git config --unset beta.baz
121 test_expect_success
'unset with cont. lines is correct' 'test_cmp expect .git/config'
123 cat > .git
/config
<< EOF
124 [beta] ; silly comment # another comment
125 noIndent= sillyValue ; 'nother silly comment
129 haha ="beta" # last silly comment
132 [nextSection] noNewline = ouch
135 cp .git
/config .git
/config2
137 test_expect_success
'multiple unset' '
138 git config --unset-all beta.haha
142 [beta] ; silly comment # another comment
143 noIndent= sillyValue ; 'nother silly comment
147 [nextSection] noNewline = ouch
150 test_expect_success
'multiple unset is correct' '
151 test_cmp expect .git/config
154 cp .git
/config2 .git
/config
156 test_expect_success
'--replace-all missing value' '
157 test_must_fail git config --replace-all beta.haha &&
158 test_cmp .git/config2 .git/config
163 test_expect_success
'--replace-all' '
164 git config --replace-all beta.haha gamma
168 [beta] ; silly comment # another comment
169 noIndent= sillyValue ; 'nother silly comment
174 [nextSection] noNewline = ouch
177 test_expect_success
'all replaced' '
178 test_cmp expect .git/config
182 [beta] ; silly comment # another comment
183 noIndent= sillyValue ; 'nother silly comment
188 [nextSection] noNewline = ouch
190 test_expect_success
'really mean test' '
191 git config beta.haha alpha &&
192 test_cmp expect .git/config
196 [beta] ; silly comment # another comment
197 noIndent= sillyValue ; 'nother silly comment
205 test_expect_success
'really really mean test' '
206 git config nextsection.nonewline wow &&
207 test_cmp expect .git/config
210 test_expect_success
'get value' '
211 test_cmp_config alpha beta.haha
215 [beta] ; silly comment # another comment
216 noIndent= sillyValue ; 'nother silly comment
223 test_expect_success
'unset' '
224 git config --unset beta.haha &&
225 test_cmp expect .git/config
229 [beta] ; silly comment # another comment
230 noIndent= sillyValue ; 'nother silly comment
236 NoNewLine = wow2 for me
238 test_expect_success
'multivar' '
239 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
240 test_cmp expect .git/config
243 test_expect_success
'non-match' '
244 git config --get nextsection.nonewline !for
247 test_expect_success
'non-match value' '
248 test_cmp_config wow --get nextsection.nonewline !for
251 test_expect_success
'multi-valued get returns final one' '
252 test_cmp_config "wow2 for me" --get nextsection.nonewline
255 test_expect_success
'multi-valued get-all returns all' '
256 cat >expect <<-\EOF &&
260 git config --get-all nextsection.nonewline >actual &&
261 test_cmp expect actual
265 [beta] ; silly comment # another comment
266 noIndent= sillyValue ; 'nother silly comment
272 NoNewLine = wow2 for me
274 test_expect_success
'multivar replace' '
275 git config nextsection.nonewline "wow3" "wow$" &&
276 test_cmp expect .git/config
279 test_expect_success
'ambiguous unset' '
280 test_must_fail git config --unset nextsection.nonewline
283 test_expect_success
'invalid unset' '
284 test_must_fail git config --unset somesection.nonewline
288 [beta] ; silly comment # another comment
289 noIndent= sillyValue ; 'nother silly comment
294 NoNewLine = wow2 for me
297 test_expect_success
'multivar unset' '
298 git config --unset nextsection.nonewline "wow3$" &&
299 test_cmp expect .git/config
302 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
304 test_expect_success
'correct key' 'git config 123456.a123 987'
306 test_expect_success
'hierarchical section' '
307 git config Version.1.2.3eX.Alpha beta
311 [beta] ; silly comment # another comment
312 noIndent= sillyValue ; 'nother silly comment
317 NoNewLine = wow2 for me
324 test_expect_success
'hierarchical section value' '
325 test_cmp expect .git/config
329 beta.noindent=sillyValue
330 nextsection.nonewline=wow2 for me
332 version.1.2.3eX.alpha=beta
335 test_expect_success
'working --list' '
336 git config --list > output &&
337 test_cmp expect output
339 test_expect_success
'--list without repo produces empty output' '
340 git --git-dir=nonexistent config --list >output &&
341 test_must_be_empty output
346 nextsection.nonewline
348 version.1.2.3eX.alpha
351 test_expect_success
'--name-only --list' '
352 git config --name-only --list >output &&
353 test_cmp expect output
357 beta.noindent sillyValue
358 nextsection.nonewline wow2 for me
361 test_expect_success
'--get-regexp' '
362 git config --get-regexp in >output &&
363 test_cmp expect output
368 nextsection.nonewline
371 test_expect_success
'--name-only --get-regexp' '
372 git config --name-only --get-regexp in >output &&
373 test_cmp expect output
381 test_expect_success
'--add' '
382 git config --add nextsection.nonewline "wow4 for you" &&
383 git config --get-all nextsection.nonewline > output &&
384 test_cmp expect output
387 cat > .git
/config
<< EOF
394 test_expect_success
'get variable with no value' '
395 git config --get novalue.variable ^$
398 test_expect_success
'get variable with empty value' '
399 git config --get emptyvalue.variable ^$
402 echo novalue.variable
> expect
404 test_expect_success
'get-regexp variable with no value' '
405 git config --get-regexp novalue > output &&
406 test_cmp expect output
409 echo 'novalue.variable true' > expect
411 test_expect_success
'get-regexp --bool variable with no value' '
412 git config --bool --get-regexp novalue > output &&
413 test_cmp expect output
416 echo 'emptyvalue.variable ' > expect
418 test_expect_success
'get-regexp variable with empty value' '
419 git config --get-regexp emptyvalue > output &&
420 test_cmp expect output
425 test_expect_success
'get bool variable with no value' '
426 git config --bool novalue.variable > output &&
427 test_cmp expect output
432 test_expect_success
'get bool variable with empty value' '
433 git config --bool emptyvalue.variable > output &&
434 test_cmp expect output
437 test_expect_success
'no arguments, but no crash' '
438 test_must_fail git config >output 2>&1 &&
439 test_i18ngrep usage output
442 cat > .git
/config
<< EOF
454 test_expect_success
'new section is partial match of another' '
456 test_cmp expect .git/config
469 test_expect_success
'new variable inserts into proper section' '
472 test_cmp expect .git/config
475 test_expect_success
'alternative --file (non-existing file should fail)' '
476 test_must_fail git config --file non-existing-config -l &&
477 test_must_fail git config --file non-existing-config test.xyzzy
480 cat > other-config
<< EOF
489 test_expect_success
'alternative GIT_CONFIG' '
490 GIT_CONFIG=other-config git config --list >output &&
491 test_cmp expect output
494 test_expect_success
'alternative GIT_CONFIG (--file)' '
495 git config --file other-config --list >output &&
496 test_cmp expect output
499 test_expect_success
'alternative GIT_CONFIG (--file=-)' '
500 git config --file - --list <other-config >output &&
501 test_cmp expect output
504 test_expect_success
'setting a value in stdin is an error' '
505 test_must_fail git config --file - some.value foo
508 test_expect_success
'editing stdin is an error' '
509 test_must_fail git config --file - --edit
512 test_expect_success
'refer config from subdirectory' '
514 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
524 test_expect_success
'--set in alternative file' '
525 git config --file=other-config anwohner.park ausweis &&
526 test_cmp expect other-config
529 cat > .git
/config
<< EOF
536 [branch "1 234 blabl/a"]
540 test_expect_success
'rename section' '
541 git config --rename-section branch.eins branch.zwei
551 [branch "1 234 blabl/a"]
555 test_expect_success
'rename succeeded' '
556 test_cmp expect .git/config
559 test_expect_success
'rename non-existing section' '
560 test_must_fail git config --rename-section \
561 branch."world domination" branch.drei
564 test_expect_success
'rename succeeded' '
565 test_cmp expect .git/config
568 test_expect_success
'rename another section' '
569 git config --rename-section branch."1 234 blabl/a" branch.drei
583 test_expect_success
'rename succeeded' '
584 test_cmp expect .git/config
587 cat >> .git
/config
<< EOF
588 [branch "vier"] z = 1
591 test_expect_success
'rename a section with a var on the same line' '
592 git config --rename-section branch.vier branch.zwei
608 test_expect_success
'rename succeeded' '
609 test_cmp expect .git/config
612 test_expect_success
'renaming empty section name is rejected' '
613 test_must_fail git config --rename-section branch.zwei ""
616 test_expect_success
'renaming to bogus section is rejected' '
617 test_must_fail git config --rename-section branch.zwei "bogus name"
620 cat >> .git
/config
<< EOF
621 [branch "zwei"] a = 1 [branch "vier"]
624 test_expect_success
'remove section' '
625 git config --remove-section branch.zwei
635 test_expect_success
'section was removed properly' '
636 test_cmp expect .git/config
642 dbname = %Ggitcvs2.%a.%m.sqlite
644 dbname = %Ggitcvs1.%a.%m.sqlite
647 test_expect_success
'section ending' '
649 git config gitcvs.enabled true &&
650 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
651 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
652 test_cmp expect .git/config
656 test_expect_success numbers
'
657 git config kilo.gram 1k &&
658 git config mega.ton 1m &&
660 echo 1048576 >>expect &&
661 git config --int --get kilo.gram >actual &&
662 git config --int --get mega.ton >>actual &&
663 test_cmp expect actual
666 test_expect_success
'--int is at least 64 bits' '
667 git config giga.watts 121g &&
669 test_cmp_config 129922760704 --int --get giga.watts
672 test_expect_success
'invalid unit' '
673 git config aninvalid.unit "1auto" &&
674 test_cmp_config 1auto aninvalid.unit &&
675 test_must_fail git config --int --get aninvalid.unit 2>actual &&
676 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
679 test_expect_success
'invalid unit boolean' '
680 git config commit.gpgsign "1true" &&
681 test_cmp_config 1true commit.gpgsign &&
682 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
683 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
686 test_expect_success
'line number is reported correctly' '
687 printf "[bool]\n\tvar\n" >invalid &&
688 test_must_fail git config -f invalid --path bool.var 2>actual &&
689 test_i18ngrep "line 2" actual
692 test_expect_success
'invalid stdin config' '
693 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
694 test_i18ngrep "bad config line 1 in standard input" output
708 test_expect_success bool
'
710 git config bool.true1 01 &&
711 git config bool.true2 -1 &&
712 git config bool.true3 YeS &&
713 git config bool.true4 true &&
714 git config bool.false1 000 &&
715 git config bool.false2 "" &&
716 git config bool.false3 nO &&
717 git config bool.false4 FALSE &&
721 git config --bool --get bool.true$i >>result &&
722 git config --bool --get bool.false$i >>result || return 1
724 test_cmp expect result'
726 test_expect_success
'invalid bool (--get)' '
728 git config bool.nobool foobar &&
729 test_must_fail git config --bool --get bool.nobool'
731 test_expect_success
'invalid bool (set)' '
733 test_must_fail git config --bool bool.nobool foobar'
747 test_expect_success
'set --bool' '
750 git config --bool bool.true1 01 &&
751 git config --bool bool.true2 -1 &&
752 git config --bool bool.true3 YeS &&
753 git config --bool bool.true4 true &&
754 git config --bool bool.false1 000 &&
755 git config --bool bool.false2 "" &&
756 git config --bool bool.false3 nO &&
757 git config --bool bool.false4 FALSE &&
758 test_cmp expect .git/config'
767 test_expect_success
'set --int' '
770 git config --int int.val1 01 &&
771 git config --int int.val2 -1 &&
772 git config --int int.val3 5m &&
773 test_cmp expect .git/config
776 test_expect_success
'get --bool-or-int' '
777 cat >.git/config <<-\EOF &&
787 cat >expect <<-\EOF &&
796 git config --bool-or-int bool.true1 &&
797 git config --bool-or-int bool.true2 &&
798 git config --bool-or-int bool.false &&
799 git config --bool-or-int int.int1 &&
800 git config --bool-or-int int.int2 &&
801 git config --bool-or-int int.int3
803 test_cmp expect actual
818 test_expect_success
'set --bool-or-int' '
820 git config --bool-or-int bool.true1 true &&
821 git config --bool-or-int bool.false1 false &&
822 git config --bool-or-int bool.true2 yes &&
823 git config --bool-or-int bool.false2 no &&
824 git config --bool-or-int int.int1 0 &&
825 git config --bool-or-int int.int2 1 &&
826 git config --bool-or-int int.int3 -1 &&
827 test_cmp expect .git/config
837 test_expect_success
!MINGW
'set --path' '
839 git config --path path.home "~/" &&
840 git config --path path.normal "/dev/null" &&
841 git config --path path.trailingtilde "foo~" &&
842 test_cmp expect .git/config'
844 if test_have_prereq
!MINGW
&& test "${HOME+set}"
846 test_set_prereq HOMEVAR
855 test_expect_success HOMEVAR
'get --path' '
856 git config --get --path path.home > result &&
857 git config --get --path path.normal >> result &&
858 git config --get --path path.trailingtilde >> result &&
859 test_cmp expect result
867 test_expect_success
!MINGW
'get --path copes with unset $HOME' '
870 test_must_fail git config --get --path path.home \
872 git config --get --path path.normal >>result &&
873 git config --get --path path.trailingtilde >>result
875 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
876 test_cmp expect result
879 test_expect_success
'get --path barfs on boolean variable' '
880 echo "[path]bool" >.git/config &&
881 test_must_fail git config --get --path path.bool
884 test_expect_success
'get --expiry-date' '
885 rel="3.weeks.5.days.00:00" &&
887 cat >.git/config <<-\EOF &&
889 valid1 = "3.weeks.5.days 00:00"
890 valid2 = "Fri Jun 4 15:46:55 2010"
891 valid3 = "2017/11/11 11:11:11PM"
892 valid4 = "2017/11/10 09:08:07 PM"
896 cat >expect <<-EOF &&
897 $(test-tool date timestamp $rel)
903 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
905 echo "$rel_out $(git config --expiry-date date.valid1)" &&
906 git config --expiry-date date.valid2 &&
907 git config --expiry-date date.valid3 &&
908 git config --expiry-date date.valid4 &&
909 git config --expiry-date date.valid5
911 test_cmp expect actual &&
912 test_must_fail git config --expiry-date date.invalid1
915 test_expect_success
'get --type=color' '
917 git config foo.color "red" &&
918 git config --get --type=color foo.color >actual.raw &&
919 test_decode_color <actual.raw >actual &&
920 echo "<RED>" >expect &&
921 test_cmp expect actual
929 test_expect_success
'set --type=color' '
931 git config --type=color foo.color "red" &&
932 test_cmp expect .git/config
935 test_expect_success
'get --type=color barfs on non-color' '
936 echo "[foo]bar=not-a-color" >.git/config &&
937 test_must_fail git config --get --type=color foo.bar
940 test_expect_success
'set --type=color barfs on non-color' '
941 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
942 test_i18ngrep "cannot parse color" error
949 semicolon = "test;test"
952 test_expect_success
'quoting' '
954 git config quote.leading " test" &&
955 git config quote.ending "test " &&
956 git config quote.semicolon "test;test" &&
957 git config quote.hash "test#test" &&
958 test_cmp expect .git/config
961 test_expect_success
'key with newline' '
962 test_must_fail git config "key.with
965 test_expect_success
'value with newline' 'git config key.sub value.with\\\
968 cat > .git
/config
<<\EOF
973 noncont
= not continued
; \
979 section.continued
=continued
980 section.noncont
=not continued
981 section.quotecont
=cont
;inued
984 test_expect_success
'value continued on next line' '
985 git config --list > result &&
986 test_cmp expect result
989 cat > .git
/config
<<\EOF
990 [section
"sub=section"]
999 section.sub
=section.val1
1000 foo
=barQsection.sub
=section.val2
1002 barQsection.sub
=section.val3
1005 Qsection.sub
=section.val4
1006 Qsection.sub
=section.val5Q
1008 test_expect_success
'--null --list' '
1009 git config --null --list >result.raw &&
1010 nul_to_q <result.raw >result &&
1012 test_cmp expect result
1015 test_expect_success
'--null --get-regexp' '
1016 git config --null --get-regexp "val[0-9]" >result.raw &&
1017 nul_to_q <result.raw >result &&
1019 test_cmp expect result
1022 test_expect_success
'inner whitespace kept verbatim' '
1023 git config section.val "foo bar" &&
1024 test_cmp_config "foo bar" section.val
1027 test_expect_success SYMLINKS
'symlinked configuration' '
1028 ln -s notyet myconfig &&
1029 git config --file=myconfig test.frotz nitfol &&
1032 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1033 git config --file=myconfig test.xyzzy rezrov &&
1036 cat >expect <<-\EOF &&
1041 git config --file=notyet test.frotz &&
1042 git config --file=notyet test.xyzzy
1044 test_cmp expect actual
1047 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
1048 ln -s doesnotexist linktonada &&
1049 ln -s linktonada linktolinktonada &&
1050 test_must_fail git config --file=linktonada --list &&
1051 test_must_fail git config --file=linktolinktonada --list
1054 test_expect_success
'check split_cmdline return' "
1055 git config alias.split-cmdline-fix 'echo \"' &&
1056 test_must_fail git split-cmdline-fix &&
1059 git commit -m 'initial commit' &&
1060 git config branch.main.mergeoptions 'echo \"' &&
1061 test_must_fail git merge main
1064 test_expect_success
'git -c "key=value" support' '
1065 cat >expect <<-\EOF &&
1071 git -c section.name=value config section.name &&
1072 git -c foo.CamelCase=value config foo.camelcase &&
1073 git -c foo.flag config --bool foo.flag
1075 test_cmp expect actual &&
1076 test_must_fail git -c name=value config section.name
1079 # We just need a type-specifier here that cares about the
1080 # distinction internally between a NULL boolean and a real
1081 # string (because most of git's internal parsers do care).
1082 # Using "--path" works, but we do not otherwise care about
1084 test_expect_success
'git -c can represent empty string' '
1086 git -c foo.empty= config --path foo.empty >actual &&
1087 test_cmp expect actual
1090 test_expect_success
'key sanity-checking' '
1091 test_must_fail git config foo=bar &&
1092 test_must_fail git config foo=.bar &&
1093 test_must_fail git config foo.ba=r &&
1094 test_must_fail git config foo.1bar &&
1095 test_must_fail git config foo."ba
1097 test_must_fail git config . false &&
1098 test_must_fail git config .foo false &&
1099 test_must_fail git config foo. false &&
1100 test_must_fail git config .foo. false &&
1101 git config foo.bar true &&
1102 git config foo."ba =z".bar false
1105 test_expect_success
'git -c works with aliases of builtins' '
1106 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1108 git checkconfig >actual &&
1109 test_cmp expect actual
1112 test_expect_success
'aliases can be CamelCased' '
1113 test_config alias.CamelCased "rev-parse HEAD" &&
1114 git CamelCased >out &&
1115 git rev-parse HEAD >expect &&
1119 test_expect_success
'git -c does not split values on equals' '
1120 echo "value with = in it" >expect &&
1121 git -c section.foo="value with = in it" config section.foo >actual &&
1122 test_cmp expect actual
1125 test_expect_success
'git -c dies on bogus config' '
1126 test_must_fail git -c core.bare=foo rev-parse
1129 test_expect_success
'git -c complains about empty key' '
1130 test_must_fail git -c "=foo" rev-parse
1133 test_expect_success
'git -c complains about empty key and value' '
1134 test_must_fail git -c "" rev-parse
1137 test_expect_success
'multiple git -c appends config' '
1138 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1139 cat >expect <<-\EOF &&
1143 git -c x.one=1 x >actual &&
1144 test_cmp expect actual
1147 test_expect_success
'last one wins: two level vars' '
1149 # sec.var and sec.VAR are the same variable, as the first
1150 # and the last level of a configuration variable name is
1155 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1156 test_cmp expect actual &&
1157 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1158 test_cmp expect actual &&
1160 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1161 test_cmp expect actual &&
1162 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1163 test_cmp expect actual
1166 test_expect_success
'last one wins: three level vars' '
1168 # v.a.r and v.A.r are not the same variable, as the middle
1169 # level of a three-level configuration variable name is
1173 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1174 test_cmp expect actual &&
1175 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1176 test_cmp expect actual &&
1178 # v.a.r and V.a.R are the same variable, as the first
1179 # and the last level of a configuration variable name is
1183 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1184 test_cmp expect actual &&
1185 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1186 test_cmp expect actual &&
1187 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1188 test_cmp expect actual &&
1189 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1190 test_cmp expect actual
1193 test_expect_success
'old-fashioned settings are case insensitive' '
1194 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1196 cat >testConfig_actual <<-EOF &&
1200 q_to_tab >testConfig_expect <<-EOF &&
1204 git config -f testConfig_actual "v.a.r" value2 &&
1205 test_cmp testConfig_expect testConfig_actual &&
1207 cat >testConfig_actual <<-EOF &&
1211 q_to_tab >testConfig_expect <<-EOF &&
1215 git config -f testConfig_actual "V.a.R" value2 &&
1216 test_cmp testConfig_expect testConfig_actual &&
1218 cat >testConfig_actual <<-EOF &&
1222 q_to_tab >testConfig_expect <<-EOF &&
1227 git config -f testConfig_actual "V.A.r" value2 &&
1228 test_cmp testConfig_expect testConfig_actual &&
1230 cat >testConfig_actual <<-EOF &&
1234 q_to_tab >testConfig_expect <<-EOF &&
1239 git config -f testConfig_actual "v.A.r" value2 &&
1240 test_cmp testConfig_expect testConfig_actual
1243 test_expect_success
'setting different case sensitive subsections ' '
1244 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1246 cat >testConfig_actual <<-EOF &&
1256 q_to_tab >testConfig_expect <<-EOF &&
1269 git config -f testConfig_actual a.b.c v2 &&
1270 # match section and subsection, key is cased differently.
1271 git config -f testConfig_actual K.E.y v2 &&
1272 # section and key are matched case insensitive, but subsection needs
1273 # to match; When writing out new values only the key is adjusted
1274 git config -f testConfig_actual v.A.r v2 &&
1275 # subsection is not matched:
1276 git config -f testConfig_actual d.E.f v2 &&
1277 test_cmp testConfig_expect testConfig_actual
1280 for VAR
in a .a a. a
.0b a.
"b c". a.
"b c".0d
1282 test_expect_success
"git -c $VAR=VAL rejects invalid '$VAR'" '
1283 test_must_fail git -c "$VAR=VAL" config -l
1287 for VAR
in a.b a.
"b c".d
1289 test_expect_success
"git -c $VAR=VAL works with valid '$VAR'" '
1291 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1292 test_cmp expect actual
1296 test_expect_success
'git -c is not confused by empty environment' '
1297 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1300 test_expect_success
'GIT_CONFIG_PARAMETERS handles old-style entries' '
1301 v="${SQ}key.one=foo${SQ}" &&
1302 v="$v ${SQ}key.two=bar${SQ}" &&
1303 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1304 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1305 cat >expect <<-EOF &&
1308 key.ambiguous section.whatever=value
1310 test_cmp expect actual
1313 test_expect_success
'GIT_CONFIG_PARAMETERS handles new-style entries' '
1314 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1315 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1316 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1317 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1318 cat >expect <<-EOF &&
1321 key.ambiguous=section.whatever value
1323 test_cmp expect actual
1326 test_expect_success
'old and new-style entries can mix' '
1327 v="${SQ}key.oldone=oldfoo${SQ}" &&
1328 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1329 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1330 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1331 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1332 cat >expect <<-EOF &&
1338 test_cmp expect actual
1341 test_expect_success
'old and new bools with ambiguous subsection' '
1342 v="${SQ}key.with=equals.oldbool${SQ}" &&
1343 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1344 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1345 cat >expect <<-EOF &&
1346 key.with equals.oldbool
1347 key.with=equals.newbool
1349 test_cmp expect actual
1352 test_expect_success
'detect bogus GIT_CONFIG_PARAMETERS' '
1353 cat >expect <<-\EOF &&
1357 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1358 git config --get-regexp "env.*" >actual &&
1359 test_cmp expect actual &&
1361 cat >expect <<-EOF &&
1365 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1366 git config --get-regexp "env.*" >actual &&
1367 test_cmp expect actual &&
1369 test_must_fail env \
1370 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1371 git config --get-regexp "env.*"
1374 test_expect_success
'git --config-env=key=envvar support' '
1375 cat >expect <<-\EOF &&
1384 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1385 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1386 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1387 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1388 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1389 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1391 test_cmp expect actual
1394 test_expect_success
'git --config-env with missing value' '
1395 test_must_fail env ENVVAR=value git --config-env 2>error &&
1396 grep "no config key given for --config-env" error &&
1397 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1398 grep "invalid config format: config" error
1401 test_expect_success
'git --config-env fails with invalid parameters' '
1402 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1403 test_i18ngrep "invalid config format: foo.flag" error &&
1404 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1405 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1406 sane_unset NONEXISTENT &&
1407 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1408 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1411 test_expect_success
'git -c and --config-env work together' '
1412 cat >expect <<-\EOF &&
1416 ENVVAR=env-value git \
1417 -c bar.cmd=cmd-value \
1418 --config-env=bar.env=ENVVAR \
1419 config --get-regexp "^bar.*" >actual &&
1420 test_cmp expect actual
1423 test_expect_success
'git -c and --config-env override each other' '
1424 cat >expect <<-\EOF &&
1429 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1430 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1432 test_cmp expect actual
1435 test_expect_success
'--config-env handles keys with equals' '
1436 echo value=with=equals >expect &&
1437 ENVVAR=value=with=equals git \
1438 --config-env=section.subsection=with=equals.key=ENVVAR \
1439 config section.subsection=with=equals.key >actual &&
1440 test_cmp expect actual
1443 test_expect_success
'git config handles environment config pairs' '
1444 GIT_CONFIG_COUNT=2 \
1445 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1446 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1447 git config --get-regexp "pair.*" >actual &&
1448 cat >expect <<-EOF &&
1452 test_cmp expect actual
1455 test_expect_success
'git config ignores pairs without count' '
1456 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1457 git config pair.one 2>error &&
1458 test_must_be_empty error
1461 test_expect_success
'git config ignores pairs with zero count' '
1462 test_must_fail env \
1463 GIT_CONFIG_COUNT=0 \
1464 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1468 test_expect_success
'git config ignores pairs exceeding count' '
1469 GIT_CONFIG_COUNT=1 \
1470 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1471 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1472 git config --get-regexp "pair.*" >actual &&
1473 cat >expect <<-EOF &&
1476 test_cmp expect actual
1479 test_expect_success
'git config ignores pairs with zero count' '
1480 test_must_fail env \
1481 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1482 git config pair.one >error &&
1483 test_must_be_empty error
1486 test_expect_success
'git config ignores pairs with empty count' '
1487 test_must_fail env \
1488 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1489 git config pair.one >error &&
1490 test_must_be_empty error
1493 test_expect_success
'git config fails with invalid count' '
1494 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1495 test_i18ngrep "bogus count" error &&
1496 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1497 test_i18ngrep "too many entries" error
1500 test_expect_success
'git config fails with missing config key' '
1501 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1502 git config --list 2>error &&
1503 test_i18ngrep "missing config key" error
1506 test_expect_success
'git config fails with missing config value' '
1507 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1508 git config --list 2>error &&
1509 test_i18ngrep "missing config value" error
1512 test_expect_success
'git config fails with invalid config pair key' '
1513 test_must_fail env GIT_CONFIG_COUNT=1 \
1514 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1515 git config --list &&
1516 test_must_fail env GIT_CONFIG_COUNT=1 \
1517 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1521 test_expect_success
'environment overrides config file' '
1522 test_when_finished "rm -f .git/config" &&
1523 cat >.git/config <<-EOF &&
1527 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1528 git config pair.one >actual &&
1529 cat >expect <<-EOF &&
1532 test_cmp expect actual
1535 test_expect_success
'GIT_CONFIG_PARAMETERS overrides environment config' '
1536 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1537 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1538 git config pair.one >actual &&
1539 cat >expect <<-EOF &&
1542 test_cmp expect actual
1545 test_expect_success
'command line overrides environment config' '
1546 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1547 git -c pair.one=override config pair.one >actual &&
1548 cat >expect <<-EOF &&
1551 test_cmp expect actual
1554 test_expect_success
'git config --edit works' '
1555 git config -f tmp test.value no &&
1556 echo test.value=yes >expect &&
1557 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1558 git config -f tmp --list >actual &&
1559 test_cmp expect actual
1562 test_expect_success
'git config --edit respects core.editor' '
1563 git config -f tmp test.value no &&
1564 echo test.value=yes >expect &&
1565 test_config core.editor "echo [test]value=yes >" &&
1566 git config -f tmp --edit &&
1567 git config -f tmp --list >actual &&
1568 test_cmp expect actual
1571 # malformed configuration files
1572 test_expect_success
'barf on syntax error' '
1573 cat >.git/config <<-\EOF &&
1574 # broken section line
1578 test_must_fail git config --get section.key >actual 2>error &&
1579 test_i18ngrep " line 3 " error
1582 test_expect_success
'barf on incomplete section header' '
1583 cat >.git/config <<-\EOF &&
1584 # broken section line
1588 test_must_fail git config --get section.key >actual 2>error &&
1589 test_i18ngrep " line 2 " error
1592 test_expect_success
'barf on incomplete string' '
1593 cat >.git/config <<-\EOF &&
1594 # broken section line
1598 test_must_fail git config --get section.key >actual 2>error &&
1599 test_i18ngrep " line 3 " error
1602 test_expect_success
'urlmatch' '
1603 cat >.git/config <<-\EOF &&
1606 [http "https://weak.example.com"]
1608 cookieFile = /tmp/cookie.txt
1611 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1612 test_must_be_empty actual &&
1614 echo true >expect &&
1615 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1616 test_cmp expect actual &&
1618 echo false >expect &&
1619 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1620 test_cmp expect actual &&
1623 echo http.cookiefile /tmp/cookie.txt &&
1624 echo http.sslverify false
1626 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1627 test_cmp expect actual
1630 test_expect_success
'urlmatch favors more specific URLs' '
1631 cat >.git/config <<-\EOF &&
1632 [http "https://example.com/"]
1633 cookieFile = /tmp/root.txt
1634 [http "https://example.com/subdirectory"]
1635 cookieFile = /tmp/subdirectory.txt
1636 [http "https://user@example.com/"]
1637 cookieFile = /tmp/user.txt
1638 [http "https://averylonguser@example.com/"]
1639 cookieFile = /tmp/averylonguser.txt
1640 [http "https://preceding.example.com"]
1641 cookieFile = /tmp/preceding.txt
1642 [http "https://*.example.com"]
1643 cookieFile = /tmp/wildcard.txt
1644 [http "https://*.example.com/wildcardwithsubdomain"]
1645 cookieFile = /tmp/wildcardwithsubdomain.txt
1646 [http "https://*.example.*"]
1647 cookieFile = /tmp/multiwildcard.txt
1648 [http "https://trailing.example.com"]
1649 cookieFile = /tmp/trailing.txt
1650 [http "https://user@*.example.com/"]
1651 cookieFile = /tmp/wildcardwithuser.txt
1652 [http "https://sub.example.com/"]
1653 cookieFile = /tmp/sub.txt
1656 echo http.cookiefile /tmp/root.txt >expect &&
1657 git config --get-urlmatch HTTP https://example.com >actual &&
1658 test_cmp expect actual &&
1660 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1661 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1662 test_cmp expect actual &&
1664 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1665 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1666 test_cmp expect actual &&
1668 echo http.cookiefile /tmp/user.txt >expect &&
1669 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1670 test_cmp expect actual &&
1672 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1673 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1674 test_cmp expect actual &&
1676 echo http.cookiefile /tmp/preceding.txt >expect &&
1677 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1678 test_cmp expect actual &&
1680 echo http.cookiefile /tmp/wildcard.txt >expect &&
1681 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1682 test_cmp expect actual &&
1684 echo http.cookiefile /tmp/sub.txt >expect &&
1685 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1686 test_cmp expect actual &&
1688 echo http.cookiefile /tmp/trailing.txt >expect &&
1689 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1690 test_cmp expect actual &&
1692 echo http.cookiefile /tmp/sub.txt >expect &&
1693 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1694 test_cmp expect actual &&
1696 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1697 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1698 test_cmp expect actual
1701 test_expect_success
'urlmatch with wildcard' '
1702 cat >.git/config <<-\EOF &&
1705 [http "https://*.example.com"]
1707 cookieFile = /tmp/cookie.txt
1710 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1711 test_must_be_empty actual &&
1713 echo true >expect &&
1714 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1715 test_cmp expect actual &&
1717 echo true >expect &&
1718 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1719 test_cmp expect actual &&
1721 echo true >expect &&
1722 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1723 test_cmp expect actual &&
1725 echo false >expect &&
1726 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1727 test_cmp expect actual &&
1730 echo http.cookiefile /tmp/cookie.txt &&
1731 echo http.sslverify false
1733 git config --get-urlmatch HTTP https://good.example.com >actual &&
1734 test_cmp expect actual &&
1736 echo http.sslverify >expect &&
1737 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1738 test_cmp expect actual
1741 # good section hygiene
1742 test_expect_success
'--unset last key removes section (except if commented)' '
1743 cat >.git/config <<-\EOF &&
1744 # some generic comment on the configuration file itself
1745 # a comment specific to this "section" section.
1747 # some intervening lines
1748 # that should also be dropped
1751 # please be careful when you update the above variable
1754 cat >expect <<-\EOF &&
1755 # some generic comment on the configuration file itself
1756 # a comment specific to this "section" section.
1758 # some intervening lines
1759 # that should also be dropped
1761 # please be careful when you update the above variable
1764 git config --unset section.key &&
1765 test_cmp expect .git/config &&
1767 cat >.git/config <<-\EOF &&
1773 cat >expect <<-\EOF &&
1777 git config --unset section.key &&
1778 test_cmp expect .git/config &&
1780 q_to_tab >.git/config <<-\EOF &&
1787 git config --unset two.key &&
1788 ! grep two .git/config &&
1790 q_to_tab >.git/config <<-\EOF &&
1797 git config --unset-all one.key &&
1798 test_line_count = 0 .git/config &&
1800 q_to_tab >.git/config <<-\EOF &&
1803 Q# a comment not at the start
1807 git config --unset two.key &&
1808 grep two .git/config &&
1810 q_to_tab >.git/config <<-\EOF &&
1812 Qkey = not [two "subsection"]
1819 git config --unset two.subsection.key &&
1820 test "not [two subsection]" = "$(git config one.key)" &&
1821 test_line_count = 3 .git/config
1824 test_expect_success
'--unset-all removes section if empty & uncommented' '
1825 cat >.git/config <<-\EOF &&
1831 git config --unset-all section.key &&
1832 test_line_count = 0 .git/config
1835 test_expect_success
'adding a key into an empty section reuses header' '
1836 cat >.git/config <<-\EOF &&
1840 q_to_tab >expect <<-\EOF &&
1845 git config section.key value &&
1846 test_cmp expect .git/config
1849 test_expect_success POSIXPERM
,PERL
'preserves existing permissions' '
1850 chmod 0600 .git/config &&
1851 git config imap.pass Hunter2 &&
1853 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1854 git config --rename-section imap pop &&
1856 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1859 ! test_have_prereq MINGW ||
1860 HOME
="$(pwd)" # convert to Windows path
1862 test_expect_success
'set up --show-origin tests' '
1863 INCLUDE_DIR="$HOME/include" &&
1864 mkdir -p "$INCLUDE_DIR" &&
1865 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1869 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1873 cat >"$HOME"/.gitconfig <<-EOF &&
1878 path = "$INCLUDE_DIR/absolute.include"
1880 cat >.git/config <<-\EOF
1885 path = ../include/relative.include
1889 test_expect_success
'--show-origin with --list' '
1890 cat >expect <<-EOF &&
1891 file:$HOME/.gitconfig user.global=true
1892 file:$HOME/.gitconfig user.override=global
1893 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1894 file:$INCLUDE_DIR/absolute.include user.absolute=include
1895 file:.git/config user.local=true
1896 file:.git/config user.override=local
1897 file:.git/config include.path=../include/relative.include
1898 file:.git/../include/relative.include user.relative=include
1899 command line: user.environ=true
1900 command line: user.cmdline=true
1902 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1903 git -c user.cmdline=true config --list --show-origin >output &&
1904 test_cmp expect output
1907 test_expect_success
'--show-origin with --list --null' '
1908 cat >expect <<-EOF &&
1909 file:$HOME/.gitconfigQuser.global
1910 trueQfile:$HOME/.gitconfigQuser.override
1911 globalQfile:$HOME/.gitconfigQinclude.path
1912 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1913 includeQfile:.git/configQuser.local
1914 trueQfile:.git/configQuser.override
1915 localQfile:.git/configQinclude.path
1916 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1917 includeQcommand line:Quser.cmdline
1920 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1921 nul_to_q <output.raw >output &&
1922 # The here-doc above adds a newline that the --null output would not
1923 # include. Add it here to make the two comparable.
1925 test_cmp expect output
1928 test_expect_success
'--show-origin with single file' '
1929 cat >expect <<-\EOF &&
1930 file:.git/config user.local=true
1931 file:.git/config user.override=local
1932 file:.git/config include.path=../include/relative.include
1934 git config --local --list --show-origin >output &&
1935 test_cmp expect output
1938 test_expect_success
'--show-origin with --get-regexp' '
1939 cat >expect <<-EOF &&
1940 file:$HOME/.gitconfig user.global true
1941 file:.git/config user.local true
1943 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1944 test_cmp expect output
1947 test_expect_success
'--show-origin getting a single key' '
1948 cat >expect <<-\EOF &&
1949 file:.git/config local
1951 git config --show-origin user.override >output &&
1952 test_cmp expect output
1955 test_expect_success
'set up custom config file' '
1956 CUSTOM_CONFIG_FILE="custom.conf" &&
1957 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1963 test_expect_success
!MINGW
'set up custom config file with special name characters' '
1964 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
1965 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
1968 test_expect_success
!MINGW
'--show-origin escape special file name characters' '
1969 cat >expect <<-\EOF &&
1970 file:"file\" (dq) and spaces.conf" user.custom=true
1972 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
1973 test_cmp expect output
1976 test_expect_success
'--show-origin stdin' '
1977 cat >expect <<-\EOF &&
1978 standard input: user.custom=true
1980 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1981 test_cmp expect output
1984 test_expect_success
'--show-origin stdin with file include' '
1985 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1989 cat >expect <<-EOF &&
1990 file:$INCLUDE_DIR/stdin.include include
1992 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
1993 git config --show-origin --includes --file - user.stdin >output &&
1995 test_cmp expect output
1998 test_expect_success
'--show-origin blob' '
1999 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2000 cat >expect <<-EOF &&
2001 blob:$blob user.custom=true
2003 git config --blob=$blob --show-origin --list >output &&
2004 test_cmp expect output
2007 test_expect_success
'--show-origin blob ref' '
2008 cat >expect <<-\EOF &&
2009 blob:main:custom.conf user.custom=true
2011 git add "$CUSTOM_CONFIG_FILE" &&
2012 git commit -m "new config file" &&
2013 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2014 test_cmp expect output
2017 test_expect_success
'--show-scope with --list' '
2018 cat >expect <<-EOF &&
2019 global user.global=true
2020 global user.override=global
2021 global include.path=$INCLUDE_DIR/absolute.include
2022 global user.absolute=include
2023 local user.local=true
2024 local user.override=local
2025 local include.path=../include/relative.include
2026 local user.relative=include
2027 command user.cmdline=true
2029 git -c user.cmdline=true config --list --show-scope >output &&
2030 test_cmp expect output
2033 test_expect_success
!MINGW
'--show-scope with --blob' '
2034 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2035 cat >expect <<-EOF &&
2036 command user.custom=true
2038 git config --blob=$blob --show-scope --list >output &&
2039 test_cmp expect output
2042 test_expect_success
'--show-scope with --local' '
2043 cat >expect <<-\EOF &&
2044 local user.local=true
2045 local user.override=local
2046 local include.path=../include/relative.include
2048 git config --local --list --show-scope >output &&
2049 test_cmp expect output
2052 test_expect_success
'--show-scope getting a single value' '
2053 cat >expect <<-\EOF &&
2056 git config --show-scope --get user.local >output &&
2057 test_cmp expect output
2060 test_expect_success
'--show-scope with --show-origin' '
2061 cat >expect <<-EOF &&
2062 global file:$HOME/.gitconfig user.global=true
2063 global file:$HOME/.gitconfig user.override=global
2064 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2065 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2066 local file:.git/config user.local=true
2067 local file:.git/config user.override=local
2068 local file:.git/config include.path=../include/relative.include
2069 local file:.git/../include/relative.include user.relative=include
2070 command command line: user.cmdline=true
2072 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2073 test_cmp expect output
2076 test_expect_success
'override global and system config' '
2077 test_when_finished rm -f "$HOME"/.config/git &&
2079 cat >"$HOME"/.gitconfig <<-EOF &&
2083 mkdir -p "$HOME"/.config/git &&
2084 cat >"$HOME"/.config/git/config <<-EOF &&
2088 cat >.git/config <<-EOF &&
2092 cat >custom-global-config <<-EOF &&
2096 cat >custom-system-config <<-EOF &&
2101 cat >expect <<-EOF &&
2102 global xdg.config=true
2103 global home.config=true
2104 local local.config=true
2106 git config --show-scope --list >output &&
2107 test_cmp expect output &&
2109 cat >expect <<-EOF &&
2110 system system.config=true
2111 global global.config=true
2112 local local.config=true
2114 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2115 git config --show-scope --list >output &&
2116 test_cmp expect output &&
2118 cat >expect <<-EOF &&
2119 local local.config=true
2121 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2122 git config --show-scope --list >output &&
2123 test_cmp expect output
2126 test_expect_success
'override global and system config with missing file' '
2127 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2128 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2129 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2132 test_expect_success
'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2133 # `git config --system` has different semantics compared to other
2134 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2135 # variable has an effect via a different proxy.
2136 cat >alias-config <<-EOF &&
2138 hello-world = !echo "hello world"
2140 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2142 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2143 git hello-world >actual &&
2144 echo "hello world" >expect &&
2145 test_cmp expect actual
2148 test_expect_success
'write to overridden global and system config' '
2149 cat >expect <<EOF &&
2154 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2155 test_cmp expect write-to-global &&
2157 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2158 test_cmp expect write-to-system
2161 for opt
in --local --worktree
2163 test_expect_success
"$opt requires a repo" '
2164 # we expect 128 to ensure that we do not simply
2165 # fail to find anything and return code "1"
2166 test_expect_code 128 nongit git config $opt foo.bar
2170 cat >.git
/config
<<-\EOF &&
2177 test_expect_success 'identical modern --type specifiers are allowed' '
2178 test_cmp_config 1048576 --type=int --type=int section.big
2181 test_expect_success 'identical legacy --type specifiers are allowed' '
2182 test_cmp_config 1048576 --int --int section.big
2185 test_expect_success 'identical mixed --type specifiers are allowed' '
2186 test_cmp_config 1048576 --int --type=int section.big
2189 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2190 test_must_fail git config --type=int --type=bool section.big 2>error &&
2191 test_i18ngrep "only one type at a time" error
2194 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2195 test_must_fail git config --int --bool section.big 2>error &&
2196 test_i18ngrep "only one type at a time" error
2199 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2200 test_must_fail git config --type=int --bool section.big 2>error &&
2201 test_i18ngrep "only one type at a time" error
2204 test_expect_success '--type allows valid type specifiers' '
2205 test_cmp_config true --type=bool section.foo
2208 test_expect_success '--no-type unsets type specifiers' '
2209 test_cmp_config 10 --type=bool --no-type section.number
2212 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2213 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2216 test_expect_success '--type rejects unknown specifiers' '
2217 test_must_fail git config --type=nonsense section.foo 2>error &&
2218 test_i18ngrep "unrecognized --type argument" error
2221 test_expect_success '--replace-all does not invent newlines' '
2222 q_to_tab >.git/config <<-\
EOF &&
2230 q_to_tab >expect <<-\EOF &&
2238 git config --replace-all abc.key b &&
2239 test_cmp expect .git/config
2242 test_expect_success 'set all config with value-pattern' '
2243 test_when_finished rm -f config initial &&
2244 git config --file=initial abc.key one &&
2246 # no match => add new entry
2247 cp initial config &&
2248 git config --file=config abc.key two a+ &&
2249 git config --file=config --list >actual &&
2250 cat >expect <<-\EOF &&
2254 test_cmp expect actual &&
2256 # multiple matches => failure
2257 test_must_fail git config --file=config abc.key three o+ 2>err &&
2258 test_i18ngrep "has multiple values" err &&
2260 # multiple values, no match => add
2261 git config --file=config abc.key three a+ &&
2262 git config --file=config --list >actual &&
2263 cat >expect <<-\EOF &&
2268 test_cmp expect actual &&
2270 # single match => replace
2271 git config --file=config abc.key four h+ &&
2272 git config --file=config --list >actual &&
2273 cat >expect <<-\EOF &&
2278 test_cmp expect actual
2281 test_expect_success '--replace-all and value-pattern' '
2282 test_when_finished rm -f config &&
2283 git config --file=config --add abc.key one &&
2284 git config --file=config --add abc.key two &&
2285 git config --file=config --add abc.key three &&
2286 git config --file=config --replace-all abc.key four "o+" &&
2287 git config --file=config --list >actual &&
2288 cat >expect <<-\EOF &&
2292 test_cmp expect actual
2295 test_expect_success 'refuse --fixed-value for incompatible actions' '
2296 test_when_finished rm -f config &&
2297 git config --file=config dev.null bogus &&
2299 # These modes do not allow --fixed-value at all
2300 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2301 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2302 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2303 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2304 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2305 test_must_fail git config --file=config --fixed-value --list &&
2306 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2307 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2309 # These modes complain when --fixed-value has no value-pattern
2310 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2311 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2312 test_must_fail git config --file=config --fixed-value --get dev.null &&
2313 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2314 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2315 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2316 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2319 test_expect_success '--fixed-value uses exact string matching' '
2320 test_when_finished rm -f config initial &&
2321 META="a+b*c?d[e]f.g" &&
2322 git config --file=initial fixed.test "$META" &&
2324 cp initial config &&
2325 git config --file=config fixed.test bogus "$META" &&
2326 git config --file=config --list >actual &&
2327 cat >expect <<-EOF &&
2331 test_cmp expect actual &&
2333 cp initial config &&
2334 git config --file=config --fixed-value fixed.test bogus "$META" &&
2335 git config --file=config --list >actual &&
2336 cat >expect <<-\EOF &&
2339 test_cmp expect actual &&
2341 cp initial config &&
2342 test_must_fail git config --file=config --unset fixed.test "$META" &&
2343 git config --file=config --fixed-value --unset fixed.test "$META" &&
2344 test_must_fail git config --file=config fixed.test &&
2346 cp initial config &&
2347 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2348 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2349 test_must_fail git config --file=config fixed.test &&
2351 cp initial config &&
2352 git config --file=config --replace-all fixed.test bogus "$META" &&
2353 git config --file=config --list >actual &&
2354 cat >expect <<-EOF &&
2358 test_cmp expect actual &&
2360 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2361 git config --file=config --list >actual &&
2362 cat >expect <<-EOF &&
2366 test_cmp expect actual
2369 test_expect_success '--get and --get-all with --fixed-value' '
2370 test_when_finished rm -f config &&
2371 META="a+b*c?d[e]f.g" &&
2372 git config --file=config fixed.test bogus &&
2373 git config --file=config --add fixed.test "$META" &&
2375 git config --file=config --get fixed.test bogus &&
2376 test_must_fail git config --file=config --get fixed.test "$META" &&
2377 git config --file=config --get --fixed-value fixed.test "$META" &&
2378 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2380 git config --file=config --get-all fixed.test bogus &&
2381 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2382 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2383 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2385 git config --file=config --get-regexp fixed+ bogus &&
2386 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2387 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2388 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent