Merge branch 'hv/trailer-formatting'
[alt-git.git] / t / t1300-config.sh
blobe0dd5d65cedadbab2a5d4aa9c0697b346374612b
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-lib.sh
13 test_expect_success 'clear default config' '
14 rm -f .git/config
17 cat > expect << EOF
18 [section]
19 penguin = little blue
20 EOF
21 test_expect_success 'initial' '
22 git config section.penguin "little blue" &&
23 test_cmp expect .git/config
26 cat > expect << EOF
27 [section]
28 penguin = little blue
29 Movie = BadPhysics
30 EOF
31 test_expect_success 'mixed case' '
32 git config Section.Movie BadPhysics &&
33 test_cmp expect .git/config
36 cat > expect << EOF
37 [section]
38 penguin = little blue
39 Movie = BadPhysics
40 [Sections]
41 WhatEver = Second
42 EOF
43 test_expect_success 'similar section' '
44 git config Sections.WhatEver Second &&
45 test_cmp expect .git/config
48 cat > expect << EOF
49 [section]
50 penguin = little blue
51 Movie = BadPhysics
52 UPPERCASE = true
53 [Sections]
54 WhatEver = Second
55 EOF
56 test_expect_success 'uppercase section' '
57 git config SECTION.UPPERCASE true &&
58 test_cmp expect .git/config
61 test_expect_success 'replace with non-match' '
62 git config section.penguin kingpin !blue
65 test_expect_success 'replace with non-match (actually matching)' '
66 git config section.penguin "very blue" !kingpin
69 cat > expect << EOF
70 [section]
71 penguin = very blue
72 Movie = BadPhysics
73 UPPERCASE = true
74 penguin = kingpin
75 [Sections]
76 WhatEver = Second
77 EOF
79 test_expect_success 'non-match result' 'test_cmp expect .git/config'
81 test_expect_success 'find mixed-case key by canonical name' '
82 test_cmp_config Second sections.whatever
85 test_expect_success 'find mixed-case key by non-canonical name' '
86 test_cmp_config Second SeCtIoNs.WhAtEvEr
89 test_expect_success 'subsections are not canonicalized by git-config' '
90 cat >>.git/config <<-\EOF &&
91 [section.SubSection]
92 key = one
93 [section "SubSection"]
94 key = two
95 EOF
96 test_cmp_config one section.subsection.key &&
97 test_cmp_config two section.SubSection.key
100 cat > .git/config <<\EOF
101 [alpha]
102 bar = foo
103 [beta]
104 baz = multiple \
105 lines
106 foo = bar
109 test_expect_success 'unset with cont. lines' '
110 git config --unset beta.baz
113 cat > expect <<\EOF
114 [alpha]
115 bar = foo
116 [beta]
117 foo = bar
120 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
122 cat > .git/config << EOF
123 [beta] ; silly comment # another comment
124 noIndent= sillyValue ; 'nother silly comment
126 # empty line
127 ; comment
128 haha ="beta" # last silly comment
129 haha = hello
130 haha = bello
131 [nextSection] noNewline = ouch
134 cp .git/config .git/config2
136 test_expect_success 'multiple unset' '
137 git config --unset-all beta.haha
140 cat > expect << EOF
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
144 # empty line
145 ; comment
146 [nextSection] noNewline = ouch
149 test_expect_success 'multiple unset is correct' '
150 test_cmp expect .git/config
153 cp .git/config2 .git/config
155 test_expect_success '--replace-all missing value' '
156 test_must_fail git config --replace-all beta.haha &&
157 test_cmp .git/config2 .git/config
160 rm .git/config2
162 test_expect_success '--replace-all' '
163 git config --replace-all beta.haha gamma
166 cat > expect << EOF
167 [beta] ; silly comment # another comment
168 noIndent= sillyValue ; 'nother silly comment
170 # empty line
171 ; comment
172 haha = gamma
173 [nextSection] noNewline = ouch
176 test_expect_success 'all replaced' '
177 test_cmp expect .git/config
180 cat > expect << EOF
181 [beta] ; silly comment # another comment
182 noIndent= sillyValue ; 'nother silly comment
184 # empty line
185 ; comment
186 haha = alpha
187 [nextSection] noNewline = ouch
189 test_expect_success 'really mean test' '
190 git config beta.haha alpha &&
191 test_cmp expect .git/config
194 cat > expect << EOF
195 [beta] ; silly comment # another comment
196 noIndent= sillyValue ; 'nother silly comment
198 # empty line
199 ; comment
200 haha = alpha
201 [nextSection]
202 nonewline = wow
204 test_expect_success 'really really mean test' '
205 git config nextsection.nonewline wow &&
206 test_cmp expect .git/config
209 test_expect_success 'get value' '
210 test_cmp_config alpha beta.haha
213 cat > expect << EOF
214 [beta] ; silly comment # another comment
215 noIndent= sillyValue ; 'nother silly comment
217 # empty line
218 ; comment
219 [nextSection]
220 nonewline = wow
222 test_expect_success 'unset' '
223 git config --unset beta.haha &&
224 test_cmp expect .git/config
227 cat > expect << EOF
228 [beta] ; silly comment # another comment
229 noIndent= sillyValue ; 'nother silly comment
231 # empty line
232 ; comment
233 [nextSection]
234 nonewline = wow
235 NoNewLine = wow2 for me
237 test_expect_success 'multivar' '
238 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
239 test_cmp expect .git/config
242 test_expect_success 'non-match' '
243 git config --get nextsection.nonewline !for
246 test_expect_success 'non-match value' '
247 test_cmp_config wow --get nextsection.nonewline !for
250 test_expect_success 'multi-valued get returns final one' '
251 test_cmp_config "wow2 for me" --get nextsection.nonewline
254 test_expect_success 'multi-valued get-all returns all' '
255 cat >expect <<-\EOF &&
257 wow2 for me
259 git config --get-all nextsection.nonewline >actual &&
260 test_cmp expect actual
263 cat > expect << EOF
264 [beta] ; silly comment # another comment
265 noIndent= sillyValue ; 'nother silly comment
267 # empty line
268 ; comment
269 [nextSection]
270 nonewline = wow3
271 NoNewLine = wow2 for me
273 test_expect_success 'multivar replace' '
274 git config nextsection.nonewline "wow3" "wow$" &&
275 test_cmp expect .git/config
278 test_expect_success 'ambiguous unset' '
279 test_must_fail git config --unset nextsection.nonewline
282 test_expect_success 'invalid unset' '
283 test_must_fail git config --unset somesection.nonewline
286 cat > expect << EOF
287 [beta] ; silly comment # another comment
288 noIndent= sillyValue ; 'nother silly comment
290 # empty line
291 ; comment
292 [nextSection]
293 NoNewLine = wow2 for me
296 test_expect_success 'multivar unset' '
297 git config --unset nextsection.nonewline "wow3$" &&
298 test_cmp expect .git/config
301 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
303 test_expect_success 'correct key' 'git config 123456.a123 987'
305 test_expect_success 'hierarchical section' '
306 git config Version.1.2.3eX.Alpha beta
309 cat > expect << EOF
310 [beta] ; silly comment # another comment
311 noIndent= sillyValue ; 'nother silly comment
313 # empty line
314 ; comment
315 [nextSection]
316 NoNewLine = wow2 for me
317 [123456]
318 a123 = 987
319 [Version "1.2.3eX"]
320 Alpha = beta
323 test_expect_success 'hierarchical section value' '
324 test_cmp expect .git/config
327 cat > expect << EOF
328 beta.noindent=sillyValue
329 nextsection.nonewline=wow2 for me
330 123456.a123=987
331 version.1.2.3eX.alpha=beta
334 test_expect_success 'working --list' '
335 git config --list > output &&
336 test_cmp expect output
338 test_expect_success '--list without repo produces empty output' '
339 git --git-dir=nonexistent config --list >output &&
340 test_must_be_empty output
343 cat > expect << EOF
344 beta.noindent
345 nextsection.nonewline
346 123456.a123
347 version.1.2.3eX.alpha
350 test_expect_success '--name-only --list' '
351 git config --name-only --list >output &&
352 test_cmp expect output
355 cat > expect << EOF
356 beta.noindent sillyValue
357 nextsection.nonewline wow2 for me
360 test_expect_success '--get-regexp' '
361 git config --get-regexp in >output &&
362 test_cmp expect output
365 cat > expect << EOF
366 beta.noindent
367 nextsection.nonewline
370 test_expect_success '--name-only --get-regexp' '
371 git config --name-only --get-regexp in >output &&
372 test_cmp expect output
375 cat > expect << EOF
376 wow2 for me
377 wow4 for you
380 test_expect_success '--add' '
381 git config --add nextsection.nonewline "wow4 for you" &&
382 git config --get-all nextsection.nonewline > output &&
383 test_cmp expect output
386 cat > .git/config << EOF
387 [novalue]
388 variable
389 [emptyvalue]
390 variable =
393 test_expect_success 'get variable with no value' '
394 git config --get novalue.variable ^$
397 test_expect_success 'get variable with empty value' '
398 git config --get emptyvalue.variable ^$
401 echo novalue.variable > expect
403 test_expect_success 'get-regexp variable with no value' '
404 git config --get-regexp novalue > output &&
405 test_cmp expect output
408 echo 'novalue.variable true' > expect
410 test_expect_success 'get-regexp --bool variable with no value' '
411 git config --bool --get-regexp novalue > output &&
412 test_cmp expect output
415 echo 'emptyvalue.variable ' > expect
417 test_expect_success 'get-regexp variable with empty value' '
418 git config --get-regexp emptyvalue > output &&
419 test_cmp expect output
422 echo true > expect
424 test_expect_success 'get bool variable with no value' '
425 git config --bool novalue.variable > output &&
426 test_cmp expect output
429 echo false > expect
431 test_expect_success 'get bool variable with empty value' '
432 git config --bool emptyvalue.variable > output &&
433 test_cmp expect output
436 test_expect_success 'no arguments, but no crash' '
437 test_must_fail git config >output 2>&1 &&
438 test_i18ngrep usage output
441 cat > .git/config << EOF
442 [a.b]
443 c = d
446 cat > expect << EOF
447 [a.b]
448 c = d
450 x = y
453 test_expect_success 'new section is partial match of another' '
454 git config a.x y &&
455 test_cmp expect .git/config
458 cat > expect << EOF
459 [a.b]
460 c = d
462 x = y
463 b = c
465 x = y
468 test_expect_success 'new variable inserts into proper section' '
469 git config b.x y &&
470 git config a.b c &&
471 test_cmp expect .git/config
474 test_expect_success 'alternative --file (non-existing file should fail)' '
475 test_must_fail git config --file non-existing-config -l &&
476 test_must_fail git config --file non-existing-config test.xyzzy
479 cat > other-config << EOF
480 [ein]
481 bahn = strasse
484 cat > expect << EOF
485 ein.bahn=strasse
488 test_expect_success 'alternative GIT_CONFIG' '
489 GIT_CONFIG=other-config git config --list >output &&
490 test_cmp expect output
493 test_expect_success 'alternative GIT_CONFIG (--file)' '
494 git config --file other-config --list >output &&
495 test_cmp expect output
498 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
499 git config --file - --list <other-config >output &&
500 test_cmp expect output
503 test_expect_success 'setting a value in stdin is an error' '
504 test_must_fail git config --file - some.value foo
507 test_expect_success 'editing stdin is an error' '
508 test_must_fail git config --file - --edit
511 test_expect_success 'refer config from subdirectory' '
512 mkdir x &&
513 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
516 cat > expect << EOF
517 [ein]
518 bahn = strasse
519 [anwohner]
520 park = ausweis
523 test_expect_success '--set in alternative file' '
524 git config --file=other-config anwohner.park ausweis &&
525 test_cmp expect other-config
528 cat > .git/config << EOF
529 # Hallo
530 #Bello
531 [branch "eins"]
532 x = 1
533 [branch.eins]
534 y = 1
535 [branch "1 234 blabl/a"]
536 weird
539 test_expect_success 'rename section' '
540 git config --rename-section branch.eins branch.zwei
543 cat > expect << EOF
544 # Hallo
545 #Bello
546 [branch "zwei"]
547 x = 1
548 [branch "zwei"]
549 y = 1
550 [branch "1 234 blabl/a"]
551 weird
554 test_expect_success 'rename succeeded' '
555 test_cmp expect .git/config
558 test_expect_success 'rename non-existing section' '
559 test_must_fail git config --rename-section \
560 branch."world domination" branch.drei
563 test_expect_success 'rename succeeded' '
564 test_cmp expect .git/config
567 test_expect_success 'rename another section' '
568 git config --rename-section branch."1 234 blabl/a" branch.drei
571 cat > expect << EOF
572 # Hallo
573 #Bello
574 [branch "zwei"]
575 x = 1
576 [branch "zwei"]
577 y = 1
578 [branch "drei"]
579 weird
582 test_expect_success 'rename succeeded' '
583 test_cmp expect .git/config
586 cat >> .git/config << EOF
587 [branch "vier"] z = 1
590 test_expect_success 'rename a section with a var on the same line' '
591 git config --rename-section branch.vier branch.zwei
594 cat > expect << EOF
595 # Hallo
596 #Bello
597 [branch "zwei"]
598 x = 1
599 [branch "zwei"]
600 y = 1
601 [branch "drei"]
602 weird
603 [branch "zwei"]
604 z = 1
607 test_expect_success 'rename succeeded' '
608 test_cmp expect .git/config
611 test_expect_success 'renaming empty section name is rejected' '
612 test_must_fail git config --rename-section branch.zwei ""
615 test_expect_success 'renaming to bogus section is rejected' '
616 test_must_fail git config --rename-section branch.zwei "bogus name"
619 cat >> .git/config << EOF
620 [branch "zwei"] a = 1 [branch "vier"]
623 test_expect_success 'remove section' '
624 git config --remove-section branch.zwei
627 cat > expect << EOF
628 # Hallo
629 #Bello
630 [branch "drei"]
631 weird
634 test_expect_success 'section was removed properly' '
635 test_cmp expect .git/config
638 cat > expect << EOF
639 [gitcvs]
640 enabled = true
641 dbname = %Ggitcvs2.%a.%m.sqlite
642 [gitcvs "ext"]
643 dbname = %Ggitcvs1.%a.%m.sqlite
646 test_expect_success 'section ending' '
647 rm -f .git/config &&
648 git config gitcvs.enabled true &&
649 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
650 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
651 test_cmp expect .git/config
655 test_expect_success numbers '
656 git config kilo.gram 1k &&
657 git config mega.ton 1m &&
658 echo 1024 >expect &&
659 echo 1048576 >>expect &&
660 git config --int --get kilo.gram >actual &&
661 git config --int --get mega.ton >>actual &&
662 test_cmp expect actual
665 test_expect_success '--int is at least 64 bits' '
666 git config giga.watts 121g &&
667 echo >expect &&
668 test_cmp_config 129922760704 --int --get giga.watts
671 test_expect_success 'invalid unit' '
672 git config aninvalid.unit "1auto" &&
673 test_cmp_config 1auto aninvalid.unit &&
674 test_must_fail git config --int --get aninvalid.unit 2>actual &&
675 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
678 test_expect_success 'invalid unit boolean' '
679 git config commit.gpgsign "1true" &&
680 test_cmp_config 1true commit.gpgsign &&
681 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
682 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
685 test_expect_success 'line number is reported correctly' '
686 printf "[bool]\n\tvar\n" >invalid &&
687 test_must_fail git config -f invalid --path bool.var 2>actual &&
688 test_i18ngrep "line 2" actual
691 test_expect_success 'invalid stdin config' '
692 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
693 test_i18ngrep "bad config line 1 in standard input" output
696 cat > expect << EOF
697 true
698 false
699 true
700 false
701 true
702 false
703 true
704 false
707 test_expect_success bool '
709 git config bool.true1 01 &&
710 git config bool.true2 -1 &&
711 git config bool.true3 YeS &&
712 git config bool.true4 true &&
713 git config bool.false1 000 &&
714 git config bool.false2 "" &&
715 git config bool.false3 nO &&
716 git config bool.false4 FALSE &&
717 rm -f result &&
718 for i in 1 2 3 4
720 git config --bool --get bool.true$i >>result
721 git config --bool --get bool.false$i >>result
722 done &&
723 test_cmp expect result'
725 test_expect_success 'invalid bool (--get)' '
727 git config bool.nobool foobar &&
728 test_must_fail git config --bool --get bool.nobool'
730 test_expect_success 'invalid bool (set)' '
732 test_must_fail git config --bool bool.nobool foobar'
734 cat > expect <<\EOF
735 [bool]
736 true1 = true
737 true2 = true
738 true3 = true
739 true4 = true
740 false1 = false
741 false2 = false
742 false3 = false
743 false4 = false
746 test_expect_success 'set --bool' '
748 rm -f .git/config &&
749 git config --bool bool.true1 01 &&
750 git config --bool bool.true2 -1 &&
751 git config --bool bool.true3 YeS &&
752 git config --bool bool.true4 true &&
753 git config --bool bool.false1 000 &&
754 git config --bool bool.false2 "" &&
755 git config --bool bool.false3 nO &&
756 git config --bool bool.false4 FALSE &&
757 test_cmp expect .git/config'
759 cat > expect <<\EOF
760 [int]
761 val1 = 1
762 val2 = -1
763 val3 = 5242880
766 test_expect_success 'set --int' '
768 rm -f .git/config &&
769 git config --int int.val1 01 &&
770 git config --int int.val2 -1 &&
771 git config --int int.val3 5m &&
772 test_cmp expect .git/config
775 test_expect_success 'get --bool-or-int' '
776 cat >.git/config <<-\EOF &&
777 [bool]
778 true1
779 true2 = true
780 false = false
781 [int]
782 int1 = 0
783 int2 = 1
784 int3 = -1
786 cat >expect <<-\EOF &&
787 true
788 true
789 false
795 git config --bool-or-int bool.true1 &&
796 git config --bool-or-int bool.true2 &&
797 git config --bool-or-int bool.false &&
798 git config --bool-or-int int.int1 &&
799 git config --bool-or-int int.int2 &&
800 git config --bool-or-int int.int3
801 } >actual &&
802 test_cmp expect actual
805 cat >expect <<\EOF
806 [bool]
807 true1 = true
808 false1 = false
809 true2 = true
810 false2 = false
811 [int]
812 int1 = 0
813 int2 = 1
814 int3 = -1
817 test_expect_success 'set --bool-or-int' '
818 rm -f .git/config &&
819 git config --bool-or-int bool.true1 true &&
820 git config --bool-or-int bool.false1 false &&
821 git config --bool-or-int bool.true2 yes &&
822 git config --bool-or-int bool.false2 no &&
823 git config --bool-or-int int.int1 0 &&
824 git config --bool-or-int int.int2 1 &&
825 git config --bool-or-int int.int3 -1 &&
826 test_cmp expect .git/config
829 cat >expect <<\EOF
830 [path]
831 home = ~/
832 normal = /dev/null
833 trailingtilde = foo~
836 test_expect_success !MINGW 'set --path' '
837 rm -f .git/config &&
838 git config --path path.home "~/" &&
839 git config --path path.normal "/dev/null" &&
840 git config --path path.trailingtilde "foo~" &&
841 test_cmp expect .git/config'
843 if test_have_prereq !MINGW && test "${HOME+set}"
844 then
845 test_set_prereq HOMEVAR
848 cat >expect <<EOF
849 $HOME/
850 /dev/null
851 foo~
854 test_expect_success HOMEVAR 'get --path' '
855 git config --get --path path.home > result &&
856 git config --get --path path.normal >> result &&
857 git config --get --path path.trailingtilde >> result &&
858 test_cmp expect result
861 cat >expect <<\EOF
862 /dev/null
863 foo~
866 test_expect_success !MINGW 'get --path copes with unset $HOME' '
868 sane_unset HOME &&
869 test_must_fail git config --get --path path.home \
870 >result 2>msg &&
871 git config --get --path path.normal >>result &&
872 git config --get --path path.trailingtilde >>result
873 ) &&
874 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
875 test_cmp expect result
878 test_expect_success 'get --path barfs on boolean variable' '
879 echo "[path]bool" >.git/config &&
880 test_must_fail git config --get --path path.bool
883 test_expect_success 'get --expiry-date' '
884 rel="3.weeks.5.days.00:00" &&
885 rel_out="$rel ->" &&
886 cat >.git/config <<-\EOF &&
887 [date]
888 valid1 = "3.weeks.5.days 00:00"
889 valid2 = "Fri Jun 4 15:46:55 2010"
890 valid3 = "2017/11/11 11:11:11PM"
891 valid4 = "2017/11/10 09:08:07 PM"
892 valid5 = "never"
893 invalid1 = "abc"
895 cat >expect <<-EOF &&
896 $(test-tool date timestamp $rel)
897 1275666415
898 1510441871
899 1510348087
902 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
904 echo "$rel_out $(git config --expiry-date date.valid1)"
905 git config --expiry-date date.valid2 &&
906 git config --expiry-date date.valid3 &&
907 git config --expiry-date date.valid4 &&
908 git config --expiry-date date.valid5
909 } >actual &&
910 test_cmp expect actual &&
911 test_must_fail git config --expiry-date date.invalid1
914 test_expect_success 'get --type=color' '
915 rm .git/config &&
916 git config foo.color "red" &&
917 git config --get --type=color foo.color >actual.raw &&
918 test_decode_color <actual.raw >actual &&
919 echo "<RED>" >expect &&
920 test_cmp expect actual
923 cat >expect << EOF
924 [foo]
925 color = red
928 test_expect_success 'set --type=color' '
929 rm .git/config &&
930 git config --type=color foo.color "red" &&
931 test_cmp expect .git/config
934 test_expect_success 'get --type=color barfs on non-color' '
935 echo "[foo]bar=not-a-color" >.git/config &&
936 test_must_fail git config --get --type=color foo.bar
939 test_expect_success 'set --type=color barfs on non-color' '
940 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
941 test_i18ngrep "cannot parse color" error
944 cat > expect << EOF
945 [quote]
946 leading = " test"
947 ending = "test "
948 semicolon = "test;test"
949 hash = "test#test"
951 test_expect_success 'quoting' '
952 rm -f .git/config &&
953 git config quote.leading " test" &&
954 git config quote.ending "test " &&
955 git config quote.semicolon "test;test" &&
956 git config quote.hash "test#test" &&
957 test_cmp expect .git/config
960 test_expect_success 'key with newline' '
961 test_must_fail git config "key.with
962 newline" 123'
964 test_expect_success 'value with newline' 'git config key.sub value.with\\\
965 newline'
967 cat > .git/config <<\EOF
968 [section]
969 ; comment \
970 continued = cont\
971 inued
972 noncont = not continued ; \
973 quotecont = "cont;\
974 inued"
977 cat > expect <<\EOF
978 section.continued=continued
979 section.noncont=not continued
980 section.quotecont=cont;inued
983 test_expect_success 'value continued on next line' '
984 git config --list > result &&
985 test_cmp expect result
988 cat > .git/config <<\EOF
989 [section "sub=section"]
990 val1 = foo=bar
991 val2 = foo\nbar
992 val3 = \n\n
993 val4 =
994 val5
997 cat > expect <<\EOF
998 section.sub=section.val1
999 foo=barQsection.sub=section.val2
1001 barQsection.sub=section.val3
1004 Qsection.sub=section.val4
1005 Qsection.sub=section.val5Q
1007 test_expect_success '--null --list' '
1008 git config --null --list >result.raw &&
1009 nul_to_q <result.raw >result &&
1010 echo >>result &&
1011 test_cmp expect result
1014 test_expect_success '--null --get-regexp' '
1015 git config --null --get-regexp "val[0-9]" >result.raw &&
1016 nul_to_q <result.raw >result &&
1017 echo >>result &&
1018 test_cmp expect result
1021 test_expect_success 'inner whitespace kept verbatim' '
1022 git config section.val "foo bar" &&
1023 test_cmp_config "foo bar" section.val
1026 test_expect_success SYMLINKS 'symlinked configuration' '
1027 ln -s notyet myconfig &&
1028 git config --file=myconfig test.frotz nitfol &&
1029 test -h myconfig &&
1030 test -f notyet &&
1031 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1032 git config --file=myconfig test.xyzzy rezrov &&
1033 test -h myconfig &&
1034 test -f notyet &&
1035 cat >expect <<-\EOF &&
1036 nitfol
1037 rezrov
1040 git config --file=notyet test.frotz &&
1041 git config --file=notyet test.xyzzy
1042 } >actual &&
1043 test_cmp expect actual
1046 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1047 ln -s doesnotexist linktonada &&
1048 ln -s linktonada linktolinktonada &&
1049 test_must_fail git config --file=linktonada --list &&
1050 test_must_fail git config --file=linktolinktonada --list
1053 test_expect_success 'check split_cmdline return' "
1054 git config alias.split-cmdline-fix 'echo \"' &&
1055 test_must_fail git split-cmdline-fix &&
1056 echo foo > foo &&
1057 git add foo &&
1058 git commit -m 'initial commit' &&
1059 git config branch.main.mergeoptions 'echo \"' &&
1060 test_must_fail git merge main
1063 test_expect_success 'git -c "key=value" support' '
1064 cat >expect <<-\EOF &&
1065 value
1066 value
1067 true
1070 git -c section.name=value config section.name &&
1071 git -c foo.CamelCase=value config foo.camelcase &&
1072 git -c foo.flag config --bool foo.flag
1073 } >actual &&
1074 test_cmp expect actual &&
1075 test_must_fail git -c name=value config section.name
1078 # We just need a type-specifier here that cares about the
1079 # distinction internally between a NULL boolean and a real
1080 # string (because most of git's internal parsers do care).
1081 # Using "--path" works, but we do not otherwise care about
1082 # its semantics.
1083 test_expect_success 'git -c can represent empty string' '
1084 echo >expect &&
1085 git -c foo.empty= config --path foo.empty >actual &&
1086 test_cmp expect actual
1089 test_expect_success 'key sanity-checking' '
1090 test_must_fail git config foo=bar &&
1091 test_must_fail git config foo=.bar &&
1092 test_must_fail git config foo.ba=r &&
1093 test_must_fail git config foo.1bar &&
1094 test_must_fail git config foo."ba
1095 z".bar &&
1096 test_must_fail git config . false &&
1097 test_must_fail git config .foo false &&
1098 test_must_fail git config foo. false &&
1099 test_must_fail git config .foo. false &&
1100 git config foo.bar true &&
1101 git config foo."ba =z".bar false
1104 test_expect_success 'git -c works with aliases of builtins' '
1105 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1106 echo bar >expect &&
1107 git checkconfig >actual &&
1108 test_cmp expect actual
1111 test_expect_success 'aliases can be CamelCased' '
1112 test_config alias.CamelCased "rev-parse HEAD" &&
1113 git CamelCased >out &&
1114 git rev-parse HEAD >expect &&
1115 test_cmp expect out
1118 test_expect_success 'git -c does not split values on equals' '
1119 echo "value with = in it" >expect &&
1120 git -c section.foo="value with = in it" config section.foo >actual &&
1121 test_cmp expect actual
1124 test_expect_success 'git -c dies on bogus config' '
1125 test_must_fail git -c core.bare=foo rev-parse
1128 test_expect_success 'git -c complains about empty key' '
1129 test_must_fail git -c "=foo" rev-parse
1132 test_expect_success 'git -c complains about empty key and value' '
1133 test_must_fail git -c "" rev-parse
1136 test_expect_success 'multiple git -c appends config' '
1137 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1138 cat >expect <<-\EOF &&
1139 x.one 1
1140 x.two 2
1142 git -c x.one=1 x >actual &&
1143 test_cmp expect actual
1146 test_expect_success 'last one wins: two level vars' '
1148 # sec.var and sec.VAR are the same variable, as the first
1149 # and the last level of a configuration variable name is
1150 # case insensitive.
1152 echo VAL >expect &&
1154 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1155 test_cmp expect actual &&
1156 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1157 test_cmp expect actual &&
1159 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1160 test_cmp expect actual &&
1161 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1162 test_cmp expect actual
1165 test_expect_success 'last one wins: three level vars' '
1167 # v.a.r and v.A.r are not the same variable, as the middle
1168 # level of a three-level configuration variable name is
1169 # case sensitive.
1171 echo val >expect &&
1172 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1173 test_cmp expect actual &&
1174 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1175 test_cmp expect actual &&
1177 # v.a.r and V.a.R are the same variable, as the first
1178 # and the last level of a configuration variable name is
1179 # case insensitive.
1181 echo VAL >expect &&
1182 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1183 test_cmp expect actual &&
1184 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1185 test_cmp expect actual &&
1186 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1187 test_cmp expect actual &&
1188 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1189 test_cmp expect actual
1192 test_expect_success 'old-fashioned settings are case insensitive' '
1193 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1195 cat >testConfig_actual <<-EOF &&
1196 [V.A]
1197 r = value1
1199 q_to_tab >testConfig_expect <<-EOF &&
1200 [V.A]
1201 Qr = value2
1203 git config -f testConfig_actual "v.a.r" value2 &&
1204 test_cmp testConfig_expect testConfig_actual &&
1206 cat >testConfig_actual <<-EOF &&
1207 [V.A]
1208 r = value1
1210 q_to_tab >testConfig_expect <<-EOF &&
1211 [V.A]
1212 QR = value2
1214 git config -f testConfig_actual "V.a.R" value2 &&
1215 test_cmp testConfig_expect testConfig_actual &&
1217 cat >testConfig_actual <<-EOF &&
1218 [V.A]
1219 r = value1
1221 q_to_tab >testConfig_expect <<-EOF &&
1222 [V.A]
1223 r = value1
1224 Qr = value2
1226 git config -f testConfig_actual "V.A.r" value2 &&
1227 test_cmp testConfig_expect testConfig_actual &&
1229 cat >testConfig_actual <<-EOF &&
1230 [V.A]
1231 r = value1
1233 q_to_tab >testConfig_expect <<-EOF &&
1234 [V.A]
1235 r = value1
1236 Qr = value2
1238 git config -f testConfig_actual "v.A.r" value2 &&
1239 test_cmp testConfig_expect testConfig_actual
1242 test_expect_success 'setting different case sensitive subsections ' '
1243 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1245 cat >testConfig_actual <<-EOF &&
1246 [V "A"]
1247 R = v1
1248 [K "E"]
1249 Y = v1
1250 [a "b"]
1251 c = v1
1252 [d "e"]
1253 f = v1
1255 q_to_tab >testConfig_expect <<-EOF &&
1256 [V "A"]
1257 Qr = v2
1258 [K "E"]
1259 Qy = v2
1260 [a "b"]
1261 Qc = v2
1262 [d "e"]
1263 f = v1
1264 [d "E"]
1265 Qf = v2
1267 # exact match
1268 git config -f testConfig_actual a.b.c v2 &&
1269 # match section and subsection, key is cased differently.
1270 git config -f testConfig_actual K.E.y v2 &&
1271 # section and key are matched case insensitive, but subsection needs
1272 # to match; When writing out new values only the key is adjusted
1273 git config -f testConfig_actual v.A.r v2 &&
1274 # subsection is not matched:
1275 git config -f testConfig_actual d.E.f v2 &&
1276 test_cmp testConfig_expect testConfig_actual
1279 for VAR in a .a a. a.0b a."b c". a."b c".0d
1281 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1282 test_must_fail git -c "$VAR=VAL" config -l
1284 done
1286 for VAR in a.b a."b c".d
1288 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1289 echo VAL >expect &&
1290 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1291 test_cmp expect actual
1293 done
1295 test_expect_success 'git -c is not confused by empty environment' '
1296 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1299 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1300 v="${SQ}key.one=foo${SQ}" &&
1301 v="$v ${SQ}key.two=bar${SQ}" &&
1302 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1303 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1304 cat >expect <<-EOF &&
1305 key.one foo
1306 key.two bar
1307 key.ambiguous section.whatever=value
1309 test_cmp expect actual
1312 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1313 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1314 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1315 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1316 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1317 cat >expect <<-EOF &&
1318 key.one foo
1319 key.two bar
1320 key.ambiguous=section.whatever value
1322 test_cmp expect actual
1325 test_expect_success 'old and new-style entries can mix' '
1326 v="${SQ}key.oldone=oldfoo${SQ}" &&
1327 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1328 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1329 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1330 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1331 cat >expect <<-EOF &&
1332 key.oldone oldfoo
1333 key.newone newfoo
1334 key.oldtwo oldbar
1335 key.newtwo newbar
1337 test_cmp expect actual
1340 test_expect_success 'old and new bools with ambiguous subsection' '
1341 v="${SQ}key.with=equals.oldbool${SQ}" &&
1342 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1343 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1344 cat >expect <<-EOF &&
1345 key.with equals.oldbool
1346 key.with=equals.newbool
1348 test_cmp expect actual
1351 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1352 cat >expect <<-\EOF &&
1353 env.one one
1354 env.two two
1356 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1357 git config --get-regexp "env.*" >actual &&
1358 test_cmp expect actual &&
1360 cat >expect <<-EOF &&
1361 env.one one${SQ}
1362 env.two two
1364 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1365 git config --get-regexp "env.*" >actual &&
1366 test_cmp expect actual &&
1368 test_must_fail env \
1369 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1370 git config --get-regexp "env.*"
1373 test_expect_success 'git --config-env=key=envvar support' '
1374 cat >expect <<-\EOF &&
1375 value
1376 value
1377 false
1380 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1381 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1382 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag
1383 } >actual &&
1384 test_cmp expect actual
1387 test_expect_success 'git --config-env fails with invalid parameters' '
1388 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1389 test_i18ngrep "invalid config format: foo.flag" error &&
1390 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1391 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1392 sane_unset NONEXISTENT &&
1393 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1394 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1397 test_expect_success 'git -c and --config-env work together' '
1398 cat >expect <<-\EOF &&
1399 bar.cmd cmd-value
1400 bar.env env-value
1402 ENVVAR=env-value git \
1403 -c bar.cmd=cmd-value \
1404 --config-env=bar.env=ENVVAR \
1405 config --get-regexp "^bar.*" >actual &&
1406 test_cmp expect actual
1409 test_expect_success 'git -c and --config-env override each other' '
1410 cat >expect <<-\EOF &&
1415 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1416 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1417 } >actual &&
1418 test_cmp expect actual
1421 test_expect_success '--config-env handles keys with equals' '
1422 echo value=with=equals >expect &&
1423 ENVVAR=value=with=equals git \
1424 --config-env=section.subsection=with=equals.key=ENVVAR \
1425 config section.subsection=with=equals.key >actual &&
1426 test_cmp expect actual
1429 test_expect_success 'git config handles environment config pairs' '
1430 GIT_CONFIG_COUNT=2 \
1431 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1432 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1433 git config --get-regexp "pair.*" >actual &&
1434 cat >expect <<-EOF &&
1435 pair.one foo
1436 pair.two bar
1438 test_cmp expect actual
1441 test_expect_success 'git config ignores pairs without count' '
1442 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1443 git config pair.one 2>error &&
1444 test_must_be_empty error
1447 test_expect_success 'git config ignores pairs with zero count' '
1448 test_must_fail env \
1449 GIT_CONFIG_COUNT=0 \
1450 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1451 git config pair.one
1454 test_expect_success 'git config ignores pairs exceeding count' '
1455 GIT_CONFIG_COUNT=1 \
1456 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1457 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1458 git config --get-regexp "pair.*" >actual &&
1459 cat >expect <<-EOF &&
1460 pair.one value
1462 test_cmp expect actual
1465 test_expect_success 'git config ignores pairs with zero count' '
1466 test_must_fail env \
1467 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1468 git config pair.one >error &&
1469 test_must_be_empty error
1472 test_expect_success 'git config ignores pairs with empty count' '
1473 test_must_fail env \
1474 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1475 git config pair.one >error &&
1476 test_must_be_empty error
1479 test_expect_success 'git config fails with invalid count' '
1480 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1481 test_i18ngrep "bogus count" error &&
1482 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1483 test_i18ngrep "too many entries" error
1486 test_expect_success 'git config fails with missing config key' '
1487 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1488 git config --list 2>error &&
1489 test_i18ngrep "missing config key" error
1492 test_expect_success 'git config fails with missing config value' '
1493 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1494 git config --list 2>error &&
1495 test_i18ngrep "missing config value" error
1498 test_expect_success 'git config fails with invalid config pair key' '
1499 test_must_fail env GIT_CONFIG_COUNT=1 \
1500 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1501 git config --list &&
1502 test_must_fail env GIT_CONFIG_COUNT=1 \
1503 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1504 git config --list
1507 test_expect_success 'environment overrides config file' '
1508 test_when_finished "rm -f .git/config" &&
1509 cat >.git/config <<-EOF &&
1510 [pair]
1511 one = value
1513 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1514 git config pair.one >actual &&
1515 cat >expect <<-EOF &&
1516 override
1518 test_cmp expect actual
1521 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1522 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1523 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1524 git config pair.one >actual &&
1525 cat >expect <<-EOF &&
1526 override
1528 test_cmp expect actual
1531 test_expect_success 'command line overrides environment config' '
1532 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1533 git -c pair.one=override config pair.one >actual &&
1534 cat >expect <<-EOF &&
1535 override
1537 test_cmp expect actual
1540 test_expect_success 'git config --edit works' '
1541 git config -f tmp test.value no &&
1542 echo test.value=yes >expect &&
1543 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1544 git config -f tmp --list >actual &&
1545 test_cmp expect actual
1548 test_expect_success 'git config --edit respects core.editor' '
1549 git config -f tmp test.value no &&
1550 echo test.value=yes >expect &&
1551 test_config core.editor "echo [test]value=yes >" &&
1552 git config -f tmp --edit &&
1553 git config -f tmp --list >actual &&
1554 test_cmp expect actual
1557 # malformed configuration files
1558 test_expect_success 'barf on syntax error' '
1559 cat >.git/config <<-\EOF &&
1560 # broken section line
1561 [section]
1562 key garbage
1564 test_must_fail git config --get section.key >actual 2>error &&
1565 test_i18ngrep " line 3 " error
1568 test_expect_success 'barf on incomplete section header' '
1569 cat >.git/config <<-\EOF &&
1570 # broken section line
1571 [section
1572 key = value
1574 test_must_fail git config --get section.key >actual 2>error &&
1575 test_i18ngrep " line 2 " error
1578 test_expect_success 'barf on incomplete string' '
1579 cat >.git/config <<-\EOF &&
1580 # broken section line
1581 [section]
1582 key = "value string
1584 test_must_fail git config --get section.key >actual 2>error &&
1585 test_i18ngrep " line 3 " error
1588 test_expect_success 'urlmatch' '
1589 cat >.git/config <<-\EOF &&
1590 [http]
1591 sslVerify
1592 [http "https://weak.example.com"]
1593 sslVerify = false
1594 cookieFile = /tmp/cookie.txt
1597 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1598 test_must_be_empty actual &&
1600 echo true >expect &&
1601 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1602 test_cmp expect actual &&
1604 echo false >expect &&
1605 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1606 test_cmp expect actual &&
1609 echo http.cookiefile /tmp/cookie.txt &&
1610 echo http.sslverify false
1611 } >expect &&
1612 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1613 test_cmp expect actual
1616 test_expect_success 'urlmatch favors more specific URLs' '
1617 cat >.git/config <<-\EOF &&
1618 [http "https://example.com/"]
1619 cookieFile = /tmp/root.txt
1620 [http "https://example.com/subdirectory"]
1621 cookieFile = /tmp/subdirectory.txt
1622 [http "https://user@example.com/"]
1623 cookieFile = /tmp/user.txt
1624 [http "https://averylonguser@example.com/"]
1625 cookieFile = /tmp/averylonguser.txt
1626 [http "https://preceding.example.com"]
1627 cookieFile = /tmp/preceding.txt
1628 [http "https://*.example.com"]
1629 cookieFile = /tmp/wildcard.txt
1630 [http "https://*.example.com/wildcardwithsubdomain"]
1631 cookieFile = /tmp/wildcardwithsubdomain.txt
1632 [http "https://*.example.*"]
1633 cookieFile = /tmp/multiwildcard.txt
1634 [http "https://trailing.example.com"]
1635 cookieFile = /tmp/trailing.txt
1636 [http "https://user@*.example.com/"]
1637 cookieFile = /tmp/wildcardwithuser.txt
1638 [http "https://sub.example.com/"]
1639 cookieFile = /tmp/sub.txt
1642 echo http.cookiefile /tmp/root.txt >expect &&
1643 git config --get-urlmatch HTTP https://example.com >actual &&
1644 test_cmp expect actual &&
1646 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1647 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1648 test_cmp expect actual &&
1650 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1651 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1652 test_cmp expect actual &&
1654 echo http.cookiefile /tmp/user.txt >expect &&
1655 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1656 test_cmp expect actual &&
1658 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1659 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1660 test_cmp expect actual &&
1662 echo http.cookiefile /tmp/preceding.txt >expect &&
1663 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1664 test_cmp expect actual &&
1666 echo http.cookiefile /tmp/wildcard.txt >expect &&
1667 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1668 test_cmp expect actual &&
1670 echo http.cookiefile /tmp/sub.txt >expect &&
1671 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1672 test_cmp expect actual &&
1674 echo http.cookiefile /tmp/trailing.txt >expect &&
1675 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1676 test_cmp expect actual &&
1678 echo http.cookiefile /tmp/sub.txt >expect &&
1679 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1680 test_cmp expect actual &&
1682 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1683 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1684 test_cmp expect actual
1687 test_expect_success 'urlmatch with wildcard' '
1688 cat >.git/config <<-\EOF &&
1689 [http]
1690 sslVerify
1691 [http "https://*.example.com"]
1692 sslVerify = false
1693 cookieFile = /tmp/cookie.txt
1696 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1697 test_must_be_empty actual &&
1699 echo true >expect &&
1700 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1701 test_cmp expect actual &&
1703 echo true >expect &&
1704 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1705 test_cmp expect actual &&
1707 echo true >expect &&
1708 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1709 test_cmp expect actual &&
1711 echo false >expect &&
1712 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1713 test_cmp expect actual &&
1716 echo http.cookiefile /tmp/cookie.txt &&
1717 echo http.sslverify false
1718 } >expect &&
1719 git config --get-urlmatch HTTP https://good.example.com >actual &&
1720 test_cmp expect actual &&
1722 echo http.sslverify >expect &&
1723 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1724 test_cmp expect actual
1727 # good section hygiene
1728 test_expect_success '--unset last key removes section (except if commented)' '
1729 cat >.git/config <<-\EOF &&
1730 # some generic comment on the configuration file itself
1731 # a comment specific to this "section" section.
1732 [section]
1733 # some intervening lines
1734 # that should also be dropped
1736 key = value
1737 # please be careful when you update the above variable
1740 cat >expect <<-\EOF &&
1741 # some generic comment on the configuration file itself
1742 # a comment specific to this "section" section.
1743 [section]
1744 # some intervening lines
1745 # that should also be dropped
1747 # please be careful when you update the above variable
1750 git config --unset section.key &&
1751 test_cmp expect .git/config &&
1753 cat >.git/config <<-\EOF &&
1754 [section]
1755 key = value
1756 [next-section]
1759 cat >expect <<-\EOF &&
1760 [next-section]
1763 git config --unset section.key &&
1764 test_cmp expect .git/config &&
1766 q_to_tab >.git/config <<-\EOF &&
1767 [one]
1768 Qkey = "multiline \
1769 QQ# with comment"
1770 [two]
1771 key = true
1773 git config --unset two.key &&
1774 ! grep two .git/config &&
1776 q_to_tab >.git/config <<-\EOF &&
1777 [one]
1778 Qkey = "multiline \
1779 QQ# with comment"
1780 [one]
1781 key = true
1783 git config --unset-all one.key &&
1784 test_line_count = 0 .git/config &&
1786 q_to_tab >.git/config <<-\EOF &&
1787 [one]
1788 Qkey = true
1789 Q# a comment not at the start
1790 [two]
1791 Qkey = true
1793 git config --unset two.key &&
1794 grep two .git/config &&
1796 q_to_tab >.git/config <<-\EOF &&
1797 [one]
1798 Qkey = not [two "subsection"]
1799 [two "subsection"]
1800 [two "subsection"]
1801 Qkey = true
1802 [TWO "subsection"]
1803 [one]
1805 git config --unset two.subsection.key &&
1806 test "not [two subsection]" = "$(git config one.key)" &&
1807 test_line_count = 3 .git/config
1810 test_expect_success '--unset-all removes section if empty & uncommented' '
1811 cat >.git/config <<-\EOF &&
1812 [section]
1813 key = value1
1814 key = value2
1817 git config --unset-all section.key &&
1818 test_line_count = 0 .git/config
1821 test_expect_success 'adding a key into an empty section reuses header' '
1822 cat >.git/config <<-\EOF &&
1823 [section]
1826 q_to_tab >expect <<-\EOF &&
1827 [section]
1828 Qkey = value
1831 git config section.key value &&
1832 test_cmp expect .git/config
1835 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1836 chmod 0600 .git/config &&
1837 git config imap.pass Hunter2 &&
1838 perl -e \
1839 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1840 git config --rename-section imap pop &&
1841 perl -e \
1842 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1845 ! test_have_prereq MINGW ||
1846 HOME="$(pwd)" # convert to Windows path
1848 test_expect_success 'set up --show-origin tests' '
1849 INCLUDE_DIR="$HOME/include" &&
1850 mkdir -p "$INCLUDE_DIR" &&
1851 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1852 [user]
1853 absolute = include
1855 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1856 [user]
1857 relative = include
1859 cat >"$HOME"/.gitconfig <<-EOF &&
1860 [user]
1861 global = true
1862 override = global
1863 [include]
1864 path = "$INCLUDE_DIR/absolute.include"
1866 cat >.git/config <<-\EOF
1867 [user]
1868 local = true
1869 override = local
1870 [include]
1871 path = ../include/relative.include
1875 test_expect_success '--show-origin with --list' '
1876 cat >expect <<-EOF &&
1877 file:$HOME/.gitconfig user.global=true
1878 file:$HOME/.gitconfig user.override=global
1879 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1880 file:$INCLUDE_DIR/absolute.include user.absolute=include
1881 file:.git/config user.local=true
1882 file:.git/config user.override=local
1883 file:.git/config include.path=../include/relative.include
1884 file:.git/../include/relative.include user.relative=include
1885 command line: user.environ=true
1886 command line: user.cmdline=true
1888 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1889 git -c user.cmdline=true config --list --show-origin >output &&
1890 test_cmp expect output
1893 test_expect_success '--show-origin with --list --null' '
1894 cat >expect <<-EOF &&
1895 file:$HOME/.gitconfigQuser.global
1896 trueQfile:$HOME/.gitconfigQuser.override
1897 globalQfile:$HOME/.gitconfigQinclude.path
1898 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1899 includeQfile:.git/configQuser.local
1900 trueQfile:.git/configQuser.override
1901 localQfile:.git/configQinclude.path
1902 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1903 includeQcommand line:Quser.cmdline
1904 trueQ
1906 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1907 nul_to_q <output.raw >output &&
1908 # The here-doc above adds a newline that the --null output would not
1909 # include. Add it here to make the two comparable.
1910 echo >>output &&
1911 test_cmp expect output
1914 test_expect_success '--show-origin with single file' '
1915 cat >expect <<-\EOF &&
1916 file:.git/config user.local=true
1917 file:.git/config user.override=local
1918 file:.git/config include.path=../include/relative.include
1920 git config --local --list --show-origin >output &&
1921 test_cmp expect output
1924 test_expect_success '--show-origin with --get-regexp' '
1925 cat >expect <<-EOF &&
1926 file:$HOME/.gitconfig user.global true
1927 file:.git/config user.local true
1929 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1930 test_cmp expect output
1933 test_expect_success '--show-origin getting a single key' '
1934 cat >expect <<-\EOF &&
1935 file:.git/config local
1937 git config --show-origin user.override >output &&
1938 test_cmp expect output
1941 test_expect_success 'set up custom config file' '
1942 CUSTOM_CONFIG_FILE="custom.conf" &&
1943 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1944 [user]
1945 custom = true
1949 test_expect_success !MINGW 'set up custom config file with special name characters' '
1950 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
1951 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
1954 test_expect_success !MINGW '--show-origin escape special file name characters' '
1955 cat >expect <<-\EOF &&
1956 file:"file\" (dq) and spaces.conf" user.custom=true
1958 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
1959 test_cmp expect output
1962 test_expect_success '--show-origin stdin' '
1963 cat >expect <<-\EOF &&
1964 standard input: user.custom=true
1966 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1967 test_cmp expect output
1970 test_expect_success '--show-origin stdin with file include' '
1971 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1972 [user]
1973 stdin = include
1975 cat >expect <<-EOF &&
1976 file:$INCLUDE_DIR/stdin.include include
1978 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
1979 git config --show-origin --includes --file - user.stdin >output &&
1981 test_cmp expect output
1984 test_expect_success '--show-origin blob' '
1985 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1986 cat >expect <<-EOF &&
1987 blob:$blob user.custom=true
1989 git config --blob=$blob --show-origin --list >output &&
1990 test_cmp expect output
1993 test_expect_success '--show-origin blob ref' '
1994 cat >expect <<-\EOF &&
1995 blob:main:custom.conf user.custom=true
1997 git add "$CUSTOM_CONFIG_FILE" &&
1998 git commit -m "new config file" &&
1999 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2000 test_cmp expect output
2003 test_expect_success '--show-scope with --list' '
2004 cat >expect <<-EOF &&
2005 global user.global=true
2006 global user.override=global
2007 global include.path=$INCLUDE_DIR/absolute.include
2008 global user.absolute=include
2009 local user.local=true
2010 local user.override=local
2011 local include.path=../include/relative.include
2012 local user.relative=include
2013 command user.cmdline=true
2015 git -c user.cmdline=true config --list --show-scope >output &&
2016 test_cmp expect output
2019 test_expect_success !MINGW '--show-scope with --blob' '
2020 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2021 cat >expect <<-EOF &&
2022 command user.custom=true
2024 git config --blob=$blob --show-scope --list >output &&
2025 test_cmp expect output
2028 test_expect_success '--show-scope with --local' '
2029 cat >expect <<-\EOF &&
2030 local user.local=true
2031 local user.override=local
2032 local include.path=../include/relative.include
2034 git config --local --list --show-scope >output &&
2035 test_cmp expect output
2038 test_expect_success '--show-scope getting a single value' '
2039 cat >expect <<-\EOF &&
2040 local true
2042 git config --show-scope --get user.local >output &&
2043 test_cmp expect output
2046 test_expect_success '--show-scope with --show-origin' '
2047 cat >expect <<-EOF &&
2048 global file:$HOME/.gitconfig user.global=true
2049 global file:$HOME/.gitconfig user.override=global
2050 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2051 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2052 local file:.git/config user.local=true
2053 local file:.git/config user.override=local
2054 local file:.git/config include.path=../include/relative.include
2055 local file:.git/../include/relative.include user.relative=include
2056 command command line: user.cmdline=true
2058 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2059 test_cmp expect output
2062 for opt in --local --worktree
2064 test_expect_success "$opt requires a repo" '
2065 # we expect 128 to ensure that we do not simply
2066 # fail to find anything and return code "1"
2067 test_expect_code 128 nongit git config $opt foo.bar
2069 done
2071 cat >.git/config <<-\EOF &&
2072 [section]
2073 foo = true
2074 number = 10
2075 big = 1M
2078 test_expect_success 'identical modern --type specifiers are allowed' '
2079 test_cmp_config 1048576 --type=int --type=int section.big
2082 test_expect_success 'identical legacy --type specifiers are allowed' '
2083 test_cmp_config 1048576 --int --int section.big
2086 test_expect_success 'identical mixed --type specifiers are allowed' '
2087 test_cmp_config 1048576 --int --type=int section.big
2090 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2091 test_must_fail git config --type=int --type=bool section.big 2>error &&
2092 test_i18ngrep "only one type at a time" error
2095 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2096 test_must_fail git config --int --bool section.big 2>error &&
2097 test_i18ngrep "only one type at a time" error
2100 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2101 test_must_fail git config --type=int --bool section.big 2>error &&
2102 test_i18ngrep "only one type at a time" error
2105 test_expect_success '--type allows valid type specifiers' '
2106 test_cmp_config true --type=bool section.foo
2109 test_expect_success '--no-type unsets type specifiers' '
2110 test_cmp_config 10 --type=bool --no-type section.number
2113 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2114 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2117 test_expect_success '--type rejects unknown specifiers' '
2118 test_must_fail git config --type=nonsense section.foo 2>error &&
2119 test_i18ngrep "unrecognized --type argument" error
2122 test_expect_success '--replace-all does not invent newlines' '
2123 q_to_tab >.git/config <<-\EOF &&
2124 [abc]key
2125 QkeepSection
2126 [xyz]
2127 Qkey = 1
2128 [abc]
2129 Qkey = a
2131 q_to_tab >expect <<-\EOF &&
2132 [abc]
2133 QkeepSection
2134 [xyz]
2135 Qkey = 1
2136 [abc]
2137 Qkey = b
2139 git config --replace-all abc.key b &&
2140 test_cmp expect .git/config
2143 test_expect_success 'set all config with value-pattern' '
2144 test_when_finished rm -f config initial &&
2145 git config --file=initial abc.key one &&
2147 # no match => add new entry
2148 cp initial config &&
2149 git config --file=config abc.key two a+ &&
2150 git config --file=config --list >actual &&
2151 cat >expect <<-\EOF &&
2152 abc.key=one
2153 abc.key=two
2155 test_cmp expect actual &&
2157 # multiple matches => failure
2158 test_must_fail git config --file=config abc.key three o+ 2>err &&
2159 test_i18ngrep "has multiple values" err &&
2161 # multiple values, no match => add
2162 git config --file=config abc.key three a+ &&
2163 git config --file=config --list >actual &&
2164 cat >expect <<-\EOF &&
2165 abc.key=one
2166 abc.key=two
2167 abc.key=three
2169 test_cmp expect actual &&
2171 # single match => replace
2172 git config --file=config abc.key four h+ &&
2173 git config --file=config --list >actual &&
2174 cat >expect <<-\EOF &&
2175 abc.key=one
2176 abc.key=two
2177 abc.key=four
2179 test_cmp expect actual
2182 test_expect_success '--replace-all and value-pattern' '
2183 test_when_finished rm -f config &&
2184 git config --file=config --add abc.key one &&
2185 git config --file=config --add abc.key two &&
2186 git config --file=config --add abc.key three &&
2187 git config --file=config --replace-all abc.key four "o+" &&
2188 git config --file=config --list >actual &&
2189 cat >expect <<-\EOF &&
2190 abc.key=four
2191 abc.key=three
2193 test_cmp expect actual
2196 test_expect_success 'refuse --fixed-value for incompatible actions' '
2197 test_when_finished rm -f config &&
2198 git config --file=config dev.null bogus &&
2200 # These modes do not allow --fixed-value at all
2201 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2202 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2203 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2204 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2205 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2206 test_must_fail git config --file=config --fixed-value --list &&
2207 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2208 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2210 # These modes complain when --fixed-value has no value-pattern
2211 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2212 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2213 test_must_fail git config --file=config --fixed-value --get dev.null &&
2214 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2215 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2216 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2217 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2220 test_expect_success '--fixed-value uses exact string matching' '
2221 test_when_finished rm -f config initial &&
2222 META="a+b*c?d[e]f.g" &&
2223 git config --file=initial fixed.test "$META" &&
2225 cp initial config &&
2226 git config --file=config fixed.test bogus "$META" &&
2227 git config --file=config --list >actual &&
2228 cat >expect <<-EOF &&
2229 fixed.test=$META
2230 fixed.test=bogus
2232 test_cmp expect actual &&
2234 cp initial config &&
2235 git config --file=config --fixed-value fixed.test bogus "$META" &&
2236 git config --file=config --list >actual &&
2237 cat >expect <<-\EOF &&
2238 fixed.test=bogus
2240 test_cmp expect actual &&
2242 cp initial config &&
2243 test_must_fail git config --file=config --unset fixed.test "$META" &&
2244 git config --file=config --fixed-value --unset fixed.test "$META" &&
2245 test_must_fail git config --file=config fixed.test &&
2247 cp initial config &&
2248 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2249 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2250 test_must_fail git config --file=config fixed.test &&
2252 cp initial config &&
2253 git config --file=config --replace-all fixed.test bogus "$META" &&
2254 git config --file=config --list >actual &&
2255 cat >expect <<-EOF &&
2256 fixed.test=$META
2257 fixed.test=bogus
2259 test_cmp expect actual &&
2261 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2262 git config --file=config --list >actual &&
2263 cat >expect <<-EOF &&
2264 fixed.test=bogus
2265 fixed.test=bogus
2267 test_cmp expect actual
2270 test_expect_success '--get and --get-all with --fixed-value' '
2271 test_when_finished rm -f config &&
2272 META="a+b*c?d[e]f.g" &&
2273 git config --file=config fixed.test bogus &&
2274 git config --file=config --add fixed.test "$META" &&
2276 git config --file=config --get fixed.test bogus &&
2277 test_must_fail git config --file=config --get fixed.test "$META" &&
2278 git config --file=config --get --fixed-value fixed.test "$META" &&
2279 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2281 git config --file=config --get-all fixed.test bogus &&
2282 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2283 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2284 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2286 git config --file=config --get-regexp fixed+ bogus &&
2287 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2288 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2289 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2292 test_done