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 for mode
in legacy subcommands
21 mode_get_all
="--get-all"
22 mode_get_regexp
="--get-regexp"
24 mode_replace_all
="--replace-all"
26 mode_unset_all
="--unset-all"
31 mode_get_all
="get --all"
32 mode_get_regexp
="get --regexp --all --show-names"
34 mode_replace_all
="set --all"
36 mode_unset_all
="unset --all"
39 BUG
"unknown mode $mode";;
42 test_expect_success
'setup whitespace config' '
45 -e "s/X/ /g" >.git/config <<-\EOF
48 | sparse = big XX blue
49 | sparseAndTail = big XX blue $
50 | sparseAndTailQuoted = "big XX blue "
51 | sparseAndBiggerTail = big XX blue X X
52 | sparseAndBiggerTailQuoted = "big XX blue X X"
53 | sparseAndBiggerTailQuotedPlus = "big XX blue X X"X $
54 | headAndTail = Xbig blue $
55 | headAndTailQuoted = "Xbig blue "
56 | headAndTailQuotedPlus = "Xbig blue " $
57 | annotated = big blueX# to be discarded
58 | annotatedQuoted = "big blue"X# to be discarded
62 test_expect_success
'no internal whitespace' '
63 echo "rock" >expect &&
64 git config --get section.solid >actual &&
65 test_cmp expect actual
68 test_expect_success
'internal whitespace' '
69 echo "big QQ blue" | q_to_tab >expect &&
70 git config --get section.sparse >actual &&
71 test_cmp expect actual
74 test_expect_success
'internal and trailing whitespace' '
75 echo "big QQ blue" | q_to_tab >expect &&
76 git config --get section.sparseAndTail >actual &&
77 test_cmp expect actual
80 test_expect_success
'internal and trailing whitespace, all quoted' '
81 echo "big QQ blue " | q_to_tab >expect &&
82 git config --get section.sparseAndTailQuoted >actual &&
83 test_cmp expect actual
86 test_expect_success
'internal and more trailing whitespace' '
87 echo "big QQ blue" | q_to_tab >expect &&
88 git config --get section.sparseAndBiggerTail >actual &&
89 test_cmp expect actual
92 test_expect_success
'internal and more trailing whitespace, all quoted' '
93 echo "big QQ blue Q Q" | q_to_tab >expect &&
94 git config --get section.sparseAndBiggerTailQuoted >actual &&
95 test_cmp expect actual
98 test_expect_success
'internal and more trailing whitespace, not all quoted' '
99 echo "big QQ blue Q Q" | q_to_tab >expect &&
100 git config --get section.sparseAndBiggerTailQuotedPlus >actual &&
101 test_cmp expect actual
104 test_expect_success
'leading and trailing whitespace' '
105 echo "big blue" >expect &&
106 git config --get section.headAndTail >actual &&
107 test_cmp expect actual
110 test_expect_success
'leading and trailing whitespace, all quoted' '
111 echo "Qbig blue " | q_to_tab >expect &&
112 git config --get section.headAndTailQuoted >actual &&
113 test_cmp expect actual
116 test_expect_success
'leading and trailing whitespace, not all quoted' '
117 echo "Qbig blue " | q_to_tab >expect &&
118 git config --get section.headAndTailQuotedPlus >actual &&
119 test_cmp expect actual
122 test_expect_success
'inline comment' '
123 echo "big blue" >expect &&
124 git config --get section.annotated >actual &&
125 test_cmp expect actual
128 test_expect_success
'inline comment, quoted' '
129 echo "big blue" >expect &&
130 git config --get section.annotatedQuoted >actual &&
131 test_cmp expect actual
134 test_expect_success
'clear default config' '
140 penguin = little blue
142 test_expect_success
'initial' '
143 git config ${mode_set} section.penguin "little blue" &&
144 test_cmp expect .git/config
149 penguin = little blue
152 test_expect_success
'mixed case' '
153 git config ${mode_set} Section.Movie BadPhysics &&
154 test_cmp expect .git/config
159 penguin = little blue
164 test_expect_success
'similar section' '
165 git config ${mode_set} Sections.WhatEver Second &&
166 test_cmp expect .git/config
171 penguin = little blue
177 test_expect_success
'uppercase section' '
178 git config ${mode_set} SECTION.UPPERCASE true &&
179 test_cmp expect .git/config
182 test_expect_success
'replace with non-match' '
183 git config section.penguin kingpin !blue
186 test_expect_success
'replace with non-match (actually matching)' '
187 git config section.penguin "very blue" !kingpin
194 penguin = gentoo # Pygoscelis papua
195 disposition = peckish # find fish
197 spsp = value # and comment
198 htsp = value # and comment
203 test_expect_success
'append comments' '
204 git config --replace-all --comment="Pygoscelis papua" section.penguin gentoo &&
205 git config ${mode_set} --comment="find fish" section.disposition peckish &&
206 git config ${mode_set} --comment="#abc" section.foo bar &&
208 git config --comment="and comment" section.spsp value &&
209 git config --comment=" # and comment" section.htsp value &&
211 test_cmp expect .git/config
214 test_expect_success
'Prohibited LF in comment' '
215 test_must_fail git config ${mode_set} --comment="a${LF}b" section.k v
218 test_expect_success
'non-match result' 'test_cmp expect .git/config'
220 test_expect_success
'find mixed-case key by canonical name' '
221 test_cmp_config Second sections.whatever
224 test_expect_success
'find mixed-case key by non-canonical name' '
225 test_cmp_config Second SeCtIoNs.WhAtEvEr
228 test_expect_success
'subsections are not canonicalized by git-config' '
229 cat >>.git/config <<-\EOF &&
232 [section "SubSection"]
235 test_cmp_config one section.subsection.key &&
236 test_cmp_config two section.SubSection.key
239 test_missing_key
() {
242 test_expect_success
"value for $title is not printed" '
243 test_must_fail git config "$key" >out 2>err &&
244 test_must_be_empty out &&
245 test_must_be_empty err
249 test_missing_key
'missingsection.missingkey' 'missing section and missing key'
250 test_missing_key
'missingsection.penguin' 'missing section and existing key'
251 test_missing_key
'section.missingkey' 'existing section and missing key'
252 test_missing_key
'section.MissingSubSection.missingkey' 'missing subsection and missing key'
253 test_missing_key
'section.SubSection.missingkey' 'existing subsection and missing key'
254 test_missing_key
'section.MissingSubSection.key' 'missing subsection and existing key'
256 cat > .git
/config
<<\EOF
265 test_expect_success
'unset with cont. lines' '
266 git config ${mode_unset} beta.baz
276 test_expect_success
'unset with cont. lines is correct' 'test_cmp expect .git/config'
278 cat > .git
/config
<< EOF
279 [beta] ; silly comment # another comment
280 noIndent= sillyValue ; 'nother silly comment
284 haha ="beta" # last silly comment
287 [nextSection] noNewline = ouch
290 cp .git
/config .git
/config2
292 test_expect_success
'multiple unset' '
293 git config ${mode_unset_all} beta.haha
297 [beta] ; silly comment # another comment
298 noIndent= sillyValue ; 'nother silly comment
302 [nextSection] noNewline = ouch
305 test_expect_success
'multiple unset is correct' '
306 test_cmp expect .git/config
309 cp .git
/config2 .git
/config
311 test_expect_success
'--replace-all missing value' '
312 test_must_fail git config ${mode_replace_all} beta.haha &&
313 test_cmp .git/config2 .git/config
318 test_expect_success
'--replace-all' '
319 git config ${mode_replace_all} beta.haha gamma
323 [beta] ; silly comment # another comment
324 noIndent= sillyValue ; 'nother silly comment
329 [nextSection] noNewline = ouch
332 test_expect_success
'all replaced' '
333 test_cmp expect .git/config
337 [beta] ; silly comment # another comment
338 noIndent= sillyValue ; 'nother silly comment
343 [nextSection] noNewline = ouch
345 test_expect_success
'really mean test' '
346 git config ${mode_set} beta.haha alpha &&
347 test_cmp expect .git/config
351 [beta] ; silly comment # another comment
352 noIndent= sillyValue ; 'nother silly comment
360 test_expect_success
'really really mean test' '
361 git config ${mode_set} nextsection.nonewline wow &&
362 test_cmp expect .git/config
365 test_expect_success
'get value' '
366 test_cmp_config alpha beta.haha
370 [beta] ; silly comment # another comment
371 noIndent= sillyValue ; 'nother silly comment
378 test_expect_success
'unset' '
379 git config ${mode_unset} beta.haha &&
380 test_cmp expect .git/config
384 [beta] ; silly comment # another comment
385 noIndent= sillyValue ; 'nother silly comment
391 NoNewLine = wow2 for me
393 test_expect_success
'multivar' '
394 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
395 test_cmp expect .git/config
398 test_expect_success
'non-match' '
399 git config --get nextsection.nonewline !for
402 test_expect_success
'non-match value' '
403 test_cmp_config wow --get nextsection.nonewline !for
406 test_expect_success
'multi-valued get returns final one' '
407 test_cmp_config "wow2 for me" --get nextsection.nonewline
410 test_expect_success
'multi-valued get-all returns all' '
411 cat >expect <<-\EOF &&
415 git config ${mode_get_all} nextsection.nonewline >actual &&
416 test_cmp expect actual
420 [beta] ; silly comment # another comment
421 noIndent= sillyValue ; 'nother silly comment
427 NoNewLine = wow2 for me
429 test_expect_success
'multivar replace' '
430 git config nextsection.nonewline "wow3" "wow$" &&
431 test_cmp expect .git/config
434 test_expect_success
'ambiguous unset' '
435 test_must_fail git config ${mode_unset} nextsection.nonewline
438 test_expect_success
'invalid unset' '
439 test_must_fail git config ${mode_unset} somesection.nonewline
443 [beta] ; silly comment # another comment
444 noIndent= sillyValue ; 'nother silly comment
449 NoNewLine = wow2 for me
452 test_expect_success
'multivar unset' '
455 git config --unset nextsection.nonewline "wow3$";;
457 git config unset --value="wow3$" nextsection.nonewline;;
459 test_cmp expect .git/config
462 test_expect_success
'invalid key' 'test_must_fail git config inval.2key blabla'
464 test_expect_success
'correct key' 'git config 123456.a123 987'
466 test_expect_success
'hierarchical section' '
467 git config Version.1.2.3eX.Alpha beta
471 [beta] ; silly comment # another comment
472 noIndent= sillyValue ; 'nother silly comment
477 NoNewLine = wow2 for me
484 test_expect_success
'hierarchical section value' '
485 test_cmp expect .git/config
489 beta.noindent=sillyValue
490 nextsection.nonewline=wow2 for me
492 version.1.2.3eX.alpha=beta
495 test_expect_success
'working --list' '
496 git config ${mode_prefix}list > output &&
497 test_cmp expect output
499 test_expect_success
'--list without repo produces empty output' '
500 git --git-dir=nonexistent config ${mode_prefix}list >output &&
501 test_must_be_empty output
506 nextsection.nonewline
508 version.1.2.3eX.alpha
511 test_expect_success
'--name-only --list' '
512 git config ${mode_prefix}list --name-only >output &&
513 test_cmp expect output
517 beta.noindent sillyValue
518 nextsection.nonewline wow2 for me
521 test_expect_success
'--get-regexp' '
522 git config ${mode_get_regexp} in >output &&
523 test_cmp expect output
528 nextsection.nonewline
531 test_expect_success
'--name-only --get-regexp' '
532 git config ${mode_get_regexp} --name-only in >output &&
533 test_cmp expect output
541 test_expect_success
'--add' '
542 git config --add nextsection.nonewline "wow4 for you" &&
543 git config ${mode_get_all} nextsection.nonewline > output &&
544 test_cmp expect output
547 cat > .git
/config
<< EOF
554 test_expect_success
'get variable with no value' '
555 git config --get novalue.variable ^$
558 test_expect_success
'get variable with empty value' '
559 git config --get emptyvalue.variable ^$
562 echo novalue.variable
> expect
564 test_expect_success
'get-regexp variable with no value' '
565 git config ${mode_get_regexp} novalue > output &&
566 test_cmp expect output
569 echo 'novalue.variable true' > expect
571 test_expect_success
'get-regexp --bool variable with no value' '
572 git config ${mode_get_regexp} --bool novalue > output &&
573 test_cmp expect output
576 echo 'emptyvalue.variable ' > expect
578 test_expect_success
'get-regexp variable with empty value' '
579 git config ${mode_get_regexp} emptyvalue > output &&
580 test_cmp expect output
585 test_expect_success
'get bool variable with no value' '
586 git config --bool novalue.variable > output &&
587 test_cmp expect output
592 test_expect_success
'get bool variable with empty value' '
593 git config --bool emptyvalue.variable > output &&
594 test_cmp expect output
597 test_expect_success
'no arguments, but no crash' '
598 test_must_fail git config >output 2>&1 &&
599 echo "error: no action specified" >expect &&
600 test_cmp expect output
603 cat > .git
/config
<< EOF
615 test_expect_success
'new section is partial match of another' '
617 test_cmp expect .git/config
630 test_expect_success
'new variable inserts into proper section' '
633 test_cmp expect .git/config
636 test_expect_success
'alternative --file (non-existing file should fail)' '
637 test_must_fail git config --file non-existing-config -l &&
638 test_must_fail git config --file non-existing-config test.xyzzy
641 cat > other-config
<< EOF
650 test_expect_success
'alternative GIT_CONFIG' '
651 GIT_CONFIG=other-config git config ${mode_prefix}list >output &&
652 test_cmp expect output
655 test_expect_success
'alternative GIT_CONFIG (--file)' '
656 git config ${mode_prefix}list --file other-config >output &&
657 test_cmp expect output
660 test_expect_success
'alternative GIT_CONFIG (--file=-)' '
661 git config ${mode_prefix}list --file - <other-config >output &&
662 test_cmp expect output
665 test_expect_success
'setting a value in stdin is an error' '
666 test_must_fail git config --file - some.value foo
669 test_expect_success
'editing stdin is an error' '
670 test_must_fail git config ${mode_prefix}edit --file -
673 test_expect_success
'refer config from subdirectory' '
674 test_when_finished "rm -r x" &&
676 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
686 test_expect_success
'--set in alternative file' '
687 git config --file=other-config anwohner.park ausweis &&
688 test_cmp expect other-config
691 cat > .git
/config
<< EOF
698 [branch "1 234 blabl/a"]
702 test_expect_success
'rename section' '
703 git config ${mode_prefix}rename-section branch.eins branch.zwei
713 [branch "1 234 blabl/a"]
717 test_expect_success
'rename succeeded' '
718 test_cmp expect .git/config
721 test_expect_success
'rename non-existing section' '
722 test_must_fail git config ${mode_prefix}rename-section \
723 branch."world domination" branch.drei
726 test_expect_success
'rename succeeded' '
727 test_cmp expect .git/config
730 test_expect_success
'rename another section' '
731 git config ${mode_prefix}rename-section branch."1 234 blabl/a" branch.drei
745 test_expect_success
'rename succeeded' '
746 test_cmp expect .git/config
749 cat >> .git
/config
<< EOF
750 [branch "vier"] z = 1
753 test_expect_success
'rename a section with a var on the same line' '
754 git config ${mode_prefix}rename-section branch.vier branch.zwei
770 test_expect_success
'rename succeeded' '
771 test_cmp expect .git/config
774 test_expect_success
'renaming empty section name is rejected' '
775 test_must_fail git config ${mode_prefix}rename-section branch.zwei ""
778 test_expect_success
'renaming to bogus section is rejected' '
779 test_must_fail git config ${mode_prefix}rename-section branch.zwei "bogus name"
782 test_expect_success
'renaming a section with a long line' '
785 printf " c = d %1024s [a] e = f\\n" " " &&
786 printf "[a] g = h\\n"
788 git config ${mode_prefix}rename-section -f y a xyz &&
789 test_must_fail git config -f y b.e
792 test_expect_success
'renaming an embedded section with a long line' '
795 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
796 printf "[a] g = h\\n"
798 git config ${mode_prefix}rename-section -f y a xyz &&
799 test_must_fail git config -f y foo.e
802 test_expect_success
'renaming a section with an overly-long line' '
805 printf " c = d %525000s e" " " &&
806 printf "[a] g = h\\n"
808 test_must_fail git config ${mode_prefix}rename-section -f y a xyz 2>err &&
809 grep "refusing to work with overly long line in .y. on line 2" err
812 cat >> .git
/config
<< EOF
813 [branch "zwei"] a = 1 [branch "vier"]
816 test_expect_success
'remove section' '
817 git config ${mode_prefix}remove-section branch.zwei
827 test_expect_success
'section was removed properly' '
828 test_cmp expect .git/config
834 dbname = %Ggitcvs2.%a.%m.sqlite
836 dbname = %Ggitcvs1.%a.%m.sqlite
839 test_expect_success
'section ending' '
841 git config ${mode_set} gitcvs.enabled true &&
842 git config ${mode_set} gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
843 git config ${mode_set} gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
844 test_cmp expect .git/config
848 test_expect_success numbers
'
849 git config ${mode_set} kilo.gram 1k &&
850 git config ${mode_set} mega.ton 1m &&
852 echo 1048576 >>expect &&
853 git config --int --get kilo.gram >actual &&
854 git config --int --get mega.ton >>actual &&
855 test_cmp expect actual
858 test_expect_success
'--int is at least 64 bits' '
859 git config ${mode_set} giga.watts 121g &&
861 test_cmp_config 129922760704 --int --get giga.watts
864 test_expect_success
'invalid unit' '
865 git config ${mode_set} aninvalid.unit "1auto" &&
866 test_cmp_config 1auto aninvalid.unit &&
867 test_must_fail git config --int --get aninvalid.unit 2>actual &&
868 test_grep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
871 test_expect_success
'invalid unit boolean' '
872 git config ${mode_set} commit.gpgsign "1true" &&
873 test_cmp_config 1true commit.gpgsign &&
874 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
875 test_grep "bad boolean config value .1true. for .commit.gpgsign." actual
878 test_expect_success
'line number is reported correctly' '
879 printf "[bool]\n\tvar\n" >invalid &&
880 test_must_fail git config -f invalid --path bool.var 2>actual &&
881 test_grep "line 2" actual
884 test_expect_success
'invalid stdin config' '
885 echo "[broken" | test_must_fail git config ${mode_prefix}list --file - >output 2>&1 &&
886 test_grep "bad config line 1 in standard input" output
900 test_expect_success bool
'
902 git config ${mode_set} bool.true1 01 &&
903 git config ${mode_set} bool.true2 -1 &&
904 git config ${mode_set} bool.true3 YeS &&
905 git config ${mode_set} bool.true4 true &&
906 git config ${mode_set} bool.false1 000 &&
907 git config ${mode_set} bool.false2 "" &&
908 git config ${mode_set} bool.false3 nO &&
909 git config ${mode_set} bool.false4 FALSE &&
913 git config --bool --get bool.true$i >>result &&
914 git config --bool --get bool.false$i >>result || return 1
916 test_cmp expect result'
918 test_expect_success
'invalid bool (--get)' '
920 git config ${mode_set} bool.nobool foobar &&
921 test_must_fail git config --bool --get bool.nobool'
923 test_expect_success
'invalid bool (set)' '
925 test_must_fail git config --bool bool.nobool foobar'
939 test_expect_success
'set --bool' '
942 git config --bool bool.true1 01 &&
943 git config --bool bool.true2 -1 &&
944 git config --bool bool.true3 YeS &&
945 git config --bool bool.true4 true &&
946 git config --bool bool.false1 000 &&
947 git config --bool bool.false2 "" &&
948 git config --bool bool.false3 nO &&
949 git config --bool bool.false4 FALSE &&
950 test_cmp expect .git/config'
959 test_expect_success
'set --int' '
962 git config --int int.val1 01 &&
963 git config --int int.val2 -1 &&
964 git config --int int.val3 5m &&
965 test_cmp expect .git/config
968 test_expect_success
'get --bool-or-int' '
969 cat >.git/config <<-\EOF &&
979 cat >expect <<-\EOF &&
988 git config --bool-or-int bool.true1 &&
989 git config --bool-or-int bool.true2 &&
990 git config --bool-or-int bool.false &&
991 git config --bool-or-int int.int1 &&
992 git config --bool-or-int int.int2 &&
993 git config --bool-or-int int.int3
995 test_cmp expect actual
1010 test_expect_success
'set --bool-or-int' '
1011 rm -f .git/config &&
1012 git config --bool-or-int bool.true1 true &&
1013 git config --bool-or-int bool.false1 false &&
1014 git config --bool-or-int bool.true2 yes &&
1015 git config --bool-or-int bool.false2 no &&
1016 git config --bool-or-int int.int1 0 &&
1017 git config --bool-or-int int.int2 1 &&
1018 git config --bool-or-int int.int3 -1 &&
1019 test_cmp expect .git/config
1026 trailingtilde
= foo~
1029 test_expect_success
!MINGW
'set --path' '
1030 rm -f .git/config &&
1031 git config --path path.home "~/" &&
1032 git config --path path.normal "/dev/null" &&
1033 git config --path path.trailingtilde "foo~" &&
1034 test_cmp expect .git/config'
1036 if test_have_prereq
!MINGW
&& test "${HOME+set}"
1038 test_set_prereq HOMEVAR
1047 test_expect_success HOMEVAR
'get --path' '
1048 git config --get --path path.home > result &&
1049 git config --get --path path.normal >> result &&
1050 git config --get --path path.trailingtilde >> result &&
1051 test_cmp expect result
1059 test_expect_success
!MINGW
'get --path copes with unset $HOME' '
1062 test_must_fail git config --get --path path.home \
1064 git config --get --path path.normal >>result &&
1065 git config --get --path path.trailingtilde >>result
1067 test_grep "[Ff]ailed to expand.*~/" msg &&
1068 test_cmp expect result
1071 test_expect_success
'get --path barfs on boolean variable' '
1072 echo "[path]bool" >.git/config &&
1073 test_must_fail git config --get --path path.bool
1076 test_expect_success
'get --expiry-date' '
1077 rel="3.weeks.5.days.00:00" &&
1078 rel_out="$rel ->" &&
1079 cat >.git/config <<-\EOF &&
1081 valid1 = "3.weeks.5.days 00:00"
1082 valid2 = "Fri Jun 4 15:46:55 2010"
1083 valid3 = "2017/11/11 11:11:11PM"
1084 valid4 = "2017/11/10 09:08:07 PM"
1088 cat >expect <<-EOF &&
1089 $(test-tool date timestamp $rel)
1095 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
1097 echo "$rel_out $(git config --expiry-date date.valid1)" &&
1098 git config --expiry-date date.valid2 &&
1099 git config --expiry-date date.valid3 &&
1100 git config --expiry-date date.valid4 &&
1101 git config --expiry-date date.valid5
1103 test_cmp expect actual &&
1104 test_must_fail git config --expiry-date date.invalid1
1107 test_expect_success
'get --type=color' '
1109 git config ${mode_set} foo.color "red" &&
1110 git config --get --type=color foo.color >actual.raw &&
1111 test_decode_color <actual.raw >actual &&
1112 echo "<RED>" >expect &&
1113 test_cmp expect actual
1121 test_expect_success
'set --type=color' '
1123 git config --type=color foo.color "red" &&
1124 test_cmp expect .git/config
1127 test_expect_success
'get --type=color barfs on non-color' '
1128 echo "[foo]bar=not-a-color" >.git/config &&
1129 test_must_fail git config --get --type=color foo.bar
1132 test_expect_success
'set --type=color barfs on non-color' '
1133 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
1134 test_grep "cannot parse color" error
1141 semicolon = "test;test"
1144 test_expect_success
'quoting' '
1145 rm -f .git/config &&
1146 git config ${mode_set} quote.leading " test" &&
1147 git config ${mode_set} quote.ending "test " &&
1148 git config ${mode_set} quote.semicolon "test;test" &&
1149 git config ${mode_set} quote.hash "test#test" &&
1150 test_cmp expect .git/config
1153 test_expect_success
'key with newline' '
1154 test_must_fail git config ${mode_get} "key.with
1157 test_expect_success
'value with newline' 'git config ${mode_set} key.sub value.with\\\
1160 cat > .git
/config
<<\EOF
1165 noncont
= not continued
; \
1171 section.continued
=continued
1172 section.noncont
=not continued
1173 section.quotecont
=cont
;inued
1176 test_expect_success
'value continued on next line' '
1177 git config ${mode_prefix}list > result &&
1178 test_cmp expect result
1181 cat > .git
/config
<<\EOF
1182 [section
"sub=section"]
1191 section.sub
=section.val1
1192 foo
=barQsection.sub
=section.val2
1194 barQsection.sub
=section.val3
1197 Qsection.sub
=section.val4
1198 Qsection.sub
=section.val5Q
1200 test_expect_success
'--null --list' '
1201 git config ${mode_prefix}list --null >result.raw &&
1202 nul_to_q <result.raw >result &&
1204 test_cmp expect result
1207 test_expect_success
'--null --get-regexp' '
1208 git config ${mode_get_regexp} --null "val[0-9]" >result.raw &&
1209 nul_to_q <result.raw >result &&
1211 test_cmp expect result
1214 test_expect_success
'inner whitespace kept verbatim, spaces only' '
1215 echo "foo bar" >expect &&
1216 git config ${mode_set} section.val "foo bar" &&
1217 git config ${mode_get} section.val >actual &&
1218 test_cmp expect actual
1221 test_expect_success
'inner whitespace kept verbatim, horizontal tabs only' '
1222 echo "fooQQbar" | q_to_tab >expect &&
1223 git config ${mode_set} section.val "$(cat expect)" &&
1224 git config ${mode_get} section.val >actual &&
1225 test_cmp expect actual
1228 test_expect_success
'inner whitespace kept verbatim, horizontal tabs and spaces' '
1229 echo "foo Q bar" | q_to_tab >expect &&
1230 git config ${mode_set} section.val "$(cat expect)" &&
1231 git config ${mode_get} section.val >actual &&
1232 test_cmp expect actual
1235 test_expect_success SYMLINKS
'symlinked configuration' '
1236 test_when_finished "rm myconfig" &&
1237 ln -s notyet myconfig &&
1238 git config --file=myconfig test.frotz nitfol &&
1241 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1242 git config --file=myconfig test.xyzzy rezrov &&
1245 cat >expect <<-\EOF &&
1250 git config --file=notyet test.frotz &&
1251 git config --file=notyet test.xyzzy
1253 test_cmp expect actual
1256 test_expect_success SYMLINKS
'symlink to nonexistent configuration' '
1257 test_when_finished "rm linktonada linktolinktonada" &&
1258 ln -s doesnotexist linktonada &&
1259 ln -s linktonada linktolinktonada &&
1260 test_must_fail git config ${mode_prefix}list --file=linktonada &&
1261 test_must_fail git config ${mode_prefix}list --file=linktolinktonada
1264 test_expect_success
'check split_cmdline return' '
1265 test_when_finished "rm -rf repo" &&
1269 git config ${mode_set} alias.split-cmdline-fix "echo \"" &&
1270 test_must_fail git split-cmdline-fix &&
1273 git commit -m "initial commit" &&
1274 git config ${mode_set} branch.main.mergeoptions "echo \"" &&
1275 test_must_fail git merge main
1279 test_expect_success
'git -c "key=value" support' '
1280 cat >expect <<-\EOF &&
1286 git -c section.name=value config section.name &&
1287 git -c foo.CamelCase=value config foo.camelcase &&
1288 git -c foo.flag config --bool foo.flag
1290 test_cmp expect actual &&
1291 test_must_fail git -c name=value config section.name
1294 # We just need a type-specifier here that cares about the
1295 # distinction internally between a NULL boolean and a real
1296 # string (because most of git's internal parsers do care).
1297 # Using "--path" works, but we do not otherwise care about
1299 test_expect_success
'git -c can represent empty string' '
1301 git -c foo.empty= config --path foo.empty >actual &&
1302 test_cmp expect actual
1305 test_expect_success
'key sanity-checking' '
1306 test_must_fail git config ${mode_get} foo=bar &&
1307 test_must_fail git config ${mode_get} foo=.bar &&
1308 test_must_fail git config ${mode_get} foo.ba=r &&
1309 test_must_fail git config ${mode_get} foo.1bar &&
1310 test_must_fail git config ${mode_get} foo."ba
1312 test_must_fail git config ${mode_set} . false &&
1313 test_must_fail git config ${mode_set} .foo false &&
1314 test_must_fail git config ${mode_set} foo. false &&
1315 test_must_fail git config ${mode_set} .foo. false &&
1316 git config ${mode_set} foo.bar true &&
1317 git config ${mode_set} foo."ba =z".bar false
1320 test_expect_success
'git -c works with aliases of builtins' '
1321 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1323 git checkconfig >actual &&
1324 test_cmp expect actual
1327 test_expect_success
'aliases can be CamelCased' '
1328 test_when_finished "rm -rf repo" &&
1333 git config alias.CamelCased "rev-parse HEAD" &&
1334 git CamelCased >out &&
1335 git rev-parse HEAD >expect &&
1340 test_expect_success
'git -c does not split values on equals' '
1341 echo "value with = in it" >expect &&
1342 git -c section.foo="value with = in it" config section.foo >actual &&
1343 test_cmp expect actual
1346 test_expect_success
'git -c dies on bogus config' '
1347 test_must_fail git -c core.bare=foo rev-parse
1350 test_expect_success
'git -c complains about empty key' '
1351 test_must_fail git -c "=foo" rev-parse
1354 test_expect_success
'git -c complains about empty key and value' '
1355 test_must_fail git -c "" rev-parse
1358 test_expect_success
'multiple git -c appends config' '
1359 test_config alias.x "!git -c x.two=2 config ${mode_get_regexp} ^x\.*" &&
1360 cat >expect <<-\EOF &&
1364 git -c x.one=1 x >actual &&
1365 test_cmp expect actual
1368 test_expect_success
'last one wins: two level vars' '
1370 # sec.var and sec.VAR are the same variable, as the first
1371 # and the last level of a configuration variable name is
1376 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1377 test_cmp expect actual &&
1378 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1379 test_cmp expect actual &&
1381 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1382 test_cmp expect actual &&
1383 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1384 test_cmp expect actual
1387 test_expect_success
'last one wins: three level vars' '
1389 # v.a.r and v.A.r are not the same variable, as the middle
1390 # level of a three-level configuration variable name is
1394 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1395 test_cmp expect actual &&
1396 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1397 test_cmp expect actual &&
1399 # v.a.r and V.a.R are the same variable, as the first
1400 # and the last level of a configuration variable name is
1404 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1405 test_cmp expect actual &&
1406 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1407 test_cmp expect actual &&
1408 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1409 test_cmp expect actual &&
1410 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1411 test_cmp expect actual
1414 test_expect_success
'old-fashioned settings are case insensitive' '
1415 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1417 cat >testConfig_actual <<-EOF &&
1421 q_to_tab >testConfig_expect <<-EOF &&
1425 git config -f testConfig_actual "v.a.r" value2 &&
1426 test_cmp testConfig_expect testConfig_actual &&
1428 cat >testConfig_actual <<-EOF &&
1432 q_to_tab >testConfig_expect <<-EOF &&
1436 git config -f testConfig_actual "V.a.R" value2 &&
1437 test_cmp testConfig_expect testConfig_actual &&
1439 cat >testConfig_actual <<-EOF &&
1443 q_to_tab >testConfig_expect <<-EOF &&
1448 git config -f testConfig_actual "V.A.r" value2 &&
1449 test_cmp testConfig_expect testConfig_actual &&
1451 cat >testConfig_actual <<-EOF &&
1455 q_to_tab >testConfig_expect <<-EOF &&
1460 git config -f testConfig_actual "v.A.r" value2 &&
1461 test_cmp testConfig_expect testConfig_actual
1464 test_expect_success
'setting different case sensitive subsections ' '
1465 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1467 cat >testConfig_actual <<-EOF &&
1477 q_to_tab >testConfig_expect <<-EOF &&
1490 git config -f testConfig_actual a.b.c v2 &&
1491 # match section and subsection, key is cased differently.
1492 git config -f testConfig_actual K.E.y v2 &&
1493 # section and key are matched case insensitive, but subsection needs
1494 # to match; When writing out new values only the key is adjusted
1495 git config -f testConfig_actual v.A.r v2 &&
1496 # subsection is not matched:
1497 git config -f testConfig_actual d.E.f v2 &&
1498 test_cmp testConfig_expect testConfig_actual
1501 for VAR
in a .a a. a
.0b a.
"b c". a.
"b c".0d
1503 test_expect_success
"git -c $VAR=VAL rejects invalid '$VAR'" '
1504 test_must_fail git -c "$VAR=VAL" config -l
1508 for VAR
in a.b a.
"b c".d
1510 test_expect_success
"git -c $VAR=VAL works with valid '$VAR'" '
1512 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1513 test_cmp expect actual
1517 test_expect_success
'git -c is not confused by empty environment' '
1518 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config ${mode_prefix}list
1521 test_expect_success
'GIT_CONFIG_PARAMETERS handles old-style entries' '
1522 v="${SQ}key.one=foo${SQ}" &&
1523 v="$v ${SQ}key.two=bar${SQ}" &&
1524 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1525 GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1526 cat >expect <<-EOF &&
1529 key.ambiguous section.whatever=value
1531 test_cmp expect actual
1534 test_expect_success
'GIT_CONFIG_PARAMETERS handles new-style entries' '
1535 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1536 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1537 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1538 GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1539 cat >expect <<-EOF &&
1542 key.ambiguous=section.whatever value
1544 test_cmp expect actual
1547 test_expect_success
'old and new-style entries can mix' '
1548 v="${SQ}key.oldone=oldfoo${SQ}" &&
1549 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1550 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1551 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1552 GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1553 cat >expect <<-EOF &&
1559 test_cmp expect actual
1562 test_expect_success
'old and new bools with ambiguous subsection' '
1563 v="${SQ}key.with=equals.oldbool${SQ}" &&
1564 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1565 GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1566 cat >expect <<-EOF &&
1567 key.with equals.oldbool
1568 key.with=equals.newbool
1570 test_cmp expect actual
1573 test_expect_success
'detect bogus GIT_CONFIG_PARAMETERS' '
1574 cat >expect <<-\EOF &&
1578 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1579 git config ${mode_get_regexp} "env.*" >actual &&
1580 test_cmp expect actual &&
1582 cat >expect <<-EOF &&
1586 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1587 git config ${mode_get_regexp} "env.*" >actual &&
1588 test_cmp expect actual &&
1590 test_must_fail env \
1591 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1592 git config ${mode_get_regexp} "env.*"
1595 test_expect_success
'git --config-env=key=envvar support' '
1596 cat >expect <<-\EOF &&
1605 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1606 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1607 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1608 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1609 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1610 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1612 test_cmp expect actual
1615 test_expect_success
'git --config-env with missing value' '
1616 test_must_fail env ENVVAR=value git --config-env 2>error &&
1617 grep "no config key given for --config-env" error &&
1618 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1619 grep "invalid config format: config" error
1622 test_expect_success
'git --config-env fails with invalid parameters' '
1623 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1624 test_grep "invalid config format: foo.flag" error &&
1625 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1626 test_grep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1627 sane_unset NONEXISTENT &&
1628 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1629 test_grep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1632 test_expect_success
'git -c and --config-env work together' '
1633 cat >expect <<-\EOF &&
1637 ENVVAR=env-value git \
1638 -c bar.cmd=cmd-value \
1639 --config-env=bar.env=ENVVAR \
1640 config ${mode_get_regexp} "^bar.*" >actual &&
1641 test_cmp expect actual
1644 test_expect_success
'git -c and --config-env override each other' '
1645 cat >expect <<-\EOF &&
1650 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1651 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1653 test_cmp expect actual
1656 test_expect_success
'--config-env handles keys with equals' '
1657 echo value=with=equals >expect &&
1658 ENVVAR=value=with=equals git \
1659 --config-env=section.subsection=with=equals.key=ENVVAR \
1660 config section.subsection=with=equals.key >actual &&
1661 test_cmp expect actual
1664 test_expect_success
'git config handles environment config pairs' '
1665 GIT_CONFIG_COUNT=2 \
1666 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1667 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1668 git config ${mode_get_regexp} "pair.*" >actual &&
1669 cat >expect <<-EOF &&
1673 test_cmp expect actual
1676 test_expect_success
'git config ignores pairs without count' '
1677 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1678 git config ${mode_get} pair.one 2>error &&
1679 test_must_be_empty error
1682 test_expect_success
'git config ignores pairs exceeding count' '
1683 GIT_CONFIG_COUNT=1 \
1684 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1685 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1686 git config ${mode_get_regexp} "pair.*" >actual 2>error &&
1687 cat >expect <<-EOF &&
1690 test_cmp expect actual &&
1691 test_must_be_empty error
1694 test_expect_success
'git config ignores pairs with zero count' '
1695 test_must_fail env \
1696 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1697 git config ${mode_get} pair.one 2>error &&
1698 test_must_be_empty error
1701 test_expect_success
'git config ignores pairs with empty count' '
1702 test_must_fail env \
1703 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1704 git config ${mode_get} pair.one 2>error &&
1705 test_must_be_empty error
1708 test_expect_success
'git config fails with invalid count' '
1709 test_must_fail env GIT_CONFIG_COUNT=10a git config ${mode_prefix}list 2>error &&
1710 test_grep "bogus count" error &&
1711 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config ${mode_prefix}list 2>error &&
1712 test_grep "too many entries" error
1715 test_expect_success
'git config fails with missing config key' '
1716 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1717 git config ${mode_prefix}list 2>error &&
1718 test_grep "missing config key" error
1721 test_expect_success
'git config fails with missing config value' '
1722 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1723 git config ${mode_prefix}list 2>error &&
1724 test_grep "missing config value" error
1727 test_expect_success
'git config fails with invalid config pair key' '
1728 test_must_fail env GIT_CONFIG_COUNT=1 \
1729 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1730 git config ${mode_prefix}list &&
1731 test_must_fail env GIT_CONFIG_COUNT=1 \
1732 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1733 git config ${mode_prefix}list
1736 test_expect_success
'environment overrides config file' '
1737 test_when_finished "rm -f .git/config" &&
1738 cat >.git/config <<-EOF &&
1742 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1743 git config ${mode_get} pair.one >actual &&
1744 cat >expect <<-EOF &&
1747 test_cmp expect actual
1750 test_expect_success
'GIT_CONFIG_PARAMETERS overrides environment config' '
1751 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1752 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1753 git config ${mode_get} pair.one >actual &&
1754 cat >expect <<-EOF &&
1757 test_cmp expect actual
1760 test_expect_success
'command line overrides environment config' '
1761 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1762 git -c pair.one=override config pair.one >actual &&
1763 cat >expect <<-EOF &&
1766 test_cmp expect actual
1769 test_expect_success
'git config --edit works' '
1770 git config -f tmp test.value no &&
1771 echo test.value=yes >expect &&
1772 GIT_EDITOR="echo [test]value=yes >" git config ${mode_prefix}edit -f tmp &&
1773 git config ${mode_prefix}list -f tmp >actual &&
1774 test_cmp expect actual
1777 test_expect_success
'git config --edit respects core.editor' '
1778 git config -f tmp test.value no &&
1779 echo test.value=yes >expect &&
1780 test_config core.editor "echo [test]value=yes >" &&
1781 git config ${mode_prefix}edit -f tmp &&
1782 git config ${mode_prefix}list -f tmp >actual &&
1783 test_cmp expect actual
1786 # malformed configuration files
1787 test_expect_success
'barf on syntax error' '
1788 cat >.git/config <<-\EOF &&
1793 test_must_fail git config --get section.key 2>error &&
1794 test_grep " line 3 " error
1797 test_expect_success
'barf on incomplete section header' '
1798 cat >.git/config <<-\EOF &&
1799 # broken section line
1803 test_must_fail git config --get section.key 2>error &&
1804 test_grep " line 2 " error
1807 test_expect_success
'barf on incomplete string' '
1808 cat >.git/config <<-\EOF &&
1809 # broken value string
1813 test_must_fail git config --get section.key 2>error &&
1814 test_grep " line 3 " error
1817 test_expect_success
'urlmatch' '
1818 cat >.git/config <<-\EOF &&
1821 [http "https://weak.example.com"]
1823 cookieFile = /tmp/cookie.txt
1826 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1827 test_must_be_empty actual &&
1828 test_expect_code 1 git config get --url=https://good.example.com --bool doesnt.exist >actual &&
1829 test_must_be_empty actual &&
1831 echo true >expect &&
1832 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1833 test_cmp expect actual &&
1834 git config get --bool --url=https://good.example.com http.SSLverify >actual &&
1835 test_cmp expect actual &&
1837 echo false >expect &&
1838 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1839 test_cmp expect actual &&
1840 git config get --bool --url=https://weak.example.com http.sslverify >actual &&
1841 test_cmp expect actual &&
1844 echo http.cookiefile /tmp/cookie.txt &&
1845 echo http.sslverify false
1847 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1848 test_cmp expect actual &&
1849 git config get --url=https://weak.example.com HTTP >actual &&
1850 test_cmp expect actual
1853 test_expect_success
'urlmatch with --show-scope' '
1854 cat >.git/config <<-\EOF &&
1855 [http "https://weak.example.com"]
1857 cookieFile = /tmp/cookie.txt
1860 cat >expect <<-EOF &&
1861 local http.cookiefile /tmp/cookie.txt
1862 local http.sslverify false
1864 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1865 test_cmp expect actual &&
1866 git config get --url=https://weak.example.com --show-scope HTTP >actual &&
1867 test_cmp expect actual
1870 test_expect_success
'urlmatch favors more specific URLs' '
1871 cat >.git/config <<-\EOF &&
1872 [http "https://example.com/"]
1873 cookieFile = /tmp/root.txt
1874 [http "https://example.com/subdirectory"]
1875 cookieFile = /tmp/subdirectory.txt
1876 [http "https://user@example.com/"]
1877 cookieFile = /tmp/user.txt
1878 [http "https://averylonguser@example.com/"]
1879 cookieFile = /tmp/averylonguser.txt
1880 [http "https://preceding.example.com"]
1881 cookieFile = /tmp/preceding.txt
1882 [http "https://*.example.com"]
1883 cookieFile = /tmp/wildcard.txt
1884 [http "https://*.example.com/wildcardwithsubdomain"]
1885 cookieFile = /tmp/wildcardwithsubdomain.txt
1886 [http "https://*.example.*"]
1887 cookieFile = /tmp/multiwildcard.txt
1888 [http "https://trailing.example.com"]
1889 cookieFile = /tmp/trailing.txt
1890 [http "https://user@*.example.com/"]
1891 cookieFile = /tmp/wildcardwithuser.txt
1892 [http "https://sub.example.com/"]
1893 cookieFile = /tmp/sub.txt
1896 echo http.cookiefile /tmp/root.txt >expect &&
1897 git config --get-urlmatch HTTP https://example.com >actual &&
1898 test_cmp expect actual &&
1899 git config get --url=https://example.com HTTP >actual &&
1900 test_cmp expect actual &&
1902 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1903 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1904 test_cmp expect actual &&
1905 git config get --url=https://example.com/subdirectory HTTP >actual &&
1906 test_cmp expect actual &&
1908 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1909 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1910 test_cmp expect actual &&
1911 git config get --url=https://example.com/subdirectory/nested HTTP >actual &&
1912 test_cmp expect actual &&
1914 echo http.cookiefile /tmp/user.txt >expect &&
1915 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1916 test_cmp expect actual &&
1917 git config get --url=https://user@example.com/ HTTP >actual &&
1918 test_cmp expect actual &&
1920 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1921 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1922 test_cmp expect actual &&
1923 git config get --url=https://averylonguser@example.com/subdirectory HTTP >actual &&
1924 test_cmp expect actual &&
1926 echo http.cookiefile /tmp/preceding.txt >expect &&
1927 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1928 test_cmp expect actual &&
1929 git config get --url=https://preceding.example.com HTTP >actual &&
1930 test_cmp expect actual &&
1932 echo http.cookiefile /tmp/wildcard.txt >expect &&
1933 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1934 test_cmp expect actual &&
1935 git config get --url=https://wildcard.example.com HTTP >actual &&
1936 test_cmp expect actual &&
1938 echo http.cookiefile /tmp/sub.txt >expect &&
1939 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1940 test_cmp expect actual &&
1941 git config get --url=https://sub.example.com/wildcardwithsubdomain HTTP >actual &&
1942 test_cmp expect actual &&
1944 echo http.cookiefile /tmp/trailing.txt >expect &&
1945 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1946 test_cmp expect actual &&
1947 git config get --url=https://trailing.example.com HTTP >actual &&
1948 test_cmp expect actual &&
1950 echo http.cookiefile /tmp/sub.txt >expect &&
1951 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1952 test_cmp expect actual &&
1953 git config get --url=https://user@sub.example.com HTTP >actual &&
1954 test_cmp expect actual &&
1956 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1957 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1958 test_cmp expect actual &&
1959 git config get --url=https://wildcard.example.org HTTP >actual &&
1960 test_cmp expect actual
1963 test_expect_success
'urlmatch with wildcard' '
1964 cat >.git/config <<-\EOF &&
1967 [http "https://*.example.com"]
1969 cookieFile = /tmp/cookie.txt
1972 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1973 test_must_be_empty actual &&
1975 echo true >expect &&
1976 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1977 test_cmp expect actual &&
1979 echo true >expect &&
1980 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1981 test_cmp expect actual &&
1983 echo true >expect &&
1984 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1985 test_cmp expect actual &&
1987 echo false >expect &&
1988 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1989 test_cmp expect actual &&
1992 echo http.cookiefile /tmp/cookie.txt &&
1993 echo http.sslverify false
1995 git config --get-urlmatch HTTP https://good.example.com >actual &&
1996 test_cmp expect actual &&
1998 echo http.sslverify >expect &&
1999 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
2000 test_cmp expect actual
2003 # good section hygiene
2004 test_expect_success
'--unset last key removes section (except if commented)' '
2005 cat >.git/config <<-\EOF &&
2006 # some generic comment on the configuration file itself
2007 # a comment specific to this "section" section.
2009 # some intervening lines
2010 # that should also be dropped
2013 # please be careful when you update the above variable
2016 cat >expect <<-\EOF &&
2017 # some generic comment on the configuration file itself
2018 # a comment specific to this "section" section.
2020 # some intervening lines
2021 # that should also be dropped
2023 # please be careful when you update the above variable
2026 git config ${mode_unset} section.key &&
2027 test_cmp expect .git/config &&
2029 cat >.git/config <<-\EOF &&
2035 cat >expect <<-\EOF &&
2039 git config ${mode_unset} section.key &&
2040 test_cmp expect .git/config &&
2042 q_to_tab >.git/config <<-\EOF &&
2049 git config ${mode_unset} two.key &&
2050 ! grep two .git/config &&
2052 q_to_tab >.git/config <<-\EOF &&
2059 git config ${mode_unset_all} one.key &&
2060 test_line_count = 0 .git/config &&
2062 q_to_tab >.git/config <<-\EOF &&
2065 Q# a comment not at the start
2069 git config ${mode_unset} two.key &&
2070 grep two .git/config &&
2072 q_to_tab >.git/config <<-\EOF &&
2074 Qkey = not [two "subsection"]
2081 git config ${mode_unset} two.subsection.key &&
2082 test "not [two subsection]" = "$(git config ${mode_get} one.key)" &&
2083 test_line_count = 3 .git/config
2086 test_expect_success
'--unset-all removes section if empty & uncommented' '
2087 cat >.git/config <<-\EOF &&
2093 git config ${mode_unset_all} section.key &&
2094 test_line_count = 0 .git/config
2097 test_expect_success
'adding a key into an empty section reuses header' '
2098 cat >.git/config <<-\EOF &&
2102 q_to_tab >expect <<-\EOF &&
2107 git config section.key value &&
2108 test_cmp expect .git/config
2111 test_expect_success POSIXPERM
,PERL
'preserves existing permissions' '
2112 chmod 0600 .git/config &&
2113 git config imap.pass Hunter2 &&
2115 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
2116 git config ${mode_prefix}rename-section imap pop &&
2118 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
2121 ! test_have_prereq MINGW ||
2122 HOME
="$(pwd)" # convert to Windows path
2124 test_expect_success
'set up --show-origin tests' '
2125 INCLUDE_DIR="$HOME/include" &&
2126 mkdir -p "$INCLUDE_DIR" &&
2127 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
2131 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
2135 cat >"$HOME"/.gitconfig <<-EOF &&
2140 path = "$INCLUDE_DIR/absolute.include"
2142 cat >.git/config <<-\EOF
2147 path = ../include/relative.include
2151 test_expect_success
'--show-origin with --list' '
2152 cat >expect <<-EOF &&
2153 file:$HOME/.gitconfig user.global=true
2154 file:$HOME/.gitconfig user.override=global
2155 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2156 file:$INCLUDE_DIR/absolute.include user.absolute=include
2157 file:.git/config user.local=true
2158 file:.git/config user.override=local
2159 file:.git/config include.path=../include/relative.include
2160 file:.git/../include/relative.include user.relative=include
2161 command line: user.environ=true
2162 command line: user.cmdline=true
2164 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
2165 git -c user.cmdline=true config ${mode_prefix}list --show-origin >output &&
2166 test_cmp expect output
2169 test_expect_success
'--show-origin with --list --null' '
2170 cat >expect <<-EOF &&
2171 file:$HOME/.gitconfigQuser.global
2172 trueQfile:$HOME/.gitconfigQuser.override
2173 globalQfile:$HOME/.gitconfigQinclude.path
2174 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
2175 includeQfile:.git/configQuser.local
2176 trueQfile:.git/configQuser.override
2177 localQfile:.git/configQinclude.path
2178 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
2179 includeQcommand line:Quser.cmdline
2182 git -c user.cmdline=true config ${mode_prefix}list --null --show-origin >output.raw &&
2183 nul_to_q <output.raw >output &&
2184 # The here-doc above adds a newline that the --null output would not
2185 # include. Add it here to make the two comparable.
2187 test_cmp expect output
2190 test_expect_success
'--show-origin with single file' '
2191 cat >expect <<-\EOF &&
2192 file:.git/config user.local=true
2193 file:.git/config user.override=local
2194 file:.git/config include.path=../include/relative.include
2196 git config ${mode_prefix}list --local --show-origin >output &&
2197 test_cmp expect output
2200 test_expect_success
'--show-origin with --get-regexp' '
2201 cat >expect <<-EOF &&
2202 file:$HOME/.gitconfig user.global true
2203 file:.git/config user.local true
2205 git config ${mode_get_regexp} --show-origin "user\.[g|l].*" >output &&
2206 test_cmp expect output
2209 test_expect_success
'--show-origin getting a single key' '
2210 cat >expect <<-\EOF &&
2211 file:.git/config local
2213 git config ${mode_get} --show-origin user.override >output &&
2214 test_cmp expect output
2217 test_expect_success
'set up custom config file' '
2218 cat >"custom.conf" <<-\EOF &&
2222 CUSTOM_CONFIG_FILE="$(test-tool path-utils real_path custom.conf)"
2225 test_expect_success
!MINGW
'set up custom config file with special name characters' '
2226 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2227 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2230 test_expect_success
!MINGW
'--show-origin escape special file name characters' '
2231 cat >expect <<-\EOF &&
2232 file:"file\" (dq) and spaces.conf" user.custom=true
2234 git config ${mode_prefix}list --file "$WEIRDLY_NAMED_FILE" --show-origin >output &&
2235 test_cmp expect output
2238 test_expect_success
'--show-origin stdin' '
2239 cat >expect <<-\EOF &&
2240 standard input: user.custom=true
2242 git config ${mode_prefix}list --file - --show-origin <"$CUSTOM_CONFIG_FILE" >output &&
2243 test_cmp expect output
2246 test_expect_success
'--show-origin stdin with file include' '
2247 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2251 cat >expect <<-EOF &&
2252 file:$INCLUDE_DIR/stdin.include include
2254 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2255 git config --show-origin --includes --file - user.stdin >output &&
2257 test_cmp expect output
2260 test_expect_success
'--show-origin blob' '
2261 test_when_finished "rm -rf repo" &&
2265 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2266 cat >expect <<-EOF &&
2267 blob:$blob user.custom=true
2269 git config ${mode_prefix}list --blob=$blob --show-origin >output &&
2270 test_cmp expect output
2274 test_expect_success
'--show-origin blob ref' '
2275 test_when_finished "rm -rf repo" &&
2279 cat >expect <<-\EOF &&
2280 blob:main:custom.conf user.custom=true
2282 cp "$CUSTOM_CONFIG_FILE" custom.conf &&
2283 git add custom.conf &&
2284 git commit -m "new config file" &&
2285 git config ${mode_prefix}list --blob=main:custom.conf --show-origin >output &&
2286 test_cmp expect output
2290 test_expect_success
'--show-origin with --default' '
2291 git config --show-origin --default foo some.key >actual &&
2292 echo "command line: foo" >expect &&
2293 test_cmp expect actual
2296 test_expect_success
'--show-scope with --list' '
2297 cat >expect <<-EOF &&
2298 global user.global=true
2299 global user.override=global
2300 global include.path=$INCLUDE_DIR/absolute.include
2301 global user.absolute=include
2302 local user.local=true
2303 local user.override=local
2304 local include.path=../include/relative.include
2305 local user.relative=include
2306 local core.repositoryformatversion=1
2307 local extensions.worktreeconfig=true
2308 worktree user.worktree=true
2309 command user.cmdline=true
2311 test_when_finished "git worktree remove wt1" &&
2312 git worktree add wt1 &&
2313 # We need these to test for worktree scope, but outside of this
2314 # test, this is just noise
2315 test_config core.repositoryformatversion 1 &&
2316 test_config extensions.worktreeConfig true &&
2317 git config --worktree user.worktree true &&
2318 git -c user.cmdline=true config ${mode_prefix}list --show-scope >output &&
2319 test_cmp expect output
2322 test_expect_success
!MINGW
'--show-scope with --blob' '
2323 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2324 cat >expect <<-EOF &&
2325 command user.custom=true
2327 git config ${mode_prefix}list --blob=$blob --show-scope >output &&
2328 test_cmp expect output
2331 test_expect_success
'--show-scope with --local' '
2332 cat >expect <<-\EOF &&
2333 local user.local=true
2334 local user.override=local
2335 local include.path=../include/relative.include
2337 git config ${mode_prefix}list --local --show-scope >output &&
2338 test_cmp expect output
2341 test_expect_success
'--show-scope getting a single value' '
2342 cat >expect <<-\EOF &&
2345 git config ${mode_get} --show-scope user.local >output &&
2346 test_cmp expect output
2349 test_expect_success
'--show-scope with --show-origin' '
2350 cat >expect <<-EOF &&
2351 global file:$HOME/.gitconfig user.global=true
2352 global file:$HOME/.gitconfig user.override=global
2353 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2354 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2355 local file:.git/config user.local=true
2356 local file:.git/config user.override=local
2357 local file:.git/config include.path=../include/relative.include
2358 local file:.git/../include/relative.include user.relative=include
2359 command command line: user.cmdline=true
2361 git -c user.cmdline=true config ${mode_prefix}list --show-origin --show-scope >output &&
2362 test_cmp expect output
2365 test_expect_success
'--show-scope with --default' '
2366 git config --show-scope --default foo some.key >actual &&
2367 echo "command foo" >expect &&
2368 test_cmp expect actual
2371 test_expect_success
'override global and system config' '
2372 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2373 cat >"$HOME"/.gitconfig <<-EOF &&
2378 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2379 mkdir -p "$HOME"/.config/git &&
2380 cat >"$HOME"/.config/git/config <<-EOF &&
2384 cat >.git/config <<-EOF &&
2388 cat >custom-global-config <<-EOF &&
2392 cat >custom-system-config <<-EOF &&
2397 cat >expect <<-EOF &&
2398 global xdg.config=true
2399 global home.config=true
2400 local local.config=true
2402 git config ${mode_prefix}list --show-scope >output &&
2403 test_cmp expect output &&
2405 cat >expect <<-EOF &&
2406 system system.config=true
2407 global global.config=true
2408 local local.config=true
2410 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2411 git config ${mode_prefix}list --show-scope >output &&
2412 test_cmp expect output &&
2414 cat >expect <<-EOF &&
2415 local local.config=true
2417 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2418 git config ${mode_prefix}list --show-scope >output &&
2419 test_cmp expect output
2422 test_expect_success
'override global and system config with missing file' '
2423 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config ${mode_prefix}list --global &&
2424 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config ${mode_prefix}list --system &&
2425 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2428 test_expect_success
'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2429 # `git config --system` has different semantics compared to other
2430 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2431 # variable has an effect via a different proxy.
2432 cat >alias-config <<-EOF &&
2434 hello-world = !echo "hello world"
2436 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2438 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2439 git hello-world >actual &&
2440 echo "hello world" >expect &&
2441 test_cmp expect actual
2444 test_expect_success
'write to overridden global and system config' '
2445 cat >expect <<EOF &&
2450 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2451 test_cmp expect write-to-global &&
2453 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2454 test_cmp expect write-to-system
2457 for opt
in --local --worktree
2459 test_expect_success
"$opt requires a repo" '
2460 # we expect 128 to ensure that we do not simply
2461 # fail to find anything and return code "1"
2462 test_expect_code 128 nongit git config $opt foo.bar
2466 cat >.git
/config
<<-\EOF &&
2473 test_expect_success 'identical modern --type specifiers are allowed' '
2474 test_cmp_config 1048576 --type=int --type=int section.big
2477 test_expect_success 'identical legacy --type specifiers are allowed' '
2478 test_cmp_config 1048576 --int --int section.big
2481 test_expect_success 'identical mixed --type specifiers are allowed' '
2482 test_cmp_config 1048576 --int --type=int section.big
2485 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2486 test_must_fail git config --type=int --type=bool section.big 2>error &&
2487 test_grep "only one type at a time" error
2490 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2491 test_must_fail git config --int --bool section.big 2>error &&
2492 test_grep "only one type at a time" error
2495 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2496 test_must_fail git config --type=int --bool section.big 2>error &&
2497 test_grep "only one type at a time" error
2500 test_expect_success '--type allows valid type specifiers' '
2501 test_cmp_config true --type=bool section.foo
2504 test_expect_success '--no-type unsets type specifiers' '
2505 test_cmp_config 10 --type=bool --no-type section.number
2508 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2509 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2512 test_expect_success '--type rejects unknown specifiers' '
2513 test_must_fail git config --type=nonsense section.foo 2>error &&
2514 test_grep "unrecognized --type argument" error
2517 test_expect_success '--type=int requires at least one digit' '
2518 test_must_fail git config --type int --default m some.key >out 2>error &&
2519 grep "bad numeric config value" error &&
2520 test_must_be_empty out
2523 test_expect_success '--replace-all does not invent newlines' '
2524 q_to_tab >.git/config <<-\
EOF &&
2532 q_to_tab >expect <<-\EOF &&
2540 git config ${mode_replace_all} abc.key b &&
2541 test_cmp expect .git/config
2544 test_expect_success 'set all config with value-pattern' '
2545 test_when_finished rm -f config initial &&
2546 git config --file=initial abc.key one &&
2548 # no match => add new entry
2549 cp initial config &&
2550 git config --file=config abc.key two a+ &&
2551 git config ${mode_prefix}list --file=config >actual &&
2552 cat >expect <<-\EOF &&
2556 test_cmp expect actual &&
2558 # multiple matches => failure
2559 test_must_fail git config --file=config abc.key three o+ 2>err &&
2560 test_grep "has multiple values" err &&
2562 # multiple values, no match => add
2563 git config --file=config abc.key three a+ &&
2564 git config ${mode_prefix}list --file=config >actual &&
2565 cat >expect <<-\EOF &&
2570 test_cmp expect actual &&
2572 # single match => replace
2573 git config --file=config abc.key four h+ &&
2574 git config ${mode_prefix}list --file=config >actual &&
2575 cat >expect <<-\EOF &&
2580 test_cmp expect actual
2583 test_expect_success '--replace-all and value-pattern' '
2584 test_when_finished rm -f config &&
2585 git config --file=config --add abc.key one &&
2586 git config --file=config --add abc.key two &&
2587 git config --file=config --add abc.key three &&
2588 git config --file=config --replace-all abc.key four "o+" &&
2589 git config ${mode_prefix}list --file=config >actual &&
2590 cat >expect <<-\EOF &&
2594 test_cmp expect actual
2597 test_expect_success 'refuse --fixed-value for incompatible actions' '
2598 test_when_finished rm -f config &&
2599 git config --file=config dev.null bogus &&
2601 # These modes do not allow --fixed-value at all
2602 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2603 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2604 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2605 test_must_fail git config ${mode_prefix}rename-section --file=config --fixed-value dev null &&
2606 test_must_fail git config ${mode_prefix}remove-section --file=config --fixed-value dev &&
2607 test_must_fail git config ${mode_prefix}list --file=config --fixed-value &&
2608 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2609 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2611 # These modes complain when --fixed-value has no value-pattern
2612 test_must_fail git config ${mode_set} --file=config --fixed-value dev.null bogus &&
2613 test_must_fail git config ${mode_replace_all} --file=config --fixed-value dev.null bogus &&
2614 test_must_fail git config ${mode_prefix}get --file=config --fixed-value dev.null &&
2615 test_must_fail git config ${mode_get_all} --file=config --fixed-value dev.null &&
2616 test_must_fail git config ${mode_get_regexp} --file=config --fixed-value "dev.*" &&
2617 test_must_fail git config ${mode_unset} --file=config --fixed-value dev.null &&
2618 test_must_fail git config ${mode_unset_all} --file=config --fixed-value dev.null
2621 test_expect_success '--fixed-value uses exact string matching' '
2622 test_when_finished rm -f config initial &&
2623 META="a+b*c?d[e]f.g" &&
2624 git config --file=initial fixed.test "$META" &&
2626 cp initial config &&
2627 git config --file=config fixed.test bogus "$META" &&
2628 git config ${mode_prefix}list --file=config >actual &&
2629 cat >expect <<-EOF &&
2633 test_cmp expect actual &&
2635 cp initial config &&
2636 git config --file=config --fixed-value fixed.test bogus "$META" &&
2637 git config ${mode_prefix}list --file=config >actual &&
2638 cat >expect <<-\EOF &&
2641 test_cmp expect actual &&
2643 cp initial config &&
2644 test_must_fail git config --file=config --unset fixed.test "$META" &&
2645 git config --file=config --fixed-value --unset fixed.test "$META" &&
2646 test_must_fail git config ${mode_get} --file=config fixed.test &&
2648 cp initial config &&
2649 test_must_fail git config unset --file=config --value="$META" fixed.test &&
2650 git config unset --file=config --fixed-value --value="$META" fixed.test &&
2651 test_must_fail git config ${mode_get} --file=config fixed.test &&
2653 cp initial config &&
2654 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2655 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2656 test_must_fail git config ${mode_get} --file=config fixed.test &&
2658 cp initial config &&
2659 git config --file=config fixed.test bogus "$META" &&
2660 git config ${mode_prefix}list --file=config >actual &&
2661 cat >expect <<-EOF &&
2665 test_cmp expect actual &&
2667 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2668 git config ${mode_prefix}list --file=config >actual &&
2669 cat >expect <<-EOF &&
2673 test_cmp expect actual
2676 test_expect_success '--get and --get-all with --fixed-value' '
2677 test_when_finished rm -f config &&
2678 META="a+b*c?d[e]f.g" &&
2679 git config --file=config fixed.test bogus &&
2680 git config --file=config --add fixed.test "$META" &&
2682 git config --file=config --get fixed.test bogus &&
2683 git config get --file=config --value=bogus fixed.test &&
2684 test_must_fail git config --file=config --get fixed.test "$META" &&
2685 test_must_fail git config get --file=config --value="$META" fixed.test &&
2686 git config --file=config --get --fixed-value fixed.test "$META" &&
2687 git config get --file=config --fixed-value --value="$META" fixed.test &&
2688 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2690 git config --file=config --get-all fixed.test bogus &&
2691 git config get --all --file=config --value=bogus fixed.test &&
2692 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2693 test_must_fail git config get --all --file=config --value="$META" fixed.test &&
2694 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2695 git config get --all --file=config --value="$META" --fixed-value fixed.test &&
2696 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2698 git config --file=config --get-regexp fixed+ bogus &&
2699 git config get --regexp --file=config --value=bogus fixed+ &&
2700 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2701 test_must_fail git config get --regexp --file=config --value="$META" fixed+ &&
2702 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2703 git config get --regexp --file=config --fixed-value --value="$META" fixed+ &&
2704 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2707 test_expect_success '--fixed-value with value-less configuration' '
2708 test_when_finished rm -f config &&
2709 cat >config <<-\EOF &&
2713 git config --file=config --fixed-value section.key value pattern
2716 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2717 git init hasremoteurlTest &&
2718 test_when_finished "rm -rf hasremoteurlTest" &&
2720 cat >include-this <<-\EOF &&
2722 this = this-is-included
2724 cat >dont-include-that <<-\EOF &&
2726 that = that-is-not-included
2728 cat >>hasremoteurlTest/.git/config <<-EOF &&
2729 [includeIf "hasconfig:remote.*.url:foourl"]
2730 path = "$(pwd)/include-this"
2731 [includeIf "hasconfig:remote.*.url:barurl"]
2732 path = "$(pwd)/dont-include-that"
2737 echo this-is-included >expect-this &&
2738 git -C hasremoteurlTest config --get user.this >actual-this &&
2739 test_cmp expect-this actual-this &&
2741 test_must_fail git -C hasremoteurlTest config --get user.that
2744 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2745 git init hasremoteurlTest &&
2746 test_when_finished "rm -rf hasremoteurlTest" &&
2748 cat >include-two-three <<-\EOF &&
2750 two = included-config
2751 three = included-config
2753 cat >>hasremoteurlTest/.git/config <<-EOF &&
2759 [includeIf "hasconfig:remote.*.url:foourl"]
2760 path = "$(pwd)/include-two-three"
2765 echo main-config >expect-main-config &&
2766 echo included-config >expect-included-config &&
2768 git -C hasremoteurlTest config --get user.one >actual &&
2769 test_cmp expect-main-config actual &&
2771 git -C hasremoteurlTest config --get user.two >actual &&
2772 test_cmp expect-included-config actual &&
2774 git -C hasremoteurlTest config --get user.three >actual &&
2775 test_cmp expect-main-config actual
2778 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2779 git init hasremoteurlTest &&
2780 test_when_finished "rm -rf hasremoteurlTest" &&
2782 printf "[user]\ndss = yes\n" >double-star-start &&
2783 printf "[user]\ndse = yes\n" >double-star-end &&
2784 printf "[user]\ndsm = yes\n" >double-star-middle &&
2785 printf "[user]\nssm = yes\n" >single-star-middle &&
2786 printf "[user]\nno = no\n" >no &&
2788 cat >>hasremoteurlTest/.git/config <<-EOF &&
2790 url = https://foo/bar/baz
2791 [includeIf "hasconfig:remote.*.url:**/baz"]
2792 path = "$(pwd)/double-star-start"
2793 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2795 [includeIf "hasconfig:remote.*.url:https:/**"]
2796 path = "$(pwd)/double-star-end"
2797 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2799 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2800 path = "$(pwd)/double-star-middle"
2801 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2803 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2804 path = "$(pwd)/single-star-middle"
2805 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2809 git -C hasremoteurlTest config --get user.dss &&
2810 git -C hasremoteurlTest config --get user.dse &&
2811 git -C hasremoteurlTest config --get user.dsm &&
2812 git -C hasremoteurlTest config --get user.ssm &&
2813 test_must_fail git -C hasremoteurlTest config --get user.no
2816 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2817 git init hasremoteurlTest &&
2818 test_when_finished "rm -rf hasremoteurlTest" &&
2820 cat >include-with-url <<-\EOF &&
2824 cat >>hasremoteurlTest/.git/config <<-EOF &&
2825 [includeIf "hasconfig:remote.*.url:foourl"]
2826 path = "$(pwd)/include-with-url"
2829 # test with any Git command
2830 test_must_fail git -C hasremoteurlTest status 2>err &&
2831 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err
2834 test_expect_success 'negated mode causes failure' '
2835 test_must_fail git config --no-get 2>err &&
2836 grep "unknown option \`no-get${SQ}" err
2839 test_expect_success 'specifying multiple modes causes failure' '
2840 cat >expect <<-EOF &&
2841 error: options ${SQ}--get-all${SQ} and ${SQ}--get${SQ} cannot be used together
2843 test_must_fail git config --get --get-all 2>err &&
2847 test_expect_success 'writing to stdin is rejected' '
2848 echo "fatal: writing to stdin is not supported" >expect &&
2849 test_must_fail git config ${mode_set} --file - foo.bar baz
2>err
&&