t1300: add more tests for whitespace and inline comments
[git.git] / t / t1300-config.sh
blob624ed7545f5421e43818fddef23a0f0766c8f0bb
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 penguin = very blue
165 Movie = BadPhysics
166 UPPERCASE = true
167 penguin = kingpin
168 [Sections]
169 WhatEver = Second
172 test_expect_success 'non-match result' 'test_cmp expect .git/config'
174 test_expect_success 'find mixed-case key by canonical name' '
175 test_cmp_config Second sections.whatever
178 test_expect_success 'find mixed-case key by non-canonical name' '
179 test_cmp_config Second SeCtIoNs.WhAtEvEr
182 test_expect_success 'subsections are not canonicalized by git-config' '
183 cat >>.git/config <<-\EOF &&
184 [section.SubSection]
185 key = one
186 [section "SubSection"]
187 key = two
189 test_cmp_config one section.subsection.key &&
190 test_cmp_config two section.SubSection.key
193 test_missing_key () {
194 local key="$1" &&
195 local title="$2" &&
196 test_expect_success "value for $title is not printed" '
197 test_must_fail git config "$key" >out 2>err &&
198 test_must_be_empty out &&
199 test_must_be_empty err
203 test_missing_key 'missingsection.missingkey' 'missing section and missing key'
204 test_missing_key 'missingsection.penguin' 'missing section and existing key'
205 test_missing_key 'section.missingkey' 'existing section and missing key'
206 test_missing_key 'section.MissingSubSection.missingkey' 'missing subsection and missing key'
207 test_missing_key 'section.SubSection.missingkey' 'existing subsection and missing key'
208 test_missing_key 'section.MissingSubSection.key' 'missing subsection and existing key'
210 cat > .git/config <<\EOF
211 [alpha]
212 bar = foo
213 [beta]
214 baz = multiple \
215 lines
216 foo = bar
219 test_expect_success 'unset with cont. lines' '
220 git config --unset beta.baz
223 cat > expect <<\EOF
224 [alpha]
225 bar = foo
226 [beta]
227 foo = bar
230 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
232 cat > .git/config << EOF
233 [beta] ; silly comment # another comment
234 noIndent= sillyValue ; 'nother silly comment
236 # empty line
237 ; comment
238 haha ="beta" # last silly comment
239 haha = hello
240 haha = bello
241 [nextSection] noNewline = ouch
244 cp .git/config .git/config2
246 test_expect_success 'multiple unset' '
247 git config --unset-all beta.haha
250 cat > expect << EOF
251 [beta] ; silly comment # another comment
252 noIndent= sillyValue ; 'nother silly comment
254 # empty line
255 ; comment
256 [nextSection] noNewline = ouch
259 test_expect_success 'multiple unset is correct' '
260 test_cmp expect .git/config
263 cp .git/config2 .git/config
265 test_expect_success '--replace-all missing value' '
266 test_must_fail git config --replace-all beta.haha &&
267 test_cmp .git/config2 .git/config
270 rm .git/config2
272 test_expect_success '--replace-all' '
273 git config --replace-all beta.haha gamma
276 cat > expect << EOF
277 [beta] ; silly comment # another comment
278 noIndent= sillyValue ; 'nother silly comment
280 # empty line
281 ; comment
282 haha = gamma
283 [nextSection] noNewline = ouch
286 test_expect_success 'all replaced' '
287 test_cmp expect .git/config
290 cat > expect << EOF
291 [beta] ; silly comment # another comment
292 noIndent= sillyValue ; 'nother silly comment
294 # empty line
295 ; comment
296 haha = alpha
297 [nextSection] noNewline = ouch
299 test_expect_success 'really mean test' '
300 git config beta.haha alpha &&
301 test_cmp expect .git/config
304 cat > expect << EOF
305 [beta] ; silly comment # another comment
306 noIndent= sillyValue ; 'nother silly comment
308 # empty line
309 ; comment
310 haha = alpha
311 [nextSection]
312 nonewline = wow
314 test_expect_success 'really really mean test' '
315 git config nextsection.nonewline wow &&
316 test_cmp expect .git/config
319 test_expect_success 'get value' '
320 test_cmp_config alpha beta.haha
323 cat > expect << EOF
324 [beta] ; silly comment # another comment
325 noIndent= sillyValue ; 'nother silly comment
327 # empty line
328 ; comment
329 [nextSection]
330 nonewline = wow
332 test_expect_success 'unset' '
333 git config --unset beta.haha &&
334 test_cmp expect .git/config
337 cat > expect << EOF
338 [beta] ; silly comment # another comment
339 noIndent= sillyValue ; 'nother silly comment
341 # empty line
342 ; comment
343 [nextSection]
344 nonewline = wow
345 NoNewLine = wow2 for me
347 test_expect_success 'multivar' '
348 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
349 test_cmp expect .git/config
352 test_expect_success 'non-match' '
353 git config --get nextsection.nonewline !for
356 test_expect_success 'non-match value' '
357 test_cmp_config wow --get nextsection.nonewline !for
360 test_expect_success 'multi-valued get returns final one' '
361 test_cmp_config "wow2 for me" --get nextsection.nonewline
364 test_expect_success 'multi-valued get-all returns all' '
365 cat >expect <<-\EOF &&
367 wow2 for me
369 git config --get-all nextsection.nonewline >actual &&
370 test_cmp expect actual
373 cat > expect << EOF
374 [beta] ; silly comment # another comment
375 noIndent= sillyValue ; 'nother silly comment
377 # empty line
378 ; comment
379 [nextSection]
380 nonewline = wow3
381 NoNewLine = wow2 for me
383 test_expect_success 'multivar replace' '
384 git config nextsection.nonewline "wow3" "wow$" &&
385 test_cmp expect .git/config
388 test_expect_success 'ambiguous unset' '
389 test_must_fail git config --unset nextsection.nonewline
392 test_expect_success 'invalid unset' '
393 test_must_fail git config --unset somesection.nonewline
396 cat > expect << EOF
397 [beta] ; silly comment # another comment
398 noIndent= sillyValue ; 'nother silly comment
400 # empty line
401 ; comment
402 [nextSection]
403 NoNewLine = wow2 for me
406 test_expect_success 'multivar unset' '
407 git config --unset nextsection.nonewline "wow3$" &&
408 test_cmp expect .git/config
411 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
413 test_expect_success 'correct key' 'git config 123456.a123 987'
415 test_expect_success 'hierarchical section' '
416 git config Version.1.2.3eX.Alpha beta
419 cat > expect << EOF
420 [beta] ; silly comment # another comment
421 noIndent= sillyValue ; 'nother silly comment
423 # empty line
424 ; comment
425 [nextSection]
426 NoNewLine = wow2 for me
427 [123456]
428 a123 = 987
429 [Version "1.2.3eX"]
430 Alpha = beta
433 test_expect_success 'hierarchical section value' '
434 test_cmp expect .git/config
437 cat > expect << EOF
438 beta.noindent=sillyValue
439 nextsection.nonewline=wow2 for me
440 123456.a123=987
441 version.1.2.3eX.alpha=beta
444 test_expect_success 'working --list' '
445 git config --list > output &&
446 test_cmp expect output
448 test_expect_success '--list without repo produces empty output' '
449 git --git-dir=nonexistent config --list >output &&
450 test_must_be_empty output
453 cat > expect << EOF
454 beta.noindent
455 nextsection.nonewline
456 123456.a123
457 version.1.2.3eX.alpha
460 test_expect_success '--name-only --list' '
461 git config --name-only --list >output &&
462 test_cmp expect output
465 cat > expect << EOF
466 beta.noindent sillyValue
467 nextsection.nonewline wow2 for me
470 test_expect_success '--get-regexp' '
471 git config --get-regexp in >output &&
472 test_cmp expect output
475 cat > expect << EOF
476 beta.noindent
477 nextsection.nonewline
480 test_expect_success '--name-only --get-regexp' '
481 git config --name-only --get-regexp in >output &&
482 test_cmp expect output
485 cat > expect << EOF
486 wow2 for me
487 wow4 for you
490 test_expect_success '--add' '
491 git config --add nextsection.nonewline "wow4 for you" &&
492 git config --get-all nextsection.nonewline > output &&
493 test_cmp expect output
496 cat > .git/config << EOF
497 [novalue]
498 variable
499 [emptyvalue]
500 variable =
503 test_expect_success 'get variable with no value' '
504 git config --get novalue.variable ^$
507 test_expect_success 'get variable with empty value' '
508 git config --get emptyvalue.variable ^$
511 echo novalue.variable > expect
513 test_expect_success 'get-regexp variable with no value' '
514 git config --get-regexp novalue > output &&
515 test_cmp expect output
518 echo 'novalue.variable true' > expect
520 test_expect_success 'get-regexp --bool variable with no value' '
521 git config --bool --get-regexp novalue > output &&
522 test_cmp expect output
525 echo 'emptyvalue.variable ' > expect
527 test_expect_success 'get-regexp variable with empty value' '
528 git config --get-regexp emptyvalue > output &&
529 test_cmp expect output
532 echo true > expect
534 test_expect_success 'get bool variable with no value' '
535 git config --bool novalue.variable > output &&
536 test_cmp expect output
539 echo false > expect
541 test_expect_success 'get bool variable with empty value' '
542 git config --bool emptyvalue.variable > output &&
543 test_cmp expect output
546 test_expect_success 'no arguments, but no crash' '
547 test_must_fail git config >output 2>&1 &&
548 test_i18ngrep usage output
551 cat > .git/config << EOF
552 [a.b]
553 c = d
556 cat > expect << EOF
557 [a.b]
558 c = d
560 x = y
563 test_expect_success 'new section is partial match of another' '
564 git config a.x y &&
565 test_cmp expect .git/config
568 cat > expect << EOF
569 [a.b]
570 c = d
572 x = y
573 b = c
575 x = y
578 test_expect_success 'new variable inserts into proper section' '
579 git config b.x y &&
580 git config a.b c &&
581 test_cmp expect .git/config
584 test_expect_success 'alternative --file (non-existing file should fail)' '
585 test_must_fail git config --file non-existing-config -l &&
586 test_must_fail git config --file non-existing-config test.xyzzy
589 cat > other-config << EOF
590 [ein]
591 bahn = strasse
594 cat > expect << EOF
595 ein.bahn=strasse
598 test_expect_success 'alternative GIT_CONFIG' '
599 GIT_CONFIG=other-config git config --list >output &&
600 test_cmp expect output
603 test_expect_success 'alternative GIT_CONFIG (--file)' '
604 git config --file other-config --list >output &&
605 test_cmp expect output
608 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
609 git config --file - --list <other-config >output &&
610 test_cmp expect output
613 test_expect_success 'setting a value in stdin is an error' '
614 test_must_fail git config --file - some.value foo
617 test_expect_success 'editing stdin is an error' '
618 test_must_fail git config --file - --edit
621 test_expect_success 'refer config from subdirectory' '
622 mkdir x &&
623 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
626 cat > expect << EOF
627 [ein]
628 bahn = strasse
629 [anwohner]
630 park = ausweis
633 test_expect_success '--set in alternative file' '
634 git config --file=other-config anwohner.park ausweis &&
635 test_cmp expect other-config
638 cat > .git/config << EOF
639 # Hallo
640 #Bello
641 [branch "eins"]
642 x = 1
643 [branch.eins]
644 y = 1
645 [branch "1 234 blabl/a"]
646 weird
649 test_expect_success 'rename section' '
650 git config --rename-section branch.eins branch.zwei
653 cat > expect << EOF
654 # Hallo
655 #Bello
656 [branch "zwei"]
657 x = 1
658 [branch "zwei"]
659 y = 1
660 [branch "1 234 blabl/a"]
661 weird
664 test_expect_success 'rename succeeded' '
665 test_cmp expect .git/config
668 test_expect_success 'rename non-existing section' '
669 test_must_fail git config --rename-section \
670 branch."world domination" branch.drei
673 test_expect_success 'rename succeeded' '
674 test_cmp expect .git/config
677 test_expect_success 'rename another section' '
678 git config --rename-section branch."1 234 blabl/a" branch.drei
681 cat > expect << EOF
682 # Hallo
683 #Bello
684 [branch "zwei"]
685 x = 1
686 [branch "zwei"]
687 y = 1
688 [branch "drei"]
689 weird
692 test_expect_success 'rename succeeded' '
693 test_cmp expect .git/config
696 cat >> .git/config << EOF
697 [branch "vier"] z = 1
700 test_expect_success 'rename a section with a var on the same line' '
701 git config --rename-section branch.vier branch.zwei
704 cat > expect << EOF
705 # Hallo
706 #Bello
707 [branch "zwei"]
708 x = 1
709 [branch "zwei"]
710 y = 1
711 [branch "drei"]
712 weird
713 [branch "zwei"]
714 z = 1
717 test_expect_success 'rename succeeded' '
718 test_cmp expect .git/config
721 test_expect_success 'renaming empty section name is rejected' '
722 test_must_fail git config --rename-section branch.zwei ""
725 test_expect_success 'renaming to bogus section is rejected' '
726 test_must_fail git config --rename-section branch.zwei "bogus name"
729 test_expect_success 'renaming a section with a long line' '
731 printf "[b]\\n" &&
732 printf " c = d %1024s [a] e = f\\n" " " &&
733 printf "[a] g = h\\n"
734 } >y &&
735 git config -f y --rename-section a xyz &&
736 test_must_fail git config -f y b.e
739 test_expect_success 'renaming an embedded section with a long line' '
741 printf "[b]\\n" &&
742 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
743 printf "[a] g = h\\n"
744 } >y &&
745 git config -f y --rename-section a xyz &&
746 test_must_fail git config -f y foo.e
749 test_expect_success 'renaming a section with an overly-long line' '
751 printf "[b]\\n" &&
752 printf " c = d %525000s e" " " &&
753 printf "[a] g = h\\n"
754 } >y &&
755 test_must_fail git config -f y --rename-section a xyz 2>err &&
756 grep "refusing to work with overly long line in .y. on line 2" err
759 cat >> .git/config << EOF
760 [branch "zwei"] a = 1 [branch "vier"]
763 test_expect_success 'remove section' '
764 git config --remove-section branch.zwei
767 cat > expect << EOF
768 # Hallo
769 #Bello
770 [branch "drei"]
771 weird
774 test_expect_success 'section was removed properly' '
775 test_cmp expect .git/config
778 cat > expect << EOF
779 [gitcvs]
780 enabled = true
781 dbname = %Ggitcvs2.%a.%m.sqlite
782 [gitcvs "ext"]
783 dbname = %Ggitcvs1.%a.%m.sqlite
786 test_expect_success 'section ending' '
787 rm -f .git/config &&
788 git config gitcvs.enabled true &&
789 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
790 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
791 test_cmp expect .git/config
795 test_expect_success numbers '
796 git config kilo.gram 1k &&
797 git config mega.ton 1m &&
798 echo 1024 >expect &&
799 echo 1048576 >>expect &&
800 git config --int --get kilo.gram >actual &&
801 git config --int --get mega.ton >>actual &&
802 test_cmp expect actual
805 test_expect_success '--int is at least 64 bits' '
806 git config giga.watts 121g &&
807 echo >expect &&
808 test_cmp_config 129922760704 --int --get giga.watts
811 test_expect_success 'invalid unit' '
812 git config aninvalid.unit "1auto" &&
813 test_cmp_config 1auto aninvalid.unit &&
814 test_must_fail git config --int --get aninvalid.unit 2>actual &&
815 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
818 test_expect_success 'invalid unit boolean' '
819 git config commit.gpgsign "1true" &&
820 test_cmp_config 1true commit.gpgsign &&
821 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
822 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
825 test_expect_success 'line number is reported correctly' '
826 printf "[bool]\n\tvar\n" >invalid &&
827 test_must_fail git config -f invalid --path bool.var 2>actual &&
828 test_i18ngrep "line 2" actual
831 test_expect_success 'invalid stdin config' '
832 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
833 test_i18ngrep "bad config line 1 in standard input" output
836 cat > expect << EOF
837 true
838 false
839 true
840 false
841 true
842 false
843 true
844 false
847 test_expect_success bool '
849 git config bool.true1 01 &&
850 git config bool.true2 -1 &&
851 git config bool.true3 YeS &&
852 git config bool.true4 true &&
853 git config bool.false1 000 &&
854 git config bool.false2 "" &&
855 git config bool.false3 nO &&
856 git config bool.false4 FALSE &&
857 rm -f result &&
858 for i in 1 2 3 4
860 git config --bool --get bool.true$i >>result &&
861 git config --bool --get bool.false$i >>result || return 1
862 done &&
863 test_cmp expect result'
865 test_expect_success 'invalid bool (--get)' '
867 git config bool.nobool foobar &&
868 test_must_fail git config --bool --get bool.nobool'
870 test_expect_success 'invalid bool (set)' '
872 test_must_fail git config --bool bool.nobool foobar'
874 cat > expect <<\EOF
875 [bool]
876 true1 = true
877 true2 = true
878 true3 = true
879 true4 = true
880 false1 = false
881 false2 = false
882 false3 = false
883 false4 = false
886 test_expect_success 'set --bool' '
888 rm -f .git/config &&
889 git config --bool bool.true1 01 &&
890 git config --bool bool.true2 -1 &&
891 git config --bool bool.true3 YeS &&
892 git config --bool bool.true4 true &&
893 git config --bool bool.false1 000 &&
894 git config --bool bool.false2 "" &&
895 git config --bool bool.false3 nO &&
896 git config --bool bool.false4 FALSE &&
897 test_cmp expect .git/config'
899 cat > expect <<\EOF
900 [int]
901 val1 = 1
902 val2 = -1
903 val3 = 5242880
906 test_expect_success 'set --int' '
908 rm -f .git/config &&
909 git config --int int.val1 01 &&
910 git config --int int.val2 -1 &&
911 git config --int int.val3 5m &&
912 test_cmp expect .git/config
915 test_expect_success 'get --bool-or-int' '
916 cat >.git/config <<-\EOF &&
917 [bool]
918 true1
919 true2 = true
920 false = false
921 [int]
922 int1 = 0
923 int2 = 1
924 int3 = -1
926 cat >expect <<-\EOF &&
927 true
928 true
929 false
935 git config --bool-or-int bool.true1 &&
936 git config --bool-or-int bool.true2 &&
937 git config --bool-or-int bool.false &&
938 git config --bool-or-int int.int1 &&
939 git config --bool-or-int int.int2 &&
940 git config --bool-or-int int.int3
941 } >actual &&
942 test_cmp expect actual
945 cat >expect <<\EOF
946 [bool]
947 true1 = true
948 false1 = false
949 true2 = true
950 false2 = false
951 [int]
952 int1 = 0
953 int2 = 1
954 int3 = -1
957 test_expect_success 'set --bool-or-int' '
958 rm -f .git/config &&
959 git config --bool-or-int bool.true1 true &&
960 git config --bool-or-int bool.false1 false &&
961 git config --bool-or-int bool.true2 yes &&
962 git config --bool-or-int bool.false2 no &&
963 git config --bool-or-int int.int1 0 &&
964 git config --bool-or-int int.int2 1 &&
965 git config --bool-or-int int.int3 -1 &&
966 test_cmp expect .git/config
969 cat >expect <<\EOF
970 [path]
971 home = ~/
972 normal = /dev/null
973 trailingtilde = foo~
976 test_expect_success !MINGW 'set --path' '
977 rm -f .git/config &&
978 git config --path path.home "~/" &&
979 git config --path path.normal "/dev/null" &&
980 git config --path path.trailingtilde "foo~" &&
981 test_cmp expect .git/config'
983 if test_have_prereq !MINGW && test "${HOME+set}"
984 then
985 test_set_prereq HOMEVAR
988 cat >expect <<EOF
989 $HOME/
990 /dev/null
991 foo~
994 test_expect_success HOMEVAR 'get --path' '
995 git config --get --path path.home > result &&
996 git config --get --path path.normal >> result &&
997 git config --get --path path.trailingtilde >> result &&
998 test_cmp expect result
1001 cat >expect <<\EOF
1002 /dev/null
1003 foo~
1006 test_expect_success !MINGW 'get --path copes with unset $HOME' '
1008 sane_unset HOME &&
1009 test_must_fail git config --get --path path.home \
1010 >result 2>msg &&
1011 git config --get --path path.normal >>result &&
1012 git config --get --path path.trailingtilde >>result
1013 ) &&
1014 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
1015 test_cmp expect result
1018 test_expect_success 'get --path barfs on boolean variable' '
1019 echo "[path]bool" >.git/config &&
1020 test_must_fail git config --get --path path.bool
1023 test_expect_success 'get --expiry-date' '
1024 rel="3.weeks.5.days.00:00" &&
1025 rel_out="$rel ->" &&
1026 cat >.git/config <<-\EOF &&
1027 [date]
1028 valid1 = "3.weeks.5.days 00:00"
1029 valid2 = "Fri Jun 4 15:46:55 2010"
1030 valid3 = "2017/11/11 11:11:11PM"
1031 valid4 = "2017/11/10 09:08:07 PM"
1032 valid5 = "never"
1033 invalid1 = "abc"
1035 cat >expect <<-EOF &&
1036 $(test-tool date timestamp $rel)
1037 1275666415
1038 1510441871
1039 1510348087
1042 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
1044 echo "$rel_out $(git config --expiry-date date.valid1)" &&
1045 git config --expiry-date date.valid2 &&
1046 git config --expiry-date date.valid3 &&
1047 git config --expiry-date date.valid4 &&
1048 git config --expiry-date date.valid5
1049 } >actual &&
1050 test_cmp expect actual &&
1051 test_must_fail git config --expiry-date date.invalid1
1054 test_expect_success 'get --type=color' '
1055 rm .git/config &&
1056 git config foo.color "red" &&
1057 git config --get --type=color foo.color >actual.raw &&
1058 test_decode_color <actual.raw >actual &&
1059 echo "<RED>" >expect &&
1060 test_cmp expect actual
1063 cat >expect << EOF
1064 [foo]
1065 color = red
1068 test_expect_success 'set --type=color' '
1069 rm .git/config &&
1070 git config --type=color foo.color "red" &&
1071 test_cmp expect .git/config
1074 test_expect_success 'get --type=color barfs on non-color' '
1075 echo "[foo]bar=not-a-color" >.git/config &&
1076 test_must_fail git config --get --type=color foo.bar
1079 test_expect_success 'set --type=color barfs on non-color' '
1080 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
1081 test_i18ngrep "cannot parse color" error
1084 cat > expect << EOF
1085 [quote]
1086 leading = " test"
1087 ending = "test "
1088 semicolon = "test;test"
1089 hash = "test#test"
1091 test_expect_success 'quoting' '
1092 rm -f .git/config &&
1093 git config quote.leading " test" &&
1094 git config quote.ending "test " &&
1095 git config quote.semicolon "test;test" &&
1096 git config quote.hash "test#test" &&
1097 test_cmp expect .git/config
1100 test_expect_success 'key with newline' '
1101 test_must_fail git config "key.with
1102 newline" 123'
1104 test_expect_success 'value with newline' 'git config key.sub value.with\\\
1105 newline'
1107 cat > .git/config <<\EOF
1108 [section]
1109 ; comment \
1110 continued = cont\
1111 inued
1112 noncont = not continued ; \
1113 quotecont = "cont;\
1114 inued"
1117 cat > expect <<\EOF
1118 section.continued=continued
1119 section.noncont=not continued
1120 section.quotecont=cont;inued
1123 test_expect_success 'value continued on next line' '
1124 git config --list > result &&
1125 test_cmp expect result
1128 cat > .git/config <<\EOF
1129 [section "sub=section"]
1130 val1 = foo=bar
1131 val2 = foo\nbar
1132 val3 = \n\n
1133 val4 =
1134 val5
1137 cat > expect <<\EOF
1138 section.sub=section.val1
1139 foo=barQsection.sub=section.val2
1141 barQsection.sub=section.val3
1144 Qsection.sub=section.val4
1145 Qsection.sub=section.val5Q
1147 test_expect_success '--null --list' '
1148 git config --null --list >result.raw &&
1149 nul_to_q <result.raw >result &&
1150 echo >>result &&
1151 test_cmp expect result
1154 test_expect_success '--null --get-regexp' '
1155 git config --null --get-regexp "val[0-9]" >result.raw &&
1156 nul_to_q <result.raw >result &&
1157 echo >>result &&
1158 test_cmp expect result
1161 test_expect_success 'inner whitespace kept verbatim, spaces only' '
1162 echo "foo bar" >expect &&
1163 git config section.val "foo bar" &&
1164 git config --get section.val >actual &&
1165 test_cmp expect actual
1168 test_expect_success 'inner whitespace kept verbatim, horizontal tabs only' '
1169 echo "fooQQbar" | q_to_tab >expect &&
1170 git config section.val "$(cat expect)" &&
1171 git config --get section.val >actual &&
1172 test_cmp expect actual
1175 test_expect_success 'inner whitespace kept verbatim, horizontal tabs and spaces' '
1176 echo "foo Q bar" | q_to_tab >expect &&
1177 git config section.val "$(cat expect)" &&
1178 git config --get section.val >actual &&
1179 test_cmp expect actual
1182 test_expect_success SYMLINKS 'symlinked configuration' '
1183 ln -s notyet myconfig &&
1184 git config --file=myconfig test.frotz nitfol &&
1185 test -h myconfig &&
1186 test -f notyet &&
1187 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1188 git config --file=myconfig test.xyzzy rezrov &&
1189 test -h myconfig &&
1190 test -f notyet &&
1191 cat >expect <<-\EOF &&
1192 nitfol
1193 rezrov
1196 git config --file=notyet test.frotz &&
1197 git config --file=notyet test.xyzzy
1198 } >actual &&
1199 test_cmp expect actual
1202 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1203 ln -s doesnotexist linktonada &&
1204 ln -s linktonada linktolinktonada &&
1205 test_must_fail git config --file=linktonada --list &&
1206 test_must_fail git config --file=linktolinktonada --list
1209 test_expect_success 'check split_cmdline return' "
1210 git config alias.split-cmdline-fix 'echo \"' &&
1211 test_must_fail git split-cmdline-fix &&
1212 echo foo > foo &&
1213 git add foo &&
1214 git commit -m 'initial commit' &&
1215 git config branch.main.mergeoptions 'echo \"' &&
1216 test_must_fail git merge main
1219 test_expect_success 'git -c "key=value" support' '
1220 cat >expect <<-\EOF &&
1221 value
1222 value
1223 true
1226 git -c section.name=value config section.name &&
1227 git -c foo.CamelCase=value config foo.camelcase &&
1228 git -c foo.flag config --bool foo.flag
1229 } >actual &&
1230 test_cmp expect actual &&
1231 test_must_fail git -c name=value config section.name
1234 # We just need a type-specifier here that cares about the
1235 # distinction internally between a NULL boolean and a real
1236 # string (because most of git's internal parsers do care).
1237 # Using "--path" works, but we do not otherwise care about
1238 # its semantics.
1239 test_expect_success 'git -c can represent empty string' '
1240 echo >expect &&
1241 git -c foo.empty= config --path foo.empty >actual &&
1242 test_cmp expect actual
1245 test_expect_success 'key sanity-checking' '
1246 test_must_fail git config foo=bar &&
1247 test_must_fail git config foo=.bar &&
1248 test_must_fail git config foo.ba=r &&
1249 test_must_fail git config foo.1bar &&
1250 test_must_fail git config foo."ba
1251 z".bar &&
1252 test_must_fail git config . false &&
1253 test_must_fail git config .foo false &&
1254 test_must_fail git config foo. false &&
1255 test_must_fail git config .foo. false &&
1256 git config foo.bar true &&
1257 git config foo."ba =z".bar false
1260 test_expect_success 'git -c works with aliases of builtins' '
1261 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1262 echo bar >expect &&
1263 git checkconfig >actual &&
1264 test_cmp expect actual
1267 test_expect_success 'aliases can be CamelCased' '
1268 test_config alias.CamelCased "rev-parse HEAD" &&
1269 git CamelCased >out &&
1270 git rev-parse HEAD >expect &&
1271 test_cmp expect out
1274 test_expect_success 'git -c does not split values on equals' '
1275 echo "value with = in it" >expect &&
1276 git -c section.foo="value with = in it" config section.foo >actual &&
1277 test_cmp expect actual
1280 test_expect_success 'git -c dies on bogus config' '
1281 test_must_fail git -c core.bare=foo rev-parse
1284 test_expect_success 'git -c complains about empty key' '
1285 test_must_fail git -c "=foo" rev-parse
1288 test_expect_success 'git -c complains about empty key and value' '
1289 test_must_fail git -c "" rev-parse
1292 test_expect_success 'multiple git -c appends config' '
1293 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1294 cat >expect <<-\EOF &&
1295 x.one 1
1296 x.two 2
1298 git -c x.one=1 x >actual &&
1299 test_cmp expect actual
1302 test_expect_success 'last one wins: two level vars' '
1304 # sec.var and sec.VAR are the same variable, as the first
1305 # and the last level of a configuration variable name is
1306 # case insensitive.
1308 echo VAL >expect &&
1310 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1311 test_cmp expect actual &&
1312 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1313 test_cmp expect actual &&
1315 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1316 test_cmp expect actual &&
1317 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1318 test_cmp expect actual
1321 test_expect_success 'last one wins: three level vars' '
1323 # v.a.r and v.A.r are not the same variable, as the middle
1324 # level of a three-level configuration variable name is
1325 # case sensitive.
1327 echo val >expect &&
1328 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1329 test_cmp expect actual &&
1330 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1331 test_cmp expect actual &&
1333 # v.a.r and V.a.R 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 &&
1338 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1339 test_cmp expect actual &&
1340 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1341 test_cmp expect actual &&
1342 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1343 test_cmp expect actual &&
1344 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1345 test_cmp expect actual
1348 test_expect_success 'old-fashioned settings are case insensitive' '
1349 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1351 cat >testConfig_actual <<-EOF &&
1352 [V.A]
1353 r = value1
1355 q_to_tab >testConfig_expect <<-EOF &&
1356 [V.A]
1357 Qr = value2
1359 git config -f testConfig_actual "v.a.r" value2 &&
1360 test_cmp testConfig_expect testConfig_actual &&
1362 cat >testConfig_actual <<-EOF &&
1363 [V.A]
1364 r = value1
1366 q_to_tab >testConfig_expect <<-EOF &&
1367 [V.A]
1368 QR = value2
1370 git config -f testConfig_actual "V.a.R" value2 &&
1371 test_cmp testConfig_expect testConfig_actual &&
1373 cat >testConfig_actual <<-EOF &&
1374 [V.A]
1375 r = value1
1377 q_to_tab >testConfig_expect <<-EOF &&
1378 [V.A]
1379 r = value1
1380 Qr = value2
1382 git config -f testConfig_actual "V.A.r" value2 &&
1383 test_cmp testConfig_expect testConfig_actual &&
1385 cat >testConfig_actual <<-EOF &&
1386 [V.A]
1387 r = value1
1389 q_to_tab >testConfig_expect <<-EOF &&
1390 [V.A]
1391 r = value1
1392 Qr = value2
1394 git config -f testConfig_actual "v.A.r" value2 &&
1395 test_cmp testConfig_expect testConfig_actual
1398 test_expect_success 'setting different case sensitive subsections ' '
1399 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1401 cat >testConfig_actual <<-EOF &&
1402 [V "A"]
1403 R = v1
1404 [K "E"]
1405 Y = v1
1406 [a "b"]
1407 c = v1
1408 [d "e"]
1409 f = v1
1411 q_to_tab >testConfig_expect <<-EOF &&
1412 [V "A"]
1413 Qr = v2
1414 [K "E"]
1415 Qy = v2
1416 [a "b"]
1417 Qc = v2
1418 [d "e"]
1419 f = v1
1420 [d "E"]
1421 Qf = v2
1423 # exact match
1424 git config -f testConfig_actual a.b.c v2 &&
1425 # match section and subsection, key is cased differently.
1426 git config -f testConfig_actual K.E.y v2 &&
1427 # section and key are matched case insensitive, but subsection needs
1428 # to match; When writing out new values only the key is adjusted
1429 git config -f testConfig_actual v.A.r v2 &&
1430 # subsection is not matched:
1431 git config -f testConfig_actual d.E.f v2 &&
1432 test_cmp testConfig_expect testConfig_actual
1435 for VAR in a .a a. a.0b a."b c". a."b c".0d
1437 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1438 test_must_fail git -c "$VAR=VAL" config -l
1440 done
1442 for VAR in a.b a."b c".d
1444 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1445 echo VAL >expect &&
1446 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1447 test_cmp expect actual
1449 done
1451 test_expect_success 'git -c is not confused by empty environment' '
1452 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1455 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1456 v="${SQ}key.one=foo${SQ}" &&
1457 v="$v ${SQ}key.two=bar${SQ}" &&
1458 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1459 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1460 cat >expect <<-EOF &&
1461 key.one foo
1462 key.two bar
1463 key.ambiguous section.whatever=value
1465 test_cmp expect actual
1468 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1469 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1470 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1471 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1472 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1473 cat >expect <<-EOF &&
1474 key.one foo
1475 key.two bar
1476 key.ambiguous=section.whatever value
1478 test_cmp expect actual
1481 test_expect_success 'old and new-style entries can mix' '
1482 v="${SQ}key.oldone=oldfoo${SQ}" &&
1483 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1484 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1485 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1486 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1487 cat >expect <<-EOF &&
1488 key.oldone oldfoo
1489 key.newone newfoo
1490 key.oldtwo oldbar
1491 key.newtwo newbar
1493 test_cmp expect actual
1496 test_expect_success 'old and new bools with ambiguous subsection' '
1497 v="${SQ}key.with=equals.oldbool${SQ}" &&
1498 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1499 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1500 cat >expect <<-EOF &&
1501 key.with equals.oldbool
1502 key.with=equals.newbool
1504 test_cmp expect actual
1507 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1508 cat >expect <<-\EOF &&
1509 env.one one
1510 env.two two
1512 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1513 git config --get-regexp "env.*" >actual &&
1514 test_cmp expect actual &&
1516 cat >expect <<-EOF &&
1517 env.one one${SQ}
1518 env.two two
1520 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1521 git config --get-regexp "env.*" >actual &&
1522 test_cmp expect actual &&
1524 test_must_fail env \
1525 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1526 git config --get-regexp "env.*"
1529 test_expect_success 'git --config-env=key=envvar support' '
1530 cat >expect <<-\EOF &&
1531 value
1532 value
1533 value
1534 value
1535 false
1536 false
1539 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1540 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1541 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1542 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1543 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1544 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1545 } >actual &&
1546 test_cmp expect actual
1549 test_expect_success 'git --config-env with missing value' '
1550 test_must_fail env ENVVAR=value git --config-env 2>error &&
1551 grep "no config key given for --config-env" error &&
1552 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1553 grep "invalid config format: config" error
1556 test_expect_success 'git --config-env fails with invalid parameters' '
1557 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1558 test_i18ngrep "invalid config format: foo.flag" error &&
1559 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1560 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1561 sane_unset NONEXISTENT &&
1562 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1563 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1566 test_expect_success 'git -c and --config-env work together' '
1567 cat >expect <<-\EOF &&
1568 bar.cmd cmd-value
1569 bar.env env-value
1571 ENVVAR=env-value git \
1572 -c bar.cmd=cmd-value \
1573 --config-env=bar.env=ENVVAR \
1574 config --get-regexp "^bar.*" >actual &&
1575 test_cmp expect actual
1578 test_expect_success 'git -c and --config-env override each other' '
1579 cat >expect <<-\EOF &&
1584 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1585 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1586 } >actual &&
1587 test_cmp expect actual
1590 test_expect_success '--config-env handles keys with equals' '
1591 echo value=with=equals >expect &&
1592 ENVVAR=value=with=equals git \
1593 --config-env=section.subsection=with=equals.key=ENVVAR \
1594 config section.subsection=with=equals.key >actual &&
1595 test_cmp expect actual
1598 test_expect_success 'git config handles environment config pairs' '
1599 GIT_CONFIG_COUNT=2 \
1600 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1601 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1602 git config --get-regexp "pair.*" >actual &&
1603 cat >expect <<-EOF &&
1604 pair.one foo
1605 pair.two bar
1607 test_cmp expect actual
1610 test_expect_success 'git config ignores pairs without count' '
1611 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1612 git config pair.one 2>error &&
1613 test_must_be_empty error
1616 test_expect_success 'git config ignores pairs exceeding count' '
1617 GIT_CONFIG_COUNT=1 \
1618 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1619 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1620 git config --get-regexp "pair.*" >actual 2>error &&
1621 cat >expect <<-EOF &&
1622 pair.one value
1624 test_cmp expect actual &&
1625 test_must_be_empty error
1628 test_expect_success 'git config ignores pairs with zero count' '
1629 test_must_fail env \
1630 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1631 git config pair.one 2>error &&
1632 test_must_be_empty error
1635 test_expect_success 'git config ignores pairs with empty count' '
1636 test_must_fail env \
1637 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1638 git config pair.one 2>error &&
1639 test_must_be_empty error
1642 test_expect_success 'git config fails with invalid count' '
1643 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1644 test_i18ngrep "bogus count" error &&
1645 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1646 test_i18ngrep "too many entries" error
1649 test_expect_success 'git config fails with missing config key' '
1650 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1651 git config --list 2>error &&
1652 test_i18ngrep "missing config key" error
1655 test_expect_success 'git config fails with missing config value' '
1656 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1657 git config --list 2>error &&
1658 test_i18ngrep "missing config value" error
1661 test_expect_success 'git config fails with invalid config pair key' '
1662 test_must_fail env GIT_CONFIG_COUNT=1 \
1663 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1664 git config --list &&
1665 test_must_fail env GIT_CONFIG_COUNT=1 \
1666 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1667 git config --list
1670 test_expect_success 'environment overrides config file' '
1671 test_when_finished "rm -f .git/config" &&
1672 cat >.git/config <<-EOF &&
1673 [pair]
1674 one = value
1676 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1677 git config pair.one >actual &&
1678 cat >expect <<-EOF &&
1679 override
1681 test_cmp expect actual
1684 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1685 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1686 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1687 git config pair.one >actual &&
1688 cat >expect <<-EOF &&
1689 override
1691 test_cmp expect actual
1694 test_expect_success 'command line overrides environment config' '
1695 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1696 git -c pair.one=override config pair.one >actual &&
1697 cat >expect <<-EOF &&
1698 override
1700 test_cmp expect actual
1703 test_expect_success 'git config --edit works' '
1704 git config -f tmp test.value no &&
1705 echo test.value=yes >expect &&
1706 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1707 git config -f tmp --list >actual &&
1708 test_cmp expect actual
1711 test_expect_success 'git config --edit respects core.editor' '
1712 git config -f tmp test.value no &&
1713 echo test.value=yes >expect &&
1714 test_config core.editor "echo [test]value=yes >" &&
1715 git config -f tmp --edit &&
1716 git config -f tmp --list >actual &&
1717 test_cmp expect actual
1720 # malformed configuration files
1721 test_expect_success 'barf on syntax error' '
1722 cat >.git/config <<-\EOF &&
1723 # broken key=value
1724 [section]
1725 key garbage
1727 test_must_fail git config --get section.key 2>error &&
1728 test_i18ngrep " line 3 " error
1731 test_expect_success 'barf on incomplete section header' '
1732 cat >.git/config <<-\EOF &&
1733 # broken section line
1734 [section
1735 key = value
1737 test_must_fail git config --get section.key 2>error &&
1738 test_i18ngrep " line 2 " error
1741 test_expect_success 'barf on incomplete string' '
1742 cat >.git/config <<-\EOF &&
1743 # broken value string
1744 [section]
1745 key = "value string
1747 test_must_fail git config --get section.key 2>error &&
1748 test_i18ngrep " line 3 " error
1751 test_expect_success 'urlmatch' '
1752 cat >.git/config <<-\EOF &&
1753 [http]
1754 sslVerify
1755 [http "https://weak.example.com"]
1756 sslVerify = false
1757 cookieFile = /tmp/cookie.txt
1760 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1761 test_must_be_empty actual &&
1763 echo true >expect &&
1764 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1765 test_cmp expect actual &&
1767 echo false >expect &&
1768 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1769 test_cmp expect actual &&
1772 echo http.cookiefile /tmp/cookie.txt &&
1773 echo http.sslverify false
1774 } >expect &&
1775 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1776 test_cmp expect actual
1779 test_expect_success 'urlmatch with --show-scope' '
1780 cat >.git/config <<-\EOF &&
1781 [http "https://weak.example.com"]
1782 sslVerify = false
1783 cookieFile = /tmp/cookie.txt
1786 cat >expect <<-EOF &&
1787 local http.cookiefile /tmp/cookie.txt
1788 local http.sslverify false
1790 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1791 test_cmp expect actual
1794 test_expect_success 'urlmatch favors more specific URLs' '
1795 cat >.git/config <<-\EOF &&
1796 [http "https://example.com/"]
1797 cookieFile = /tmp/root.txt
1798 [http "https://example.com/subdirectory"]
1799 cookieFile = /tmp/subdirectory.txt
1800 [http "https://user@example.com/"]
1801 cookieFile = /tmp/user.txt
1802 [http "https://averylonguser@example.com/"]
1803 cookieFile = /tmp/averylonguser.txt
1804 [http "https://preceding.example.com"]
1805 cookieFile = /tmp/preceding.txt
1806 [http "https://*.example.com"]
1807 cookieFile = /tmp/wildcard.txt
1808 [http "https://*.example.com/wildcardwithsubdomain"]
1809 cookieFile = /tmp/wildcardwithsubdomain.txt
1810 [http "https://*.example.*"]
1811 cookieFile = /tmp/multiwildcard.txt
1812 [http "https://trailing.example.com"]
1813 cookieFile = /tmp/trailing.txt
1814 [http "https://user@*.example.com/"]
1815 cookieFile = /tmp/wildcardwithuser.txt
1816 [http "https://sub.example.com/"]
1817 cookieFile = /tmp/sub.txt
1820 echo http.cookiefile /tmp/root.txt >expect &&
1821 git config --get-urlmatch HTTP https://example.com >actual &&
1822 test_cmp expect actual &&
1824 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1825 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1826 test_cmp expect actual &&
1828 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1829 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1830 test_cmp expect actual &&
1832 echo http.cookiefile /tmp/user.txt >expect &&
1833 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1834 test_cmp expect actual &&
1836 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1837 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1838 test_cmp expect actual &&
1840 echo http.cookiefile /tmp/preceding.txt >expect &&
1841 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1842 test_cmp expect actual &&
1844 echo http.cookiefile /tmp/wildcard.txt >expect &&
1845 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1846 test_cmp expect actual &&
1848 echo http.cookiefile /tmp/sub.txt >expect &&
1849 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1850 test_cmp expect actual &&
1852 echo http.cookiefile /tmp/trailing.txt >expect &&
1853 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1854 test_cmp expect actual &&
1856 echo http.cookiefile /tmp/sub.txt >expect &&
1857 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1858 test_cmp expect actual &&
1860 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1861 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1862 test_cmp expect actual
1865 test_expect_success 'urlmatch with wildcard' '
1866 cat >.git/config <<-\EOF &&
1867 [http]
1868 sslVerify
1869 [http "https://*.example.com"]
1870 sslVerify = false
1871 cookieFile = /tmp/cookie.txt
1874 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1875 test_must_be_empty actual &&
1877 echo true >expect &&
1878 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1879 test_cmp expect actual &&
1881 echo true >expect &&
1882 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1883 test_cmp expect actual &&
1885 echo true >expect &&
1886 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1887 test_cmp expect actual &&
1889 echo false >expect &&
1890 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1891 test_cmp expect actual &&
1894 echo http.cookiefile /tmp/cookie.txt &&
1895 echo http.sslverify false
1896 } >expect &&
1897 git config --get-urlmatch HTTP https://good.example.com >actual &&
1898 test_cmp expect actual &&
1900 echo http.sslverify >expect &&
1901 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1902 test_cmp expect actual
1905 # good section hygiene
1906 test_expect_success '--unset last key removes section (except if commented)' '
1907 cat >.git/config <<-\EOF &&
1908 # some generic comment on the configuration file itself
1909 # a comment specific to this "section" section.
1910 [section]
1911 # some intervening lines
1912 # that should also be dropped
1914 key = value
1915 # please be careful when you update the above variable
1918 cat >expect <<-\EOF &&
1919 # some generic comment on the configuration file itself
1920 # a comment specific to this "section" section.
1921 [section]
1922 # some intervening lines
1923 # that should also be dropped
1925 # please be careful when you update the above variable
1928 git config --unset section.key &&
1929 test_cmp expect .git/config &&
1931 cat >.git/config <<-\EOF &&
1932 [section]
1933 key = value
1934 [next-section]
1937 cat >expect <<-\EOF &&
1938 [next-section]
1941 git config --unset section.key &&
1942 test_cmp expect .git/config &&
1944 q_to_tab >.git/config <<-\EOF &&
1945 [one]
1946 Qkey = "multiline \
1947 QQ# with comment"
1948 [two]
1949 key = true
1951 git config --unset two.key &&
1952 ! grep two .git/config &&
1954 q_to_tab >.git/config <<-\EOF &&
1955 [one]
1956 Qkey = "multiline \
1957 QQ# with comment"
1958 [one]
1959 key = true
1961 git config --unset-all one.key &&
1962 test_line_count = 0 .git/config &&
1964 q_to_tab >.git/config <<-\EOF &&
1965 [one]
1966 Qkey = true
1967 Q# a comment not at the start
1968 [two]
1969 Qkey = true
1971 git config --unset two.key &&
1972 grep two .git/config &&
1974 q_to_tab >.git/config <<-\EOF &&
1975 [one]
1976 Qkey = not [two "subsection"]
1977 [two "subsection"]
1978 [two "subsection"]
1979 Qkey = true
1980 [TWO "subsection"]
1981 [one]
1983 git config --unset two.subsection.key &&
1984 test "not [two subsection]" = "$(git config one.key)" &&
1985 test_line_count = 3 .git/config
1988 test_expect_success '--unset-all removes section if empty & uncommented' '
1989 cat >.git/config <<-\EOF &&
1990 [section]
1991 key = value1
1992 key = value2
1995 git config --unset-all section.key &&
1996 test_line_count = 0 .git/config
1999 test_expect_success 'adding a key into an empty section reuses header' '
2000 cat >.git/config <<-\EOF &&
2001 [section]
2004 q_to_tab >expect <<-\EOF &&
2005 [section]
2006 Qkey = value
2009 git config section.key value &&
2010 test_cmp expect .git/config
2013 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
2014 chmod 0600 .git/config &&
2015 git config imap.pass Hunter2 &&
2016 perl -e \
2017 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
2018 git config --rename-section imap pop &&
2019 perl -e \
2020 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
2023 ! test_have_prereq MINGW ||
2024 HOME="$(pwd)" # convert to Windows path
2026 test_expect_success 'set up --show-origin tests' '
2027 INCLUDE_DIR="$HOME/include" &&
2028 mkdir -p "$INCLUDE_DIR" &&
2029 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
2030 [user]
2031 absolute = include
2033 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
2034 [user]
2035 relative = include
2037 cat >"$HOME"/.gitconfig <<-EOF &&
2038 [user]
2039 global = true
2040 override = global
2041 [include]
2042 path = "$INCLUDE_DIR/absolute.include"
2044 cat >.git/config <<-\EOF
2045 [user]
2046 local = true
2047 override = local
2048 [include]
2049 path = ../include/relative.include
2053 test_expect_success '--show-origin with --list' '
2054 cat >expect <<-EOF &&
2055 file:$HOME/.gitconfig user.global=true
2056 file:$HOME/.gitconfig user.override=global
2057 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2058 file:$INCLUDE_DIR/absolute.include user.absolute=include
2059 file:.git/config user.local=true
2060 file:.git/config user.override=local
2061 file:.git/config include.path=../include/relative.include
2062 file:.git/../include/relative.include user.relative=include
2063 command line: user.environ=true
2064 command line: user.cmdline=true
2066 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
2067 git -c user.cmdline=true config --list --show-origin >output &&
2068 test_cmp expect output
2071 test_expect_success '--show-origin with --list --null' '
2072 cat >expect <<-EOF &&
2073 file:$HOME/.gitconfigQuser.global
2074 trueQfile:$HOME/.gitconfigQuser.override
2075 globalQfile:$HOME/.gitconfigQinclude.path
2076 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
2077 includeQfile:.git/configQuser.local
2078 trueQfile:.git/configQuser.override
2079 localQfile:.git/configQinclude.path
2080 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
2081 includeQcommand line:Quser.cmdline
2082 trueQ
2084 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
2085 nul_to_q <output.raw >output &&
2086 # The here-doc above adds a newline that the --null output would not
2087 # include. Add it here to make the two comparable.
2088 echo >>output &&
2089 test_cmp expect output
2092 test_expect_success '--show-origin with single file' '
2093 cat >expect <<-\EOF &&
2094 file:.git/config user.local=true
2095 file:.git/config user.override=local
2096 file:.git/config include.path=../include/relative.include
2098 git config --local --list --show-origin >output &&
2099 test_cmp expect output
2102 test_expect_success '--show-origin with --get-regexp' '
2103 cat >expect <<-EOF &&
2104 file:$HOME/.gitconfig user.global true
2105 file:.git/config user.local true
2107 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
2108 test_cmp expect output
2111 test_expect_success '--show-origin getting a single key' '
2112 cat >expect <<-\EOF &&
2113 file:.git/config local
2115 git config --show-origin user.override >output &&
2116 test_cmp expect output
2119 test_expect_success 'set up custom config file' '
2120 CUSTOM_CONFIG_FILE="custom.conf" &&
2121 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
2122 [user]
2123 custom = true
2127 test_expect_success !MINGW 'set up custom config file with special name characters' '
2128 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2129 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2132 test_expect_success !MINGW '--show-origin escape special file name characters' '
2133 cat >expect <<-\EOF &&
2134 file:"file\" (dq) and spaces.conf" user.custom=true
2136 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2137 test_cmp expect output
2140 test_expect_success '--show-origin stdin' '
2141 cat >expect <<-\EOF &&
2142 standard input: user.custom=true
2144 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2145 test_cmp expect output
2148 test_expect_success '--show-origin stdin with file include' '
2149 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2150 [user]
2151 stdin = include
2153 cat >expect <<-EOF &&
2154 file:$INCLUDE_DIR/stdin.include include
2156 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2157 git config --show-origin --includes --file - user.stdin >output &&
2159 test_cmp expect output
2162 test_expect_success '--show-origin blob' '
2163 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2164 cat >expect <<-EOF &&
2165 blob:$blob user.custom=true
2167 git config --blob=$blob --show-origin --list >output &&
2168 test_cmp expect output
2171 test_expect_success '--show-origin blob ref' '
2172 cat >expect <<-\EOF &&
2173 blob:main:custom.conf user.custom=true
2175 git add "$CUSTOM_CONFIG_FILE" &&
2176 git commit -m "new config file" &&
2177 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2178 test_cmp expect output
2181 test_expect_success '--show-origin with --default' '
2182 git config --show-origin --default foo some.key >actual &&
2183 echo "command line: foo" >expect &&
2184 test_cmp expect actual
2187 test_expect_success '--show-scope with --list' '
2188 cat >expect <<-EOF &&
2189 global user.global=true
2190 global user.override=global
2191 global include.path=$INCLUDE_DIR/absolute.include
2192 global user.absolute=include
2193 local user.local=true
2194 local user.override=local
2195 local include.path=../include/relative.include
2196 local user.relative=include
2197 local core.repositoryformatversion=1
2198 local extensions.worktreeconfig=true
2199 worktree user.worktree=true
2200 command user.cmdline=true
2202 git worktree add wt1 &&
2203 # We need these to test for worktree scope, but outside of this
2204 # test, this is just noise
2205 test_config core.repositoryformatversion 1 &&
2206 test_config extensions.worktreeConfig true &&
2207 git config --worktree user.worktree true &&
2208 git -c user.cmdline=true config --list --show-scope >output &&
2209 test_cmp expect output
2212 test_expect_success !MINGW '--show-scope with --blob' '
2213 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2214 cat >expect <<-EOF &&
2215 command user.custom=true
2217 git config --blob=$blob --show-scope --list >output &&
2218 test_cmp expect output
2221 test_expect_success '--show-scope with --local' '
2222 cat >expect <<-\EOF &&
2223 local user.local=true
2224 local user.override=local
2225 local include.path=../include/relative.include
2227 git config --local --list --show-scope >output &&
2228 test_cmp expect output
2231 test_expect_success '--show-scope getting a single value' '
2232 cat >expect <<-\EOF &&
2233 local true
2235 git config --show-scope --get user.local >output &&
2236 test_cmp expect output
2239 test_expect_success '--show-scope with --show-origin' '
2240 cat >expect <<-EOF &&
2241 global file:$HOME/.gitconfig user.global=true
2242 global file:$HOME/.gitconfig user.override=global
2243 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2244 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2245 local file:.git/config user.local=true
2246 local file:.git/config user.override=local
2247 local file:.git/config include.path=../include/relative.include
2248 local file:.git/../include/relative.include user.relative=include
2249 command command line: user.cmdline=true
2251 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2252 test_cmp expect output
2255 test_expect_success '--show-scope with --default' '
2256 git config --show-scope --default foo some.key >actual &&
2257 echo "command foo" >expect &&
2258 test_cmp expect actual
2261 test_expect_success 'override global and system config' '
2262 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2263 cat >"$HOME"/.gitconfig <<-EOF &&
2264 [home]
2265 config = true
2268 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2269 mkdir -p "$HOME"/.config/git &&
2270 cat >"$HOME"/.config/git/config <<-EOF &&
2271 [xdg]
2272 config = true
2274 cat >.git/config <<-EOF &&
2275 [local]
2276 config = true
2278 cat >custom-global-config <<-EOF &&
2279 [global]
2280 config = true
2282 cat >custom-system-config <<-EOF &&
2283 [system]
2284 config = true
2287 cat >expect <<-EOF &&
2288 global xdg.config=true
2289 global home.config=true
2290 local local.config=true
2292 git config --show-scope --list >output &&
2293 test_cmp expect output &&
2295 cat >expect <<-EOF &&
2296 system system.config=true
2297 global global.config=true
2298 local local.config=true
2300 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2301 git config --show-scope --list >output &&
2302 test_cmp expect output &&
2304 cat >expect <<-EOF &&
2305 local local.config=true
2307 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2308 git config --show-scope --list >output &&
2309 test_cmp expect output
2312 test_expect_success 'override global and system config with missing file' '
2313 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2314 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2315 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2318 test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2319 # `git config --system` has different semantics compared to other
2320 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2321 # variable has an effect via a different proxy.
2322 cat >alias-config <<-EOF &&
2323 [alias]
2324 hello-world = !echo "hello world"
2326 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2327 git hello-world &&
2328 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2329 git hello-world >actual &&
2330 echo "hello world" >expect &&
2331 test_cmp expect actual
2334 test_expect_success 'write to overridden global and system config' '
2335 cat >expect <<EOF &&
2336 [config]
2337 key = value
2340 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2341 test_cmp expect write-to-global &&
2343 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2344 test_cmp expect write-to-system
2347 for opt in --local --worktree
2349 test_expect_success "$opt requires a repo" '
2350 # we expect 128 to ensure that we do not simply
2351 # fail to find anything and return code "1"
2352 test_expect_code 128 nongit git config $opt foo.bar
2354 done
2356 cat >.git/config <<-\EOF &&
2357 [section]
2358 foo = true
2359 number = 10
2360 big = 1M
2363 test_expect_success 'identical modern --type specifiers are allowed' '
2364 test_cmp_config 1048576 --type=int --type=int section.big
2367 test_expect_success 'identical legacy --type specifiers are allowed' '
2368 test_cmp_config 1048576 --int --int section.big
2371 test_expect_success 'identical mixed --type specifiers are allowed' '
2372 test_cmp_config 1048576 --int --type=int section.big
2375 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2376 test_must_fail git config --type=int --type=bool section.big 2>error &&
2377 test_i18ngrep "only one type at a time" error
2380 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2381 test_must_fail git config --int --bool section.big 2>error &&
2382 test_i18ngrep "only one type at a time" error
2385 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2386 test_must_fail git config --type=int --bool section.big 2>error &&
2387 test_i18ngrep "only one type at a time" error
2390 test_expect_success '--type allows valid type specifiers' '
2391 test_cmp_config true --type=bool section.foo
2394 test_expect_success '--no-type unsets type specifiers' '
2395 test_cmp_config 10 --type=bool --no-type section.number
2398 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2399 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2402 test_expect_success '--type rejects unknown specifiers' '
2403 test_must_fail git config --type=nonsense section.foo 2>error &&
2404 test_i18ngrep "unrecognized --type argument" error
2407 test_expect_success '--type=int requires at least one digit' '
2408 test_must_fail git config --type int --default m some.key >out 2>error &&
2409 grep "bad numeric config value" error &&
2410 test_must_be_empty out
2413 test_expect_success '--replace-all does not invent newlines' '
2414 q_to_tab >.git/config <<-\EOF &&
2415 [abc]key
2416 QkeepSection
2417 [xyz]
2418 Qkey = 1
2419 [abc]
2420 Qkey = a
2422 q_to_tab >expect <<-\EOF &&
2423 [abc]
2424 QkeepSection
2425 [xyz]
2426 Qkey = 1
2427 [abc]
2428 Qkey = b
2430 git config --replace-all abc.key b &&
2431 test_cmp expect .git/config
2434 test_expect_success 'set all config with value-pattern' '
2435 test_when_finished rm -f config initial &&
2436 git config --file=initial abc.key one &&
2438 # no match => add new entry
2439 cp initial config &&
2440 git config --file=config abc.key two a+ &&
2441 git config --file=config --list >actual &&
2442 cat >expect <<-\EOF &&
2443 abc.key=one
2444 abc.key=two
2446 test_cmp expect actual &&
2448 # multiple matches => failure
2449 test_must_fail git config --file=config abc.key three o+ 2>err &&
2450 test_i18ngrep "has multiple values" err &&
2452 # multiple values, no match => add
2453 git config --file=config abc.key three a+ &&
2454 git config --file=config --list >actual &&
2455 cat >expect <<-\EOF &&
2456 abc.key=one
2457 abc.key=two
2458 abc.key=three
2460 test_cmp expect actual &&
2462 # single match => replace
2463 git config --file=config abc.key four h+ &&
2464 git config --file=config --list >actual &&
2465 cat >expect <<-\EOF &&
2466 abc.key=one
2467 abc.key=two
2468 abc.key=four
2470 test_cmp expect actual
2473 test_expect_success '--replace-all and value-pattern' '
2474 test_when_finished rm -f config &&
2475 git config --file=config --add abc.key one &&
2476 git config --file=config --add abc.key two &&
2477 git config --file=config --add abc.key three &&
2478 git config --file=config --replace-all abc.key four "o+" &&
2479 git config --file=config --list >actual &&
2480 cat >expect <<-\EOF &&
2481 abc.key=four
2482 abc.key=three
2484 test_cmp expect actual
2487 test_expect_success 'refuse --fixed-value for incompatible actions' '
2488 test_when_finished rm -f config &&
2489 git config --file=config dev.null bogus &&
2491 # These modes do not allow --fixed-value at all
2492 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2493 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2494 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2495 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2496 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2497 test_must_fail git config --file=config --fixed-value --list &&
2498 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2499 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2501 # These modes complain when --fixed-value has no value-pattern
2502 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2503 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2504 test_must_fail git config --file=config --fixed-value --get dev.null &&
2505 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2506 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2507 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2508 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2511 test_expect_success '--fixed-value uses exact string matching' '
2512 test_when_finished rm -f config initial &&
2513 META="a+b*c?d[e]f.g" &&
2514 git config --file=initial fixed.test "$META" &&
2516 cp initial config &&
2517 git config --file=config fixed.test bogus "$META" &&
2518 git config --file=config --list >actual &&
2519 cat >expect <<-EOF &&
2520 fixed.test=$META
2521 fixed.test=bogus
2523 test_cmp expect actual &&
2525 cp initial config &&
2526 git config --file=config --fixed-value fixed.test bogus "$META" &&
2527 git config --file=config --list >actual &&
2528 cat >expect <<-\EOF &&
2529 fixed.test=bogus
2531 test_cmp expect actual &&
2533 cp initial config &&
2534 test_must_fail git config --file=config --unset fixed.test "$META" &&
2535 git config --file=config --fixed-value --unset fixed.test "$META" &&
2536 test_must_fail git config --file=config fixed.test &&
2538 cp initial config &&
2539 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2540 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2541 test_must_fail git config --file=config fixed.test &&
2543 cp initial config &&
2544 git config --file=config --replace-all fixed.test bogus "$META" &&
2545 git config --file=config --list >actual &&
2546 cat >expect <<-EOF &&
2547 fixed.test=$META
2548 fixed.test=bogus
2550 test_cmp expect actual &&
2552 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2553 git config --file=config --list >actual &&
2554 cat >expect <<-EOF &&
2555 fixed.test=bogus
2556 fixed.test=bogus
2558 test_cmp expect actual
2561 test_expect_success '--get and --get-all with --fixed-value' '
2562 test_when_finished rm -f config &&
2563 META="a+b*c?d[e]f.g" &&
2564 git config --file=config fixed.test bogus &&
2565 git config --file=config --add fixed.test "$META" &&
2567 git config --file=config --get fixed.test bogus &&
2568 test_must_fail git config --file=config --get fixed.test "$META" &&
2569 git config --file=config --get --fixed-value fixed.test "$META" &&
2570 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2572 git config --file=config --get-all fixed.test bogus &&
2573 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2574 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2575 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2577 git config --file=config --get-regexp fixed+ bogus &&
2578 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2579 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2580 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2583 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2584 git init hasremoteurlTest &&
2585 test_when_finished "rm -rf hasremoteurlTest" &&
2587 cat >include-this <<-\EOF &&
2588 [user]
2589 this = this-is-included
2591 cat >dont-include-that <<-\EOF &&
2592 [user]
2593 that = that-is-not-included
2595 cat >>hasremoteurlTest/.git/config <<-EOF &&
2596 [includeIf "hasconfig:remote.*.url:foourl"]
2597 path = "$(pwd)/include-this"
2598 [includeIf "hasconfig:remote.*.url:barurl"]
2599 path = "$(pwd)/dont-include-that"
2600 [remote "foo"]
2601 url = foourl
2604 echo this-is-included >expect-this &&
2605 git -C hasremoteurlTest config --get user.this >actual-this &&
2606 test_cmp expect-this actual-this &&
2608 test_must_fail git -C hasremoteurlTest config --get user.that
2611 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2612 git init hasremoteurlTest &&
2613 test_when_finished "rm -rf hasremoteurlTest" &&
2615 cat >include-two-three <<-\EOF &&
2616 [user]
2617 two = included-config
2618 three = included-config
2620 cat >>hasremoteurlTest/.git/config <<-EOF &&
2621 [remote "foo"]
2622 url = foourl
2623 [user]
2624 one = main-config
2625 two = main-config
2626 [includeIf "hasconfig:remote.*.url:foourl"]
2627 path = "$(pwd)/include-two-three"
2628 [user]
2629 three = main-config
2632 echo main-config >expect-main-config &&
2633 echo included-config >expect-included-config &&
2635 git -C hasremoteurlTest config --get user.one >actual &&
2636 test_cmp expect-main-config actual &&
2638 git -C hasremoteurlTest config --get user.two >actual &&
2639 test_cmp expect-included-config actual &&
2641 git -C hasremoteurlTest config --get user.three >actual &&
2642 test_cmp expect-main-config actual
2645 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2646 git init hasremoteurlTest &&
2647 test_when_finished "rm -rf hasremoteurlTest" &&
2649 printf "[user]\ndss = yes\n" >double-star-start &&
2650 printf "[user]\ndse = yes\n" >double-star-end &&
2651 printf "[user]\ndsm = yes\n" >double-star-middle &&
2652 printf "[user]\nssm = yes\n" >single-star-middle &&
2653 printf "[user]\nno = no\n" >no &&
2655 cat >>hasremoteurlTest/.git/config <<-EOF &&
2656 [remote "foo"]
2657 url = https://foo/bar/baz
2658 [includeIf "hasconfig:remote.*.url:**/baz"]
2659 path = "$(pwd)/double-star-start"
2660 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2661 path = "$(pwd)/no"
2662 [includeIf "hasconfig:remote.*.url:https:/**"]
2663 path = "$(pwd)/double-star-end"
2664 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2665 path = "$(pwd)/no"
2666 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2667 path = "$(pwd)/double-star-middle"
2668 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2669 path = "$(pwd)/no"
2670 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2671 path = "$(pwd)/single-star-middle"
2672 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2673 path = "$(pwd)/no"
2676 git -C hasremoteurlTest config --get user.dss &&
2677 git -C hasremoteurlTest config --get user.dse &&
2678 git -C hasremoteurlTest config --get user.dsm &&
2679 git -C hasremoteurlTest config --get user.ssm &&
2680 test_must_fail git -C hasremoteurlTest config --get user.no
2683 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2684 git init hasremoteurlTest &&
2685 test_when_finished "rm -rf hasremoteurlTest" &&
2687 cat >include-with-url <<-\EOF &&
2688 [remote "bar"]
2689 url = barurl
2691 cat >>hasremoteurlTest/.git/config <<-EOF &&
2692 [includeIf "hasconfig:remote.*.url:foourl"]
2693 path = "$(pwd)/include-with-url"
2696 # test with any Git command
2697 test_must_fail git -C hasremoteurlTest status 2>err &&
2698 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err
2701 test_done