builtin/config: use `OPT_CMDMODE()` to specify modes
[alt-git.git] / t / t1300-config.sh
blob86dc70769ac43d59b5037821099c5391f042fb23
1 #!/bin/sh
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
12 . ./test-lib.sh
14 test_expect_success 'setup whitespace config' '
15 sed -e "s/^|//" \
16 -e "s/[$]$//" \
17 -e "s/X/ /g" >.git/config <<-\EOF
18 [section]
19 | solid = rock
20 | sparse = big XX blue
21 | sparseAndTail = big XX blue $
22 | sparseAndTailQuoted = "big XX blue "
23 | sparseAndBiggerTail = big XX blue X X
24 | sparseAndBiggerTailQuoted = "big XX blue X X"
25 | sparseAndBiggerTailQuotedPlus = "big XX blue X X"X $
26 | headAndTail = Xbig blue $
27 | headAndTailQuoted = "Xbig blue "
28 | headAndTailQuotedPlus = "Xbig blue " $
29 | annotated = big blueX# to be discarded
30 | annotatedQuoted = "big blue"X# to be discarded
31 EOF
34 test_expect_success 'no internal whitespace' '
35 echo "rock" >expect &&
36 git config --get section.solid >actual &&
37 test_cmp expect actual
40 test_expect_success 'internal whitespace' '
41 echo "big QQ blue" | q_to_tab >expect &&
42 git config --get section.sparse >actual &&
43 test_cmp expect actual
46 test_expect_success 'internal and trailing whitespace' '
47 echo "big QQ blue" | q_to_tab >expect &&
48 git config --get section.sparseAndTail >actual &&
49 test_cmp expect actual
52 test_expect_success 'internal and trailing whitespace, all quoted' '
53 echo "big QQ blue " | q_to_tab >expect &&
54 git config --get section.sparseAndTailQuoted >actual &&
55 test_cmp expect actual
58 test_expect_success 'internal and more trailing whitespace' '
59 echo "big QQ blue" | q_to_tab >expect &&
60 git config --get section.sparseAndBiggerTail >actual &&
61 test_cmp expect actual
64 test_expect_success 'internal and more trailing whitespace, all quoted' '
65 echo "big QQ blue Q Q" | q_to_tab >expect &&
66 git config --get section.sparseAndBiggerTailQuoted >actual &&
67 test_cmp expect actual
70 test_expect_success 'internal and more trailing whitespace, not all quoted' '
71 echo "big QQ blue Q Q" | q_to_tab >expect &&
72 git config --get section.sparseAndBiggerTailQuotedPlus >actual &&
73 test_cmp expect actual
76 test_expect_success 'leading and trailing whitespace' '
77 echo "big blue" >expect &&
78 git config --get section.headAndTail >actual &&
79 test_cmp expect actual
82 test_expect_success 'leading and trailing whitespace, all quoted' '
83 echo "Qbig blue " | q_to_tab >expect &&
84 git config --get section.headAndTailQuoted >actual &&
85 test_cmp expect actual
88 test_expect_success 'leading and trailing whitespace, not all quoted' '
89 echo "Qbig blue " | q_to_tab >expect &&
90 git config --get section.headAndTailQuotedPlus >actual &&
91 test_cmp expect actual
94 test_expect_success 'inline comment' '
95 echo "big blue" >expect &&
96 git config --get section.annotated >actual &&
97 test_cmp expect actual
100 test_expect_success 'inline comment, quoted' '
101 echo "big blue" >expect &&
102 git config --get section.annotatedQuoted >actual &&
103 test_cmp expect actual
106 test_expect_success 'clear default config' '
107 rm -f .git/config
110 cat > expect << EOF
111 [section]
112 penguin = little blue
114 test_expect_success 'initial' '
115 git config section.penguin "little blue" &&
116 test_cmp expect .git/config
119 cat > expect << EOF
120 [section]
121 penguin = little blue
122 Movie = BadPhysics
124 test_expect_success 'mixed case' '
125 git config Section.Movie BadPhysics &&
126 test_cmp expect .git/config
129 cat > expect << EOF
130 [section]
131 penguin = little blue
132 Movie = BadPhysics
133 [Sections]
134 WhatEver = Second
136 test_expect_success 'similar section' '
137 git config Sections.WhatEver Second &&
138 test_cmp expect .git/config
141 cat > expect << EOF
142 [section]
143 penguin = little blue
144 Movie = BadPhysics
145 UPPERCASE = true
146 [Sections]
147 WhatEver = Second
149 test_expect_success 'uppercase section' '
150 git config SECTION.UPPERCASE true &&
151 test_cmp expect .git/config
154 test_expect_success 'replace with non-match' '
155 git config section.penguin kingpin !blue
158 test_expect_success 'replace with non-match (actually matching)' '
159 git config section.penguin "very blue" !kingpin
162 cat > expect << EOF
163 [section]
164 Movie = BadPhysics
165 UPPERCASE = true
166 penguin = gentoo # Pygoscelis papua
167 disposition = peckish # find fish
168 foo = bar #abc
169 spsp = value # and comment
170 htsp = value # and comment
171 [Sections]
172 WhatEver = Second
175 test_expect_success 'append comments' '
176 git config --replace-all --comment="Pygoscelis papua" section.penguin gentoo &&
177 git config --comment="find fish" section.disposition peckish &&
178 git config --comment="#abc" section.foo bar &&
180 git config --comment="and comment" section.spsp value &&
181 git config --comment=" # and comment" section.htsp value &&
183 test_cmp expect .git/config
186 test_expect_success 'Prohibited LF in comment' '
187 test_must_fail git config --comment="a${LF}b" section.k v
190 test_expect_success 'non-match result' 'test_cmp expect .git/config'
192 test_expect_success 'find mixed-case key by canonical name' '
193 test_cmp_config Second sections.whatever
196 test_expect_success 'find mixed-case key by non-canonical name' '
197 test_cmp_config Second SeCtIoNs.WhAtEvEr
200 test_expect_success 'subsections are not canonicalized by git-config' '
201 cat >>.git/config <<-\EOF &&
202 [section.SubSection]
203 key = one
204 [section "SubSection"]
205 key = two
207 test_cmp_config one section.subsection.key &&
208 test_cmp_config two section.SubSection.key
211 test_missing_key () {
212 local key="$1" &&
213 local title="$2" &&
214 test_expect_success "value for $title is not printed" '
215 test_must_fail git config "$key" >out 2>err &&
216 test_must_be_empty out &&
217 test_must_be_empty err
221 test_missing_key 'missingsection.missingkey' 'missing section and missing key'
222 test_missing_key 'missingsection.penguin' 'missing section and existing key'
223 test_missing_key 'section.missingkey' 'existing section and missing key'
224 test_missing_key 'section.MissingSubSection.missingkey' 'missing subsection and missing key'
225 test_missing_key 'section.SubSection.missingkey' 'existing subsection and missing key'
226 test_missing_key 'section.MissingSubSection.key' 'missing subsection and existing key'
228 cat > .git/config <<\EOF
229 [alpha]
230 bar = foo
231 [beta]
232 baz = multiple \
233 lines
234 foo = bar
237 test_expect_success 'unset with cont. lines' '
238 git config --unset beta.baz
241 cat > expect <<\EOF
242 [alpha]
243 bar = foo
244 [beta]
245 foo = bar
248 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
250 cat > .git/config << EOF
251 [beta] ; silly comment # another comment
252 noIndent= sillyValue ; 'nother silly comment
254 # empty line
255 ; comment
256 haha ="beta" # last silly comment
257 haha = hello
258 haha = bello
259 [nextSection] noNewline = ouch
262 cp .git/config .git/config2
264 test_expect_success 'multiple unset' '
265 git config --unset-all beta.haha
268 cat > expect << EOF
269 [beta] ; silly comment # another comment
270 noIndent= sillyValue ; 'nother silly comment
272 # empty line
273 ; comment
274 [nextSection] noNewline = ouch
277 test_expect_success 'multiple unset is correct' '
278 test_cmp expect .git/config
281 cp .git/config2 .git/config
283 test_expect_success '--replace-all missing value' '
284 test_must_fail git config --replace-all beta.haha &&
285 test_cmp .git/config2 .git/config
288 rm .git/config2
290 test_expect_success '--replace-all' '
291 git config --replace-all beta.haha gamma
294 cat > expect << EOF
295 [beta] ; silly comment # another comment
296 noIndent= sillyValue ; 'nother silly comment
298 # empty line
299 ; comment
300 haha = gamma
301 [nextSection] noNewline = ouch
304 test_expect_success 'all replaced' '
305 test_cmp expect .git/config
308 cat > expect << EOF
309 [beta] ; silly comment # another comment
310 noIndent= sillyValue ; 'nother silly comment
312 # empty line
313 ; comment
314 haha = alpha
315 [nextSection] noNewline = ouch
317 test_expect_success 'really mean test' '
318 git config beta.haha alpha &&
319 test_cmp expect .git/config
322 cat > expect << EOF
323 [beta] ; silly comment # another comment
324 noIndent= sillyValue ; 'nother silly comment
326 # empty line
327 ; comment
328 haha = alpha
329 [nextSection]
330 nonewline = wow
332 test_expect_success 'really really mean test' '
333 git config nextsection.nonewline wow &&
334 test_cmp expect .git/config
337 test_expect_success 'get value' '
338 test_cmp_config alpha beta.haha
341 cat > expect << EOF
342 [beta] ; silly comment # another comment
343 noIndent= sillyValue ; 'nother silly comment
345 # empty line
346 ; comment
347 [nextSection]
348 nonewline = wow
350 test_expect_success 'unset' '
351 git config --unset beta.haha &&
352 test_cmp expect .git/config
355 cat > expect << EOF
356 [beta] ; silly comment # another comment
357 noIndent= sillyValue ; 'nother silly comment
359 # empty line
360 ; comment
361 [nextSection]
362 nonewline = wow
363 NoNewLine = wow2 for me
365 test_expect_success 'multivar' '
366 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
367 test_cmp expect .git/config
370 test_expect_success 'non-match' '
371 git config --get nextsection.nonewline !for
374 test_expect_success 'non-match value' '
375 test_cmp_config wow --get nextsection.nonewline !for
378 test_expect_success 'multi-valued get returns final one' '
379 test_cmp_config "wow2 for me" --get nextsection.nonewline
382 test_expect_success 'multi-valued get-all returns all' '
383 cat >expect <<-\EOF &&
385 wow2 for me
387 git config --get-all nextsection.nonewline >actual &&
388 test_cmp expect actual
391 cat > expect << EOF
392 [beta] ; silly comment # another comment
393 noIndent= sillyValue ; 'nother silly comment
395 # empty line
396 ; comment
397 [nextSection]
398 nonewline = wow3
399 NoNewLine = wow2 for me
401 test_expect_success 'multivar replace' '
402 git config nextsection.nonewline "wow3" "wow$" &&
403 test_cmp expect .git/config
406 test_expect_success 'ambiguous unset' '
407 test_must_fail git config --unset nextsection.nonewline
410 test_expect_success 'invalid unset' '
411 test_must_fail git config --unset somesection.nonewline
414 cat > expect << EOF
415 [beta] ; silly comment # another comment
416 noIndent= sillyValue ; 'nother silly comment
418 # empty line
419 ; comment
420 [nextSection]
421 NoNewLine = wow2 for me
424 test_expect_success 'multivar unset' '
425 git config --unset nextsection.nonewline "wow3$" &&
426 test_cmp expect .git/config
429 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
431 test_expect_success 'correct key' 'git config 123456.a123 987'
433 test_expect_success 'hierarchical section' '
434 git config Version.1.2.3eX.Alpha beta
437 cat > expect << EOF
438 [beta] ; silly comment # another comment
439 noIndent= sillyValue ; 'nother silly comment
441 # empty line
442 ; comment
443 [nextSection]
444 NoNewLine = wow2 for me
445 [123456]
446 a123 = 987
447 [Version "1.2.3eX"]
448 Alpha = beta
451 test_expect_success 'hierarchical section value' '
452 test_cmp expect .git/config
455 cat > expect << EOF
456 beta.noindent=sillyValue
457 nextsection.nonewline=wow2 for me
458 123456.a123=987
459 version.1.2.3eX.alpha=beta
462 test_expect_success 'working --list' '
463 git config --list > output &&
464 test_cmp expect output
466 test_expect_success '--list without repo produces empty output' '
467 git --git-dir=nonexistent config --list >output &&
468 test_must_be_empty output
471 cat > expect << EOF
472 beta.noindent
473 nextsection.nonewline
474 123456.a123
475 version.1.2.3eX.alpha
478 test_expect_success '--name-only --list' '
479 git config --name-only --list >output &&
480 test_cmp expect output
483 cat > expect << EOF
484 beta.noindent sillyValue
485 nextsection.nonewline wow2 for me
488 test_expect_success '--get-regexp' '
489 git config --get-regexp in >output &&
490 test_cmp expect output
493 cat > expect << EOF
494 beta.noindent
495 nextsection.nonewline
498 test_expect_success '--name-only --get-regexp' '
499 git config --name-only --get-regexp in >output &&
500 test_cmp expect output
503 cat > expect << EOF
504 wow2 for me
505 wow4 for you
508 test_expect_success '--add' '
509 git config --add nextsection.nonewline "wow4 for you" &&
510 git config --get-all nextsection.nonewline > output &&
511 test_cmp expect output
514 cat > .git/config << EOF
515 [novalue]
516 variable
517 [emptyvalue]
518 variable =
521 test_expect_success 'get variable with no value' '
522 git config --get novalue.variable ^$
525 test_expect_success 'get variable with empty value' '
526 git config --get emptyvalue.variable ^$
529 echo novalue.variable > expect
531 test_expect_success 'get-regexp variable with no value' '
532 git config --get-regexp novalue > output &&
533 test_cmp expect output
536 echo 'novalue.variable true' > expect
538 test_expect_success 'get-regexp --bool variable with no value' '
539 git config --bool --get-regexp novalue > output &&
540 test_cmp expect output
543 echo 'emptyvalue.variable ' > expect
545 test_expect_success 'get-regexp variable with empty value' '
546 git config --get-regexp emptyvalue > output &&
547 test_cmp expect output
550 echo true > expect
552 test_expect_success 'get bool variable with no value' '
553 git config --bool novalue.variable > output &&
554 test_cmp expect output
557 echo false > expect
559 test_expect_success 'get bool variable with empty value' '
560 git config --bool emptyvalue.variable > output &&
561 test_cmp expect output
564 test_expect_success 'no arguments, but no crash' '
565 test_must_fail git config >output 2>&1 &&
566 test_grep usage output
569 cat > .git/config << EOF
570 [a.b]
571 c = d
574 cat > expect << EOF
575 [a.b]
576 c = d
578 x = y
581 test_expect_success 'new section is partial match of another' '
582 git config a.x y &&
583 test_cmp expect .git/config
586 cat > expect << EOF
587 [a.b]
588 c = d
590 x = y
591 b = c
593 x = y
596 test_expect_success 'new variable inserts into proper section' '
597 git config b.x y &&
598 git config a.b c &&
599 test_cmp expect .git/config
602 test_expect_success 'alternative --file (non-existing file should fail)' '
603 test_must_fail git config --file non-existing-config -l &&
604 test_must_fail git config --file non-existing-config test.xyzzy
607 cat > other-config << EOF
608 [ein]
609 bahn = strasse
612 cat > expect << EOF
613 ein.bahn=strasse
616 test_expect_success 'alternative GIT_CONFIG' '
617 GIT_CONFIG=other-config git config --list >output &&
618 test_cmp expect output
621 test_expect_success 'alternative GIT_CONFIG (--file)' '
622 git config --file other-config --list >output &&
623 test_cmp expect output
626 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
627 git config --file - --list <other-config >output &&
628 test_cmp expect output
631 test_expect_success 'setting a value in stdin is an error' '
632 test_must_fail git config --file - some.value foo
635 test_expect_success 'editing stdin is an error' '
636 test_must_fail git config --file - --edit
639 test_expect_success 'refer config from subdirectory' '
640 mkdir x &&
641 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
644 cat > expect << EOF
645 [ein]
646 bahn = strasse
647 [anwohner]
648 park = ausweis
651 test_expect_success '--set in alternative file' '
652 git config --file=other-config anwohner.park ausweis &&
653 test_cmp expect other-config
656 cat > .git/config << EOF
657 # Hallo
658 #Bello
659 [branch "eins"]
660 x = 1
661 [branch.eins]
662 y = 1
663 [branch "1 234 blabl/a"]
664 weird
667 test_expect_success 'rename section' '
668 git config --rename-section branch.eins branch.zwei
671 cat > expect << EOF
672 # Hallo
673 #Bello
674 [branch "zwei"]
675 x = 1
676 [branch "zwei"]
677 y = 1
678 [branch "1 234 blabl/a"]
679 weird
682 test_expect_success 'rename succeeded' '
683 test_cmp expect .git/config
686 test_expect_success 'rename non-existing section' '
687 test_must_fail git config --rename-section \
688 branch."world domination" branch.drei
691 test_expect_success 'rename succeeded' '
692 test_cmp expect .git/config
695 test_expect_success 'rename another section' '
696 git config --rename-section branch."1 234 blabl/a" branch.drei
699 cat > expect << EOF
700 # Hallo
701 #Bello
702 [branch "zwei"]
703 x = 1
704 [branch "zwei"]
705 y = 1
706 [branch "drei"]
707 weird
710 test_expect_success 'rename succeeded' '
711 test_cmp expect .git/config
714 cat >> .git/config << EOF
715 [branch "vier"] z = 1
718 test_expect_success 'rename a section with a var on the same line' '
719 git config --rename-section branch.vier branch.zwei
722 cat > expect << EOF
723 # Hallo
724 #Bello
725 [branch "zwei"]
726 x = 1
727 [branch "zwei"]
728 y = 1
729 [branch "drei"]
730 weird
731 [branch "zwei"]
732 z = 1
735 test_expect_success 'rename succeeded' '
736 test_cmp expect .git/config
739 test_expect_success 'renaming empty section name is rejected' '
740 test_must_fail git config --rename-section branch.zwei ""
743 test_expect_success 'renaming to bogus section is rejected' '
744 test_must_fail git config --rename-section branch.zwei "bogus name"
747 test_expect_success 'renaming a section with a long line' '
749 printf "[b]\\n" &&
750 printf " c = d %1024s [a] e = f\\n" " " &&
751 printf "[a] g = h\\n"
752 } >y &&
753 git config -f y --rename-section a xyz &&
754 test_must_fail git config -f y b.e
757 test_expect_success 'renaming an embedded section with a long line' '
759 printf "[b]\\n" &&
760 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
761 printf "[a] g = h\\n"
762 } >y &&
763 git config -f y --rename-section a xyz &&
764 test_must_fail git config -f y foo.e
767 test_expect_success 'renaming a section with an overly-long line' '
769 printf "[b]\\n" &&
770 printf " c = d %525000s e" " " &&
771 printf "[a] g = h\\n"
772 } >y &&
773 test_must_fail git config -f y --rename-section a xyz 2>err &&
774 grep "refusing to work with overly long line in .y. on line 2" err
777 cat >> .git/config << EOF
778 [branch "zwei"] a = 1 [branch "vier"]
781 test_expect_success 'remove section' '
782 git config --remove-section branch.zwei
785 cat > expect << EOF
786 # Hallo
787 #Bello
788 [branch "drei"]
789 weird
792 test_expect_success 'section was removed properly' '
793 test_cmp expect .git/config
796 cat > expect << EOF
797 [gitcvs]
798 enabled = true
799 dbname = %Ggitcvs2.%a.%m.sqlite
800 [gitcvs "ext"]
801 dbname = %Ggitcvs1.%a.%m.sqlite
804 test_expect_success 'section ending' '
805 rm -f .git/config &&
806 git config gitcvs.enabled true &&
807 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
808 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
809 test_cmp expect .git/config
813 test_expect_success numbers '
814 git config kilo.gram 1k &&
815 git config mega.ton 1m &&
816 echo 1024 >expect &&
817 echo 1048576 >>expect &&
818 git config --int --get kilo.gram >actual &&
819 git config --int --get mega.ton >>actual &&
820 test_cmp expect actual
823 test_expect_success '--int is at least 64 bits' '
824 git config giga.watts 121g &&
825 echo >expect &&
826 test_cmp_config 129922760704 --int --get giga.watts
829 test_expect_success 'invalid unit' '
830 git config aninvalid.unit "1auto" &&
831 test_cmp_config 1auto aninvalid.unit &&
832 test_must_fail git config --int --get aninvalid.unit 2>actual &&
833 test_grep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
836 test_expect_success 'invalid unit boolean' '
837 git config commit.gpgsign "1true" &&
838 test_cmp_config 1true commit.gpgsign &&
839 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
840 test_grep "bad boolean config value .1true. for .commit.gpgsign." actual
843 test_expect_success 'line number is reported correctly' '
844 printf "[bool]\n\tvar\n" >invalid &&
845 test_must_fail git config -f invalid --path bool.var 2>actual &&
846 test_grep "line 2" actual
849 test_expect_success 'invalid stdin config' '
850 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
851 test_grep "bad config line 1 in standard input" output
854 cat > expect << EOF
855 true
856 false
857 true
858 false
859 true
860 false
861 true
862 false
865 test_expect_success bool '
867 git config bool.true1 01 &&
868 git config bool.true2 -1 &&
869 git config bool.true3 YeS &&
870 git config bool.true4 true &&
871 git config bool.false1 000 &&
872 git config bool.false2 "" &&
873 git config bool.false3 nO &&
874 git config bool.false4 FALSE &&
875 rm -f result &&
876 for i in 1 2 3 4
878 git config --bool --get bool.true$i >>result &&
879 git config --bool --get bool.false$i >>result || return 1
880 done &&
881 test_cmp expect result'
883 test_expect_success 'invalid bool (--get)' '
885 git config bool.nobool foobar &&
886 test_must_fail git config --bool --get bool.nobool'
888 test_expect_success 'invalid bool (set)' '
890 test_must_fail git config --bool bool.nobool foobar'
892 cat > expect <<\EOF
893 [bool]
894 true1 = true
895 true2 = true
896 true3 = true
897 true4 = true
898 false1 = false
899 false2 = false
900 false3 = false
901 false4 = false
904 test_expect_success 'set --bool' '
906 rm -f .git/config &&
907 git config --bool bool.true1 01 &&
908 git config --bool bool.true2 -1 &&
909 git config --bool bool.true3 YeS &&
910 git config --bool bool.true4 true &&
911 git config --bool bool.false1 000 &&
912 git config --bool bool.false2 "" &&
913 git config --bool bool.false3 nO &&
914 git config --bool bool.false4 FALSE &&
915 test_cmp expect .git/config'
917 cat > expect <<\EOF
918 [int]
919 val1 = 1
920 val2 = -1
921 val3 = 5242880
924 test_expect_success 'set --int' '
926 rm -f .git/config &&
927 git config --int int.val1 01 &&
928 git config --int int.val2 -1 &&
929 git config --int int.val3 5m &&
930 test_cmp expect .git/config
933 test_expect_success 'get --bool-or-int' '
934 cat >.git/config <<-\EOF &&
935 [bool]
936 true1
937 true2 = true
938 false = false
939 [int]
940 int1 = 0
941 int2 = 1
942 int3 = -1
944 cat >expect <<-\EOF &&
945 true
946 true
947 false
953 git config --bool-or-int bool.true1 &&
954 git config --bool-or-int bool.true2 &&
955 git config --bool-or-int bool.false &&
956 git config --bool-or-int int.int1 &&
957 git config --bool-or-int int.int2 &&
958 git config --bool-or-int int.int3
959 } >actual &&
960 test_cmp expect actual
963 cat >expect <<\EOF
964 [bool]
965 true1 = true
966 false1 = false
967 true2 = true
968 false2 = false
969 [int]
970 int1 = 0
971 int2 = 1
972 int3 = -1
975 test_expect_success 'set --bool-or-int' '
976 rm -f .git/config &&
977 git config --bool-or-int bool.true1 true &&
978 git config --bool-or-int bool.false1 false &&
979 git config --bool-or-int bool.true2 yes &&
980 git config --bool-or-int bool.false2 no &&
981 git config --bool-or-int int.int1 0 &&
982 git config --bool-or-int int.int2 1 &&
983 git config --bool-or-int int.int3 -1 &&
984 test_cmp expect .git/config
987 cat >expect <<\EOF
988 [path]
989 home = ~/
990 normal = /dev/null
991 trailingtilde = foo~
994 test_expect_success !MINGW 'set --path' '
995 rm -f .git/config &&
996 git config --path path.home "~/" &&
997 git config --path path.normal "/dev/null" &&
998 git config --path path.trailingtilde "foo~" &&
999 test_cmp expect .git/config'
1001 if test_have_prereq !MINGW && test "${HOME+set}"
1002 then
1003 test_set_prereq HOMEVAR
1006 cat >expect <<EOF
1007 $HOME/
1008 /dev/null
1009 foo~
1012 test_expect_success HOMEVAR 'get --path' '
1013 git config --get --path path.home > result &&
1014 git config --get --path path.normal >> result &&
1015 git config --get --path path.trailingtilde >> result &&
1016 test_cmp expect result
1019 cat >expect <<\EOF
1020 /dev/null
1021 foo~
1024 test_expect_success !MINGW 'get --path copes with unset $HOME' '
1026 sane_unset HOME &&
1027 test_must_fail git config --get --path path.home \
1028 >result 2>msg &&
1029 git config --get --path path.normal >>result &&
1030 git config --get --path path.trailingtilde >>result
1031 ) &&
1032 test_grep "[Ff]ailed to expand.*~/" msg &&
1033 test_cmp expect result
1036 test_expect_success 'get --path barfs on boolean variable' '
1037 echo "[path]bool" >.git/config &&
1038 test_must_fail git config --get --path path.bool
1041 test_expect_success 'get --expiry-date' '
1042 rel="3.weeks.5.days.00:00" &&
1043 rel_out="$rel ->" &&
1044 cat >.git/config <<-\EOF &&
1045 [date]
1046 valid1 = "3.weeks.5.days 00:00"
1047 valid2 = "Fri Jun 4 15:46:55 2010"
1048 valid3 = "2017/11/11 11:11:11PM"
1049 valid4 = "2017/11/10 09:08:07 PM"
1050 valid5 = "never"
1051 invalid1 = "abc"
1053 cat >expect <<-EOF &&
1054 $(test-tool date timestamp $rel)
1055 1275666415
1056 1510441871
1057 1510348087
1060 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
1062 echo "$rel_out $(git config --expiry-date date.valid1)" &&
1063 git config --expiry-date date.valid2 &&
1064 git config --expiry-date date.valid3 &&
1065 git config --expiry-date date.valid4 &&
1066 git config --expiry-date date.valid5
1067 } >actual &&
1068 test_cmp expect actual &&
1069 test_must_fail git config --expiry-date date.invalid1
1072 test_expect_success 'get --type=color' '
1073 rm .git/config &&
1074 git config foo.color "red" &&
1075 git config --get --type=color foo.color >actual.raw &&
1076 test_decode_color <actual.raw >actual &&
1077 echo "<RED>" >expect &&
1078 test_cmp expect actual
1081 cat >expect << EOF
1082 [foo]
1083 color = red
1086 test_expect_success 'set --type=color' '
1087 rm .git/config &&
1088 git config --type=color foo.color "red" &&
1089 test_cmp expect .git/config
1092 test_expect_success 'get --type=color barfs on non-color' '
1093 echo "[foo]bar=not-a-color" >.git/config &&
1094 test_must_fail git config --get --type=color foo.bar
1097 test_expect_success 'set --type=color barfs on non-color' '
1098 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
1099 test_grep "cannot parse color" error
1102 cat > expect << EOF
1103 [quote]
1104 leading = " test"
1105 ending = "test "
1106 semicolon = "test;test"
1107 hash = "test#test"
1109 test_expect_success 'quoting' '
1110 rm -f .git/config &&
1111 git config quote.leading " test" &&
1112 git config quote.ending "test " &&
1113 git config quote.semicolon "test;test" &&
1114 git config quote.hash "test#test" &&
1115 test_cmp expect .git/config
1118 test_expect_success 'key with newline' '
1119 test_must_fail git config "key.with
1120 newline" 123'
1122 test_expect_success 'value with newline' 'git config key.sub value.with\\\
1123 newline'
1125 cat > .git/config <<\EOF
1126 [section]
1127 ; comment \
1128 continued = cont\
1129 inued
1130 noncont = not continued ; \
1131 quotecont = "cont;\
1132 inued"
1135 cat > expect <<\EOF
1136 section.continued=continued
1137 section.noncont=not continued
1138 section.quotecont=cont;inued
1141 test_expect_success 'value continued on next line' '
1142 git config --list > result &&
1143 test_cmp expect result
1146 cat > .git/config <<\EOF
1147 [section "sub=section"]
1148 val1 = foo=bar
1149 val2 = foo\nbar
1150 val3 = \n\n
1151 val4 =
1152 val5
1155 cat > expect <<\EOF
1156 section.sub=section.val1
1157 foo=barQsection.sub=section.val2
1159 barQsection.sub=section.val3
1162 Qsection.sub=section.val4
1163 Qsection.sub=section.val5Q
1165 test_expect_success '--null --list' '
1166 git config --null --list >result.raw &&
1167 nul_to_q <result.raw >result &&
1168 echo >>result &&
1169 test_cmp expect result
1172 test_expect_success '--null --get-regexp' '
1173 git config --null --get-regexp "val[0-9]" >result.raw &&
1174 nul_to_q <result.raw >result &&
1175 echo >>result &&
1176 test_cmp expect result
1179 test_expect_success 'inner whitespace kept verbatim, spaces only' '
1180 echo "foo bar" >expect &&
1181 git config section.val "foo bar" &&
1182 git config --get section.val >actual &&
1183 test_cmp expect actual
1186 test_expect_success 'inner whitespace kept verbatim, horizontal tabs only' '
1187 echo "fooQQbar" | q_to_tab >expect &&
1188 git config section.val "$(cat expect)" &&
1189 git config --get section.val >actual &&
1190 test_cmp expect actual
1193 test_expect_success 'inner whitespace kept verbatim, horizontal tabs and spaces' '
1194 echo "foo Q bar" | q_to_tab >expect &&
1195 git config section.val "$(cat expect)" &&
1196 git config --get section.val >actual &&
1197 test_cmp expect actual
1200 test_expect_success SYMLINKS 'symlinked configuration' '
1201 ln -s notyet myconfig &&
1202 git config --file=myconfig test.frotz nitfol &&
1203 test -h myconfig &&
1204 test -f notyet &&
1205 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1206 git config --file=myconfig test.xyzzy rezrov &&
1207 test -h myconfig &&
1208 test -f notyet &&
1209 cat >expect <<-\EOF &&
1210 nitfol
1211 rezrov
1214 git config --file=notyet test.frotz &&
1215 git config --file=notyet test.xyzzy
1216 } >actual &&
1217 test_cmp expect actual
1220 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1221 ln -s doesnotexist linktonada &&
1222 ln -s linktonada linktolinktonada &&
1223 test_must_fail git config --file=linktonada --list &&
1224 test_must_fail git config --file=linktolinktonada --list
1227 test_expect_success 'check split_cmdline return' '
1228 test_when_finished "rm -rf repo" &&
1229 git init repo &&
1231 cd repo &&
1232 git config alias.split-cmdline-fix "echo \"" &&
1233 test_must_fail git split-cmdline-fix &&
1234 echo foo >foo &&
1235 git add foo &&
1236 git commit -m "initial commit" &&
1237 git config branch.main.mergeoptions "echo \"" &&
1238 test_must_fail git merge main
1242 test_expect_success 'git -c "key=value" support' '
1243 cat >expect <<-\EOF &&
1244 value
1245 value
1246 true
1249 git -c section.name=value config section.name &&
1250 git -c foo.CamelCase=value config foo.camelcase &&
1251 git -c foo.flag config --bool foo.flag
1252 } >actual &&
1253 test_cmp expect actual &&
1254 test_must_fail git -c name=value config section.name
1257 # We just need a type-specifier here that cares about the
1258 # distinction internally between a NULL boolean and a real
1259 # string (because most of git's internal parsers do care).
1260 # Using "--path" works, but we do not otherwise care about
1261 # its semantics.
1262 test_expect_success 'git -c can represent empty string' '
1263 echo >expect &&
1264 git -c foo.empty= config --path foo.empty >actual &&
1265 test_cmp expect actual
1268 test_expect_success 'key sanity-checking' '
1269 test_must_fail git config foo=bar &&
1270 test_must_fail git config foo=.bar &&
1271 test_must_fail git config foo.ba=r &&
1272 test_must_fail git config foo.1bar &&
1273 test_must_fail git config foo."ba
1274 z".bar &&
1275 test_must_fail git config . false &&
1276 test_must_fail git config .foo false &&
1277 test_must_fail git config foo. false &&
1278 test_must_fail git config .foo. false &&
1279 git config foo.bar true &&
1280 git config foo."ba =z".bar false
1283 test_expect_success 'git -c works with aliases of builtins' '
1284 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1285 echo bar >expect &&
1286 git checkconfig >actual &&
1287 test_cmp expect actual
1290 test_expect_success 'aliases can be CamelCased' '
1291 test_when_finished "rm -rf repo" &&
1292 git init repo &&
1294 cd repo &&
1295 test_commit A &&
1296 git config alias.CamelCased "rev-parse HEAD" &&
1297 git CamelCased >out &&
1298 git rev-parse HEAD >expect &&
1299 test_cmp expect out
1303 test_expect_success 'git -c does not split values on equals' '
1304 echo "value with = in it" >expect &&
1305 git -c section.foo="value with = in it" config section.foo >actual &&
1306 test_cmp expect actual
1309 test_expect_success 'git -c dies on bogus config' '
1310 test_must_fail git -c core.bare=foo rev-parse
1313 test_expect_success 'git -c complains about empty key' '
1314 test_must_fail git -c "=foo" rev-parse
1317 test_expect_success 'git -c complains about empty key and value' '
1318 test_must_fail git -c "" rev-parse
1321 test_expect_success 'multiple git -c appends config' '
1322 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1323 cat >expect <<-\EOF &&
1324 x.one 1
1325 x.two 2
1327 git -c x.one=1 x >actual &&
1328 test_cmp expect actual
1331 test_expect_success 'last one wins: two level vars' '
1333 # sec.var and sec.VAR are the same variable, as the first
1334 # and the last level of a configuration variable name is
1335 # case insensitive.
1337 echo VAL >expect &&
1339 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1340 test_cmp expect actual &&
1341 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1342 test_cmp expect actual &&
1344 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1345 test_cmp expect actual &&
1346 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1347 test_cmp expect actual
1350 test_expect_success 'last one wins: three level vars' '
1352 # v.a.r and v.A.r are not the same variable, as the middle
1353 # level of a three-level configuration variable name is
1354 # case sensitive.
1356 echo val >expect &&
1357 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1358 test_cmp expect actual &&
1359 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1360 test_cmp expect actual &&
1362 # v.a.r and V.a.R are the same variable, as the first
1363 # and the last level of a configuration variable name is
1364 # case insensitive.
1366 echo VAL >expect &&
1367 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1368 test_cmp expect actual &&
1369 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1370 test_cmp expect actual &&
1371 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1372 test_cmp expect actual &&
1373 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1374 test_cmp expect actual
1377 test_expect_success 'old-fashioned settings are case insensitive' '
1378 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1380 cat >testConfig_actual <<-EOF &&
1381 [V.A]
1382 r = value1
1384 q_to_tab >testConfig_expect <<-EOF &&
1385 [V.A]
1386 Qr = value2
1388 git config -f testConfig_actual "v.a.r" value2 &&
1389 test_cmp testConfig_expect testConfig_actual &&
1391 cat >testConfig_actual <<-EOF &&
1392 [V.A]
1393 r = value1
1395 q_to_tab >testConfig_expect <<-EOF &&
1396 [V.A]
1397 QR = value2
1399 git config -f testConfig_actual "V.a.R" value2 &&
1400 test_cmp testConfig_expect testConfig_actual &&
1402 cat >testConfig_actual <<-EOF &&
1403 [V.A]
1404 r = value1
1406 q_to_tab >testConfig_expect <<-EOF &&
1407 [V.A]
1408 r = value1
1409 Qr = value2
1411 git config -f testConfig_actual "V.A.r" value2 &&
1412 test_cmp testConfig_expect testConfig_actual &&
1414 cat >testConfig_actual <<-EOF &&
1415 [V.A]
1416 r = value1
1418 q_to_tab >testConfig_expect <<-EOF &&
1419 [V.A]
1420 r = value1
1421 Qr = value2
1423 git config -f testConfig_actual "v.A.r" value2 &&
1424 test_cmp testConfig_expect testConfig_actual
1427 test_expect_success 'setting different case sensitive subsections ' '
1428 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1430 cat >testConfig_actual <<-EOF &&
1431 [V "A"]
1432 R = v1
1433 [K "E"]
1434 Y = v1
1435 [a "b"]
1436 c = v1
1437 [d "e"]
1438 f = v1
1440 q_to_tab >testConfig_expect <<-EOF &&
1441 [V "A"]
1442 Qr = v2
1443 [K "E"]
1444 Qy = v2
1445 [a "b"]
1446 Qc = v2
1447 [d "e"]
1448 f = v1
1449 [d "E"]
1450 Qf = v2
1452 # exact match
1453 git config -f testConfig_actual a.b.c v2 &&
1454 # match section and subsection, key is cased differently.
1455 git config -f testConfig_actual K.E.y v2 &&
1456 # section and key are matched case insensitive, but subsection needs
1457 # to match; When writing out new values only the key is adjusted
1458 git config -f testConfig_actual v.A.r v2 &&
1459 # subsection is not matched:
1460 git config -f testConfig_actual d.E.f v2 &&
1461 test_cmp testConfig_expect testConfig_actual
1464 for VAR in a .a a. a.0b a."b c". a."b c".0d
1466 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1467 test_must_fail git -c "$VAR=VAL" config -l
1469 done
1471 for VAR in a.b a."b c".d
1473 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1474 echo VAL >expect &&
1475 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1476 test_cmp expect actual
1478 done
1480 test_expect_success 'git -c is not confused by empty environment' '
1481 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1484 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1485 v="${SQ}key.one=foo${SQ}" &&
1486 v="$v ${SQ}key.two=bar${SQ}" &&
1487 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1488 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1489 cat >expect <<-EOF &&
1490 key.one foo
1491 key.two bar
1492 key.ambiguous section.whatever=value
1494 test_cmp expect actual
1497 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1498 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1499 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1500 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1501 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1502 cat >expect <<-EOF &&
1503 key.one foo
1504 key.two bar
1505 key.ambiguous=section.whatever value
1507 test_cmp expect actual
1510 test_expect_success 'old and new-style entries can mix' '
1511 v="${SQ}key.oldone=oldfoo${SQ}" &&
1512 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1513 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1514 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1515 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1516 cat >expect <<-EOF &&
1517 key.oldone oldfoo
1518 key.newone newfoo
1519 key.oldtwo oldbar
1520 key.newtwo newbar
1522 test_cmp expect actual
1525 test_expect_success 'old and new bools with ambiguous subsection' '
1526 v="${SQ}key.with=equals.oldbool${SQ}" &&
1527 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1528 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1529 cat >expect <<-EOF &&
1530 key.with equals.oldbool
1531 key.with=equals.newbool
1533 test_cmp expect actual
1536 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1537 cat >expect <<-\EOF &&
1538 env.one one
1539 env.two two
1541 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1542 git config --get-regexp "env.*" >actual &&
1543 test_cmp expect actual &&
1545 cat >expect <<-EOF &&
1546 env.one one${SQ}
1547 env.two two
1549 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1550 git config --get-regexp "env.*" >actual &&
1551 test_cmp expect actual &&
1553 test_must_fail env \
1554 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1555 git config --get-regexp "env.*"
1558 test_expect_success 'git --config-env=key=envvar support' '
1559 cat >expect <<-\EOF &&
1560 value
1561 value
1562 value
1563 value
1564 false
1565 false
1568 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1569 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1570 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1571 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1572 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1573 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1574 } >actual &&
1575 test_cmp expect actual
1578 test_expect_success 'git --config-env with missing value' '
1579 test_must_fail env ENVVAR=value git --config-env 2>error &&
1580 grep "no config key given for --config-env" error &&
1581 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1582 grep "invalid config format: config" error
1585 test_expect_success 'git --config-env fails with invalid parameters' '
1586 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1587 test_grep "invalid config format: foo.flag" error &&
1588 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1589 test_grep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1590 sane_unset NONEXISTENT &&
1591 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1592 test_grep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1595 test_expect_success 'git -c and --config-env work together' '
1596 cat >expect <<-\EOF &&
1597 bar.cmd cmd-value
1598 bar.env env-value
1600 ENVVAR=env-value git \
1601 -c bar.cmd=cmd-value \
1602 --config-env=bar.env=ENVVAR \
1603 config --get-regexp "^bar.*" >actual &&
1604 test_cmp expect actual
1607 test_expect_success 'git -c and --config-env override each other' '
1608 cat >expect <<-\EOF &&
1613 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1614 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1615 } >actual &&
1616 test_cmp expect actual
1619 test_expect_success '--config-env handles keys with equals' '
1620 echo value=with=equals >expect &&
1621 ENVVAR=value=with=equals git \
1622 --config-env=section.subsection=with=equals.key=ENVVAR \
1623 config section.subsection=with=equals.key >actual &&
1624 test_cmp expect actual
1627 test_expect_success 'git config handles environment config pairs' '
1628 GIT_CONFIG_COUNT=2 \
1629 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1630 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1631 git config --get-regexp "pair.*" >actual &&
1632 cat >expect <<-EOF &&
1633 pair.one foo
1634 pair.two bar
1636 test_cmp expect actual
1639 test_expect_success 'git config ignores pairs without count' '
1640 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1641 git config pair.one 2>error &&
1642 test_must_be_empty error
1645 test_expect_success 'git config ignores pairs exceeding count' '
1646 GIT_CONFIG_COUNT=1 \
1647 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1648 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1649 git config --get-regexp "pair.*" >actual 2>error &&
1650 cat >expect <<-EOF &&
1651 pair.one value
1653 test_cmp expect actual &&
1654 test_must_be_empty error
1657 test_expect_success 'git config ignores pairs with zero count' '
1658 test_must_fail env \
1659 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1660 git config pair.one 2>error &&
1661 test_must_be_empty error
1664 test_expect_success 'git config ignores pairs with empty count' '
1665 test_must_fail env \
1666 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1667 git config pair.one 2>error &&
1668 test_must_be_empty error
1671 test_expect_success 'git config fails with invalid count' '
1672 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1673 test_grep "bogus count" error &&
1674 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1675 test_grep "too many entries" error
1678 test_expect_success 'git config fails with missing config key' '
1679 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1680 git config --list 2>error &&
1681 test_grep "missing config key" error
1684 test_expect_success 'git config fails with missing config value' '
1685 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1686 git config --list 2>error &&
1687 test_grep "missing config value" error
1690 test_expect_success 'git config fails with invalid config pair key' '
1691 test_must_fail env GIT_CONFIG_COUNT=1 \
1692 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1693 git config --list &&
1694 test_must_fail env GIT_CONFIG_COUNT=1 \
1695 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1696 git config --list
1699 test_expect_success 'environment overrides config file' '
1700 test_when_finished "rm -f .git/config" &&
1701 cat >.git/config <<-EOF &&
1702 [pair]
1703 one = value
1705 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1706 git config pair.one >actual &&
1707 cat >expect <<-EOF &&
1708 override
1710 test_cmp expect actual
1713 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1714 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1715 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1716 git config pair.one >actual &&
1717 cat >expect <<-EOF &&
1718 override
1720 test_cmp expect actual
1723 test_expect_success 'command line overrides environment config' '
1724 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1725 git -c pair.one=override config pair.one >actual &&
1726 cat >expect <<-EOF &&
1727 override
1729 test_cmp expect actual
1732 test_expect_success 'git config --edit works' '
1733 git config -f tmp test.value no &&
1734 echo test.value=yes >expect &&
1735 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1736 git config -f tmp --list >actual &&
1737 test_cmp expect actual
1740 test_expect_success 'git config --edit respects core.editor' '
1741 git config -f tmp test.value no &&
1742 echo test.value=yes >expect &&
1743 test_config core.editor "echo [test]value=yes >" &&
1744 git config -f tmp --edit &&
1745 git config -f tmp --list >actual &&
1746 test_cmp expect actual
1749 # malformed configuration files
1750 test_expect_success 'barf on syntax error' '
1751 cat >.git/config <<-\EOF &&
1752 # broken key=value
1753 [section]
1754 key garbage
1756 test_must_fail git config --get section.key 2>error &&
1757 test_grep " line 3 " error
1760 test_expect_success 'barf on incomplete section header' '
1761 cat >.git/config <<-\EOF &&
1762 # broken section line
1763 [section
1764 key = value
1766 test_must_fail git config --get section.key 2>error &&
1767 test_grep " line 2 " error
1770 test_expect_success 'barf on incomplete string' '
1771 cat >.git/config <<-\EOF &&
1772 # broken value string
1773 [section]
1774 key = "value string
1776 test_must_fail git config --get section.key 2>error &&
1777 test_grep " line 3 " error
1780 test_expect_success 'urlmatch' '
1781 cat >.git/config <<-\EOF &&
1782 [http]
1783 sslVerify
1784 [http "https://weak.example.com"]
1785 sslVerify = false
1786 cookieFile = /tmp/cookie.txt
1789 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1790 test_must_be_empty actual &&
1792 echo true >expect &&
1793 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1794 test_cmp expect actual &&
1796 echo false >expect &&
1797 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1798 test_cmp expect actual &&
1801 echo http.cookiefile /tmp/cookie.txt &&
1802 echo http.sslverify false
1803 } >expect &&
1804 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1805 test_cmp expect actual
1808 test_expect_success 'urlmatch with --show-scope' '
1809 cat >.git/config <<-\EOF &&
1810 [http "https://weak.example.com"]
1811 sslVerify = false
1812 cookieFile = /tmp/cookie.txt
1815 cat >expect <<-EOF &&
1816 local http.cookiefile /tmp/cookie.txt
1817 local http.sslverify false
1819 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1820 test_cmp expect actual
1823 test_expect_success 'urlmatch favors more specific URLs' '
1824 cat >.git/config <<-\EOF &&
1825 [http "https://example.com/"]
1826 cookieFile = /tmp/root.txt
1827 [http "https://example.com/subdirectory"]
1828 cookieFile = /tmp/subdirectory.txt
1829 [http "https://user@example.com/"]
1830 cookieFile = /tmp/user.txt
1831 [http "https://averylonguser@example.com/"]
1832 cookieFile = /tmp/averylonguser.txt
1833 [http "https://preceding.example.com"]
1834 cookieFile = /tmp/preceding.txt
1835 [http "https://*.example.com"]
1836 cookieFile = /tmp/wildcard.txt
1837 [http "https://*.example.com/wildcardwithsubdomain"]
1838 cookieFile = /tmp/wildcardwithsubdomain.txt
1839 [http "https://*.example.*"]
1840 cookieFile = /tmp/multiwildcard.txt
1841 [http "https://trailing.example.com"]
1842 cookieFile = /tmp/trailing.txt
1843 [http "https://user@*.example.com/"]
1844 cookieFile = /tmp/wildcardwithuser.txt
1845 [http "https://sub.example.com/"]
1846 cookieFile = /tmp/sub.txt
1849 echo http.cookiefile /tmp/root.txt >expect &&
1850 git config --get-urlmatch HTTP https://example.com >actual &&
1851 test_cmp expect actual &&
1853 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1854 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1855 test_cmp expect actual &&
1857 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1858 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1859 test_cmp expect actual &&
1861 echo http.cookiefile /tmp/user.txt >expect &&
1862 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1863 test_cmp expect actual &&
1865 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1866 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1867 test_cmp expect actual &&
1869 echo http.cookiefile /tmp/preceding.txt >expect &&
1870 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1871 test_cmp expect actual &&
1873 echo http.cookiefile /tmp/wildcard.txt >expect &&
1874 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1875 test_cmp expect actual &&
1877 echo http.cookiefile /tmp/sub.txt >expect &&
1878 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1879 test_cmp expect actual &&
1881 echo http.cookiefile /tmp/trailing.txt >expect &&
1882 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1883 test_cmp expect actual &&
1885 echo http.cookiefile /tmp/sub.txt >expect &&
1886 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1887 test_cmp expect actual &&
1889 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1890 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1891 test_cmp expect actual
1894 test_expect_success 'urlmatch with wildcard' '
1895 cat >.git/config <<-\EOF &&
1896 [http]
1897 sslVerify
1898 [http "https://*.example.com"]
1899 sslVerify = false
1900 cookieFile = /tmp/cookie.txt
1903 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1904 test_must_be_empty actual &&
1906 echo true >expect &&
1907 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1908 test_cmp expect actual &&
1910 echo true >expect &&
1911 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1912 test_cmp expect actual &&
1914 echo true >expect &&
1915 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1916 test_cmp expect actual &&
1918 echo false >expect &&
1919 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1920 test_cmp expect actual &&
1923 echo http.cookiefile /tmp/cookie.txt &&
1924 echo http.sslverify false
1925 } >expect &&
1926 git config --get-urlmatch HTTP https://good.example.com >actual &&
1927 test_cmp expect actual &&
1929 echo http.sslverify >expect &&
1930 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1931 test_cmp expect actual
1934 # good section hygiene
1935 test_expect_success '--unset last key removes section (except if commented)' '
1936 cat >.git/config <<-\EOF &&
1937 # some generic comment on the configuration file itself
1938 # a comment specific to this "section" section.
1939 [section]
1940 # some intervening lines
1941 # that should also be dropped
1943 key = value
1944 # please be careful when you update the above variable
1947 cat >expect <<-\EOF &&
1948 # some generic comment on the configuration file itself
1949 # a comment specific to this "section" section.
1950 [section]
1951 # some intervening lines
1952 # that should also be dropped
1954 # please be careful when you update the above variable
1957 git config --unset section.key &&
1958 test_cmp expect .git/config &&
1960 cat >.git/config <<-\EOF &&
1961 [section]
1962 key = value
1963 [next-section]
1966 cat >expect <<-\EOF &&
1967 [next-section]
1970 git config --unset section.key &&
1971 test_cmp expect .git/config &&
1973 q_to_tab >.git/config <<-\EOF &&
1974 [one]
1975 Qkey = "multiline \
1976 QQ# with comment"
1977 [two]
1978 key = true
1980 git config --unset two.key &&
1981 ! grep two .git/config &&
1983 q_to_tab >.git/config <<-\EOF &&
1984 [one]
1985 Qkey = "multiline \
1986 QQ# with comment"
1987 [one]
1988 key = true
1990 git config --unset-all one.key &&
1991 test_line_count = 0 .git/config &&
1993 q_to_tab >.git/config <<-\EOF &&
1994 [one]
1995 Qkey = true
1996 Q# a comment not at the start
1997 [two]
1998 Qkey = true
2000 git config --unset two.key &&
2001 grep two .git/config &&
2003 q_to_tab >.git/config <<-\EOF &&
2004 [one]
2005 Qkey = not [two "subsection"]
2006 [two "subsection"]
2007 [two "subsection"]
2008 Qkey = true
2009 [TWO "subsection"]
2010 [one]
2012 git config --unset two.subsection.key &&
2013 test "not [two subsection]" = "$(git config one.key)" &&
2014 test_line_count = 3 .git/config
2017 test_expect_success '--unset-all removes section if empty & uncommented' '
2018 cat >.git/config <<-\EOF &&
2019 [section]
2020 key = value1
2021 key = value2
2024 git config --unset-all section.key &&
2025 test_line_count = 0 .git/config
2028 test_expect_success 'adding a key into an empty section reuses header' '
2029 cat >.git/config <<-\EOF &&
2030 [section]
2033 q_to_tab >expect <<-\EOF &&
2034 [section]
2035 Qkey = value
2038 git config section.key value &&
2039 test_cmp expect .git/config
2042 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
2043 chmod 0600 .git/config &&
2044 git config imap.pass Hunter2 &&
2045 perl -e \
2046 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
2047 git config --rename-section imap pop &&
2048 perl -e \
2049 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
2052 ! test_have_prereq MINGW ||
2053 HOME="$(pwd)" # convert to Windows path
2055 test_expect_success 'set up --show-origin tests' '
2056 INCLUDE_DIR="$HOME/include" &&
2057 mkdir -p "$INCLUDE_DIR" &&
2058 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
2059 [user]
2060 absolute = include
2062 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
2063 [user]
2064 relative = include
2066 cat >"$HOME"/.gitconfig <<-EOF &&
2067 [user]
2068 global = true
2069 override = global
2070 [include]
2071 path = "$INCLUDE_DIR/absolute.include"
2073 cat >.git/config <<-\EOF
2074 [user]
2075 local = true
2076 override = local
2077 [include]
2078 path = ../include/relative.include
2082 test_expect_success '--show-origin with --list' '
2083 cat >expect <<-EOF &&
2084 file:$HOME/.gitconfig user.global=true
2085 file:$HOME/.gitconfig user.override=global
2086 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2087 file:$INCLUDE_DIR/absolute.include user.absolute=include
2088 file:.git/config user.local=true
2089 file:.git/config user.override=local
2090 file:.git/config include.path=../include/relative.include
2091 file:.git/../include/relative.include user.relative=include
2092 command line: user.environ=true
2093 command line: user.cmdline=true
2095 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
2096 git -c user.cmdline=true config --list --show-origin >output &&
2097 test_cmp expect output
2100 test_expect_success '--show-origin with --list --null' '
2101 cat >expect <<-EOF &&
2102 file:$HOME/.gitconfigQuser.global
2103 trueQfile:$HOME/.gitconfigQuser.override
2104 globalQfile:$HOME/.gitconfigQinclude.path
2105 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
2106 includeQfile:.git/configQuser.local
2107 trueQfile:.git/configQuser.override
2108 localQfile:.git/configQinclude.path
2109 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
2110 includeQcommand line:Quser.cmdline
2111 trueQ
2113 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
2114 nul_to_q <output.raw >output &&
2115 # The here-doc above adds a newline that the --null output would not
2116 # include. Add it here to make the two comparable.
2117 echo >>output &&
2118 test_cmp expect output
2121 test_expect_success '--show-origin with single file' '
2122 cat >expect <<-\EOF &&
2123 file:.git/config user.local=true
2124 file:.git/config user.override=local
2125 file:.git/config include.path=../include/relative.include
2127 git config --local --list --show-origin >output &&
2128 test_cmp expect output
2131 test_expect_success '--show-origin with --get-regexp' '
2132 cat >expect <<-EOF &&
2133 file:$HOME/.gitconfig user.global true
2134 file:.git/config user.local true
2136 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
2137 test_cmp expect output
2140 test_expect_success '--show-origin getting a single key' '
2141 cat >expect <<-\EOF &&
2142 file:.git/config local
2144 git config --show-origin user.override >output &&
2145 test_cmp expect output
2148 test_expect_success 'set up custom config file' '
2149 cat >"custom.conf" <<-\EOF &&
2150 [user]
2151 custom = true
2153 CUSTOM_CONFIG_FILE="$(test-tool path-utils real_path custom.conf)"
2156 test_expect_success !MINGW 'set up custom config file with special name characters' '
2157 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2158 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2161 test_expect_success !MINGW '--show-origin escape special file name characters' '
2162 cat >expect <<-\EOF &&
2163 file:"file\" (dq) and spaces.conf" user.custom=true
2165 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2166 test_cmp expect output
2169 test_expect_success '--show-origin stdin' '
2170 cat >expect <<-\EOF &&
2171 standard input: user.custom=true
2173 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2174 test_cmp expect output
2177 test_expect_success '--show-origin stdin with file include' '
2178 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2179 [user]
2180 stdin = include
2182 cat >expect <<-EOF &&
2183 file:$INCLUDE_DIR/stdin.include include
2185 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2186 git config --show-origin --includes --file - user.stdin >output &&
2188 test_cmp expect output
2191 test_expect_success '--show-origin blob' '
2192 test_when_finished "rm -rf repo" &&
2193 git init repo &&
2195 cd repo &&
2196 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2197 cat >expect <<-EOF &&
2198 blob:$blob user.custom=true
2200 git config --blob=$blob --show-origin --list >output &&
2201 test_cmp expect output
2205 test_expect_success '--show-origin blob ref' '
2206 test_when_finished "rm -rf repo" &&
2207 git init repo &&
2209 cd repo &&
2210 cat >expect <<-\EOF &&
2211 blob:main:custom.conf user.custom=true
2213 cp "$CUSTOM_CONFIG_FILE" custom.conf &&
2214 git add custom.conf &&
2215 git commit -m "new config file" &&
2216 git config --blob=main:custom.conf --show-origin --list >output &&
2217 test_cmp expect output
2221 test_expect_success '--show-origin with --default' '
2222 git config --show-origin --default foo some.key >actual &&
2223 echo "command line: foo" >expect &&
2224 test_cmp expect actual
2227 test_expect_success '--show-scope with --list' '
2228 cat >expect <<-EOF &&
2229 global user.global=true
2230 global user.override=global
2231 global include.path=$INCLUDE_DIR/absolute.include
2232 global user.absolute=include
2233 local user.local=true
2234 local user.override=local
2235 local include.path=../include/relative.include
2236 local user.relative=include
2237 local core.repositoryformatversion=1
2238 local extensions.worktreeconfig=true
2239 worktree user.worktree=true
2240 command user.cmdline=true
2242 git worktree add wt1 &&
2243 # We need these to test for worktree scope, but outside of this
2244 # test, this is just noise
2245 test_config core.repositoryformatversion 1 &&
2246 test_config extensions.worktreeConfig true &&
2247 git config --worktree user.worktree true &&
2248 git -c user.cmdline=true config --list --show-scope >output &&
2249 test_cmp expect output
2252 test_expect_success !MINGW '--show-scope with --blob' '
2253 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2254 cat >expect <<-EOF &&
2255 command user.custom=true
2257 git config --blob=$blob --show-scope --list >output &&
2258 test_cmp expect output
2261 test_expect_success '--show-scope with --local' '
2262 cat >expect <<-\EOF &&
2263 local user.local=true
2264 local user.override=local
2265 local include.path=../include/relative.include
2267 git config --local --list --show-scope >output &&
2268 test_cmp expect output
2271 test_expect_success '--show-scope getting a single value' '
2272 cat >expect <<-\EOF &&
2273 local true
2275 git config --show-scope --get user.local >output &&
2276 test_cmp expect output
2279 test_expect_success '--show-scope with --show-origin' '
2280 cat >expect <<-EOF &&
2281 global file:$HOME/.gitconfig user.global=true
2282 global file:$HOME/.gitconfig user.override=global
2283 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2284 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2285 local file:.git/config user.local=true
2286 local file:.git/config user.override=local
2287 local file:.git/config include.path=../include/relative.include
2288 local file:.git/../include/relative.include user.relative=include
2289 command command line: user.cmdline=true
2291 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2292 test_cmp expect output
2295 test_expect_success '--show-scope with --default' '
2296 git config --show-scope --default foo some.key >actual &&
2297 echo "command foo" >expect &&
2298 test_cmp expect actual
2301 test_expect_success 'override global and system config' '
2302 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2303 cat >"$HOME"/.gitconfig <<-EOF &&
2304 [home]
2305 config = true
2308 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2309 mkdir -p "$HOME"/.config/git &&
2310 cat >"$HOME"/.config/git/config <<-EOF &&
2311 [xdg]
2312 config = true
2314 cat >.git/config <<-EOF &&
2315 [local]
2316 config = true
2318 cat >custom-global-config <<-EOF &&
2319 [global]
2320 config = true
2322 cat >custom-system-config <<-EOF &&
2323 [system]
2324 config = true
2327 cat >expect <<-EOF &&
2328 global xdg.config=true
2329 global home.config=true
2330 local local.config=true
2332 git config --show-scope --list >output &&
2333 test_cmp expect output &&
2335 cat >expect <<-EOF &&
2336 system system.config=true
2337 global global.config=true
2338 local local.config=true
2340 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2341 git config --show-scope --list >output &&
2342 test_cmp expect output &&
2344 cat >expect <<-EOF &&
2345 local local.config=true
2347 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2348 git config --show-scope --list >output &&
2349 test_cmp expect output
2352 test_expect_success 'override global and system config with missing file' '
2353 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2354 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2355 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2358 test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2359 # `git config --system` has different semantics compared to other
2360 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2361 # variable has an effect via a different proxy.
2362 cat >alias-config <<-EOF &&
2363 [alias]
2364 hello-world = !echo "hello world"
2366 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2367 git hello-world &&
2368 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2369 git hello-world >actual &&
2370 echo "hello world" >expect &&
2371 test_cmp expect actual
2374 test_expect_success 'write to overridden global and system config' '
2375 cat >expect <<EOF &&
2376 [config]
2377 key = value
2380 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2381 test_cmp expect write-to-global &&
2383 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2384 test_cmp expect write-to-system
2387 for opt in --local --worktree
2389 test_expect_success "$opt requires a repo" '
2390 # we expect 128 to ensure that we do not simply
2391 # fail to find anything and return code "1"
2392 test_expect_code 128 nongit git config $opt foo.bar
2394 done
2396 cat >.git/config <<-\EOF &&
2397 [section]
2398 foo = true
2399 number = 10
2400 big = 1M
2403 test_expect_success 'identical modern --type specifiers are allowed' '
2404 test_cmp_config 1048576 --type=int --type=int section.big
2407 test_expect_success 'identical legacy --type specifiers are allowed' '
2408 test_cmp_config 1048576 --int --int section.big
2411 test_expect_success 'identical mixed --type specifiers are allowed' '
2412 test_cmp_config 1048576 --int --type=int section.big
2415 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2416 test_must_fail git config --type=int --type=bool section.big 2>error &&
2417 test_grep "only one type at a time" error
2420 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2421 test_must_fail git config --int --bool section.big 2>error &&
2422 test_grep "only one type at a time" error
2425 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2426 test_must_fail git config --type=int --bool section.big 2>error &&
2427 test_grep "only one type at a time" error
2430 test_expect_success '--type allows valid type specifiers' '
2431 test_cmp_config true --type=bool section.foo
2434 test_expect_success '--no-type unsets type specifiers' '
2435 test_cmp_config 10 --type=bool --no-type section.number
2438 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2439 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2442 test_expect_success '--type rejects unknown specifiers' '
2443 test_must_fail git config --type=nonsense section.foo 2>error &&
2444 test_grep "unrecognized --type argument" error
2447 test_expect_success '--type=int requires at least one digit' '
2448 test_must_fail git config --type int --default m some.key >out 2>error &&
2449 grep "bad numeric config value" error &&
2450 test_must_be_empty out
2453 test_expect_success '--replace-all does not invent newlines' '
2454 q_to_tab >.git/config <<-\EOF &&
2455 [abc]key
2456 QkeepSection
2457 [xyz]
2458 Qkey = 1
2459 [abc]
2460 Qkey = a
2462 q_to_tab >expect <<-\EOF &&
2463 [abc]
2464 QkeepSection
2465 [xyz]
2466 Qkey = 1
2467 [abc]
2468 Qkey = b
2470 git config --replace-all abc.key b &&
2471 test_cmp expect .git/config
2474 test_expect_success 'set all config with value-pattern' '
2475 test_when_finished rm -f config initial &&
2476 git config --file=initial abc.key one &&
2478 # no match => add new entry
2479 cp initial config &&
2480 git config --file=config abc.key two a+ &&
2481 git config --file=config --list >actual &&
2482 cat >expect <<-\EOF &&
2483 abc.key=one
2484 abc.key=two
2486 test_cmp expect actual &&
2488 # multiple matches => failure
2489 test_must_fail git config --file=config abc.key three o+ 2>err &&
2490 test_grep "has multiple values" err &&
2492 # multiple values, no match => add
2493 git config --file=config abc.key three a+ &&
2494 git config --file=config --list >actual &&
2495 cat >expect <<-\EOF &&
2496 abc.key=one
2497 abc.key=two
2498 abc.key=three
2500 test_cmp expect actual &&
2502 # single match => replace
2503 git config --file=config abc.key four h+ &&
2504 git config --file=config --list >actual &&
2505 cat >expect <<-\EOF &&
2506 abc.key=one
2507 abc.key=two
2508 abc.key=four
2510 test_cmp expect actual
2513 test_expect_success '--replace-all and value-pattern' '
2514 test_when_finished rm -f config &&
2515 git config --file=config --add abc.key one &&
2516 git config --file=config --add abc.key two &&
2517 git config --file=config --add abc.key three &&
2518 git config --file=config --replace-all abc.key four "o+" &&
2519 git config --file=config --list >actual &&
2520 cat >expect <<-\EOF &&
2521 abc.key=four
2522 abc.key=three
2524 test_cmp expect actual
2527 test_expect_success 'refuse --fixed-value for incompatible actions' '
2528 test_when_finished rm -f config &&
2529 git config --file=config dev.null bogus &&
2531 # These modes do not allow --fixed-value at all
2532 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2533 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2534 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2535 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2536 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2537 test_must_fail git config --file=config --fixed-value --list &&
2538 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2539 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2541 # These modes complain when --fixed-value has no value-pattern
2542 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2543 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2544 test_must_fail git config --file=config --fixed-value --get dev.null &&
2545 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2546 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2547 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2548 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2551 test_expect_success '--fixed-value uses exact string matching' '
2552 test_when_finished rm -f config initial &&
2553 META="a+b*c?d[e]f.g" &&
2554 git config --file=initial fixed.test "$META" &&
2556 cp initial config &&
2557 git config --file=config fixed.test bogus "$META" &&
2558 git config --file=config --list >actual &&
2559 cat >expect <<-EOF &&
2560 fixed.test=$META
2561 fixed.test=bogus
2563 test_cmp expect actual &&
2565 cp initial config &&
2566 git config --file=config --fixed-value fixed.test bogus "$META" &&
2567 git config --file=config --list >actual &&
2568 cat >expect <<-\EOF &&
2569 fixed.test=bogus
2571 test_cmp expect actual &&
2573 cp initial config &&
2574 test_must_fail git config --file=config --unset fixed.test "$META" &&
2575 git config --file=config --fixed-value --unset fixed.test "$META" &&
2576 test_must_fail git config --file=config fixed.test &&
2578 cp initial config &&
2579 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2580 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2581 test_must_fail git config --file=config fixed.test &&
2583 cp initial config &&
2584 git config --file=config --replace-all fixed.test bogus "$META" &&
2585 git config --file=config --list >actual &&
2586 cat >expect <<-EOF &&
2587 fixed.test=$META
2588 fixed.test=bogus
2590 test_cmp expect actual &&
2592 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2593 git config --file=config --list >actual &&
2594 cat >expect <<-EOF &&
2595 fixed.test=bogus
2596 fixed.test=bogus
2598 test_cmp expect actual
2601 test_expect_success '--get and --get-all with --fixed-value' '
2602 test_when_finished rm -f config &&
2603 META="a+b*c?d[e]f.g" &&
2604 git config --file=config fixed.test bogus &&
2605 git config --file=config --add fixed.test "$META" &&
2607 git config --file=config --get fixed.test bogus &&
2608 test_must_fail git config --file=config --get fixed.test "$META" &&
2609 git config --file=config --get --fixed-value fixed.test "$META" &&
2610 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2612 git config --file=config --get-all fixed.test bogus &&
2613 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2614 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2615 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2617 git config --file=config --get-regexp fixed+ bogus &&
2618 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2619 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2620 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2623 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2624 git init hasremoteurlTest &&
2625 test_when_finished "rm -rf hasremoteurlTest" &&
2627 cat >include-this <<-\EOF &&
2628 [user]
2629 this = this-is-included
2631 cat >dont-include-that <<-\EOF &&
2632 [user]
2633 that = that-is-not-included
2635 cat >>hasremoteurlTest/.git/config <<-EOF &&
2636 [includeIf "hasconfig:remote.*.url:foourl"]
2637 path = "$(pwd)/include-this"
2638 [includeIf "hasconfig:remote.*.url:barurl"]
2639 path = "$(pwd)/dont-include-that"
2640 [remote "foo"]
2641 url = foourl
2644 echo this-is-included >expect-this &&
2645 git -C hasremoteurlTest config --get user.this >actual-this &&
2646 test_cmp expect-this actual-this &&
2648 test_must_fail git -C hasremoteurlTest config --get user.that
2651 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2652 git init hasremoteurlTest &&
2653 test_when_finished "rm -rf hasremoteurlTest" &&
2655 cat >include-two-three <<-\EOF &&
2656 [user]
2657 two = included-config
2658 three = included-config
2660 cat >>hasremoteurlTest/.git/config <<-EOF &&
2661 [remote "foo"]
2662 url = foourl
2663 [user]
2664 one = main-config
2665 two = main-config
2666 [includeIf "hasconfig:remote.*.url:foourl"]
2667 path = "$(pwd)/include-two-three"
2668 [user]
2669 three = main-config
2672 echo main-config >expect-main-config &&
2673 echo included-config >expect-included-config &&
2675 git -C hasremoteurlTest config --get user.one >actual &&
2676 test_cmp expect-main-config actual &&
2678 git -C hasremoteurlTest config --get user.two >actual &&
2679 test_cmp expect-included-config actual &&
2681 git -C hasremoteurlTest config --get user.three >actual &&
2682 test_cmp expect-main-config actual
2685 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2686 git init hasremoteurlTest &&
2687 test_when_finished "rm -rf hasremoteurlTest" &&
2689 printf "[user]\ndss = yes\n" >double-star-start &&
2690 printf "[user]\ndse = yes\n" >double-star-end &&
2691 printf "[user]\ndsm = yes\n" >double-star-middle &&
2692 printf "[user]\nssm = yes\n" >single-star-middle &&
2693 printf "[user]\nno = no\n" >no &&
2695 cat >>hasremoteurlTest/.git/config <<-EOF &&
2696 [remote "foo"]
2697 url = https://foo/bar/baz
2698 [includeIf "hasconfig:remote.*.url:**/baz"]
2699 path = "$(pwd)/double-star-start"
2700 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2701 path = "$(pwd)/no"
2702 [includeIf "hasconfig:remote.*.url:https:/**"]
2703 path = "$(pwd)/double-star-end"
2704 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2705 path = "$(pwd)/no"
2706 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2707 path = "$(pwd)/double-star-middle"
2708 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2709 path = "$(pwd)/no"
2710 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2711 path = "$(pwd)/single-star-middle"
2712 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2713 path = "$(pwd)/no"
2716 git -C hasremoteurlTest config --get user.dss &&
2717 git -C hasremoteurlTest config --get user.dse &&
2718 git -C hasremoteurlTest config --get user.dsm &&
2719 git -C hasremoteurlTest config --get user.ssm &&
2720 test_must_fail git -C hasremoteurlTest config --get user.no
2723 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2724 git init hasremoteurlTest &&
2725 test_when_finished "rm -rf hasremoteurlTest" &&
2727 cat >include-with-url <<-\EOF &&
2728 [remote "bar"]
2729 url = barurl
2731 cat >>hasremoteurlTest/.git/config <<-EOF &&
2732 [includeIf "hasconfig:remote.*.url:foourl"]
2733 path = "$(pwd)/include-with-url"
2736 # test with any Git command
2737 test_must_fail git -C hasremoteurlTest status 2>err &&
2738 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err
2741 test_expect_success 'negated mode causes failure' '
2742 test_must_fail git config --no-get 2>err &&
2743 grep "unknown option \`no-get${SQ}" err
2746 test_expect_success 'specifying multiple modes causes failure' '
2747 cat >expect <<-EOF &&
2748 error: options ${SQ}--get-all${SQ} and ${SQ}--get${SQ} cannot be used together
2750 test_must_fail git config --get --get-all 2>err &&
2751 test_cmp expect err
2754 test_done