Merge branch 'cb/grep-pcre-ucp'
[alt-git.git] / t / t1300-config.sh
blob2575279ab84e8a32239a7ea30f72022d3ff6b9f8
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 'clear default config' '
15 rm -f .git/config
18 cat > expect << EOF
19 [section]
20 penguin = little blue
21 EOF
22 test_expect_success 'initial' '
23 git config section.penguin "little blue" &&
24 test_cmp expect .git/config
27 cat > expect << EOF
28 [section]
29 penguin = little blue
30 Movie = BadPhysics
31 EOF
32 test_expect_success 'mixed case' '
33 git config Section.Movie BadPhysics &&
34 test_cmp expect .git/config
37 cat > expect << EOF
38 [section]
39 penguin = little blue
40 Movie = BadPhysics
41 [Sections]
42 WhatEver = Second
43 EOF
44 test_expect_success 'similar section' '
45 git config Sections.WhatEver Second &&
46 test_cmp expect .git/config
49 cat > expect << EOF
50 [section]
51 penguin = little blue
52 Movie = BadPhysics
53 UPPERCASE = true
54 [Sections]
55 WhatEver = Second
56 EOF
57 test_expect_success 'uppercase section' '
58 git config SECTION.UPPERCASE true &&
59 test_cmp expect .git/config
62 test_expect_success 'replace with non-match' '
63 git config section.penguin kingpin !blue
66 test_expect_success 'replace with non-match (actually matching)' '
67 git config section.penguin "very blue" !kingpin
70 cat > expect << EOF
71 [section]
72 penguin = very blue
73 Movie = BadPhysics
74 UPPERCASE = true
75 penguin = kingpin
76 [Sections]
77 WhatEver = Second
78 EOF
80 test_expect_success 'non-match result' 'test_cmp expect .git/config'
82 test_expect_success 'find mixed-case key by canonical name' '
83 test_cmp_config Second sections.whatever
86 test_expect_success 'find mixed-case key by non-canonical name' '
87 test_cmp_config Second SeCtIoNs.WhAtEvEr
90 test_expect_success 'subsections are not canonicalized by git-config' '
91 cat >>.git/config <<-\EOF &&
92 [section.SubSection]
93 key = one
94 [section "SubSection"]
95 key = two
96 EOF
97 test_cmp_config one section.subsection.key &&
98 test_cmp_config two section.SubSection.key
101 cat > .git/config <<\EOF
102 [alpha]
103 bar = foo
104 [beta]
105 baz = multiple \
106 lines
107 foo = bar
110 test_expect_success 'unset with cont. lines' '
111 git config --unset beta.baz
114 cat > expect <<\EOF
115 [alpha]
116 bar = foo
117 [beta]
118 foo = bar
121 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
123 cat > .git/config << EOF
124 [beta] ; silly comment # another comment
125 noIndent= sillyValue ; 'nother silly comment
127 # empty line
128 ; comment
129 haha ="beta" # last silly comment
130 haha = hello
131 haha = bello
132 [nextSection] noNewline = ouch
135 cp .git/config .git/config2
137 test_expect_success 'multiple unset' '
138 git config --unset-all beta.haha
141 cat > expect << EOF
142 [beta] ; silly comment # another comment
143 noIndent= sillyValue ; 'nother silly comment
145 # empty line
146 ; comment
147 [nextSection] noNewline = ouch
150 test_expect_success 'multiple unset is correct' '
151 test_cmp expect .git/config
154 cp .git/config2 .git/config
156 test_expect_success '--replace-all missing value' '
157 test_must_fail git config --replace-all beta.haha &&
158 test_cmp .git/config2 .git/config
161 rm .git/config2
163 test_expect_success '--replace-all' '
164 git config --replace-all beta.haha gamma
167 cat > expect << EOF
168 [beta] ; silly comment # another comment
169 noIndent= sillyValue ; 'nother silly comment
171 # empty line
172 ; comment
173 haha = gamma
174 [nextSection] noNewline = ouch
177 test_expect_success 'all replaced' '
178 test_cmp expect .git/config
181 cat > expect << EOF
182 [beta] ; silly comment # another comment
183 noIndent= sillyValue ; 'nother silly comment
185 # empty line
186 ; comment
187 haha = alpha
188 [nextSection] noNewline = ouch
190 test_expect_success 'really mean test' '
191 git config beta.haha alpha &&
192 test_cmp expect .git/config
195 cat > expect << EOF
196 [beta] ; silly comment # another comment
197 noIndent= sillyValue ; 'nother silly comment
199 # empty line
200 ; comment
201 haha = alpha
202 [nextSection]
203 nonewline = wow
205 test_expect_success 'really really mean test' '
206 git config nextsection.nonewline wow &&
207 test_cmp expect .git/config
210 test_expect_success 'get value' '
211 test_cmp_config alpha beta.haha
214 cat > expect << EOF
215 [beta] ; silly comment # another comment
216 noIndent= sillyValue ; 'nother silly comment
218 # empty line
219 ; comment
220 [nextSection]
221 nonewline = wow
223 test_expect_success 'unset' '
224 git config --unset beta.haha &&
225 test_cmp expect .git/config
228 cat > expect << EOF
229 [beta] ; silly comment # another comment
230 noIndent= sillyValue ; 'nother silly comment
232 # empty line
233 ; comment
234 [nextSection]
235 nonewline = wow
236 NoNewLine = wow2 for me
238 test_expect_success 'multivar' '
239 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
240 test_cmp expect .git/config
243 test_expect_success 'non-match' '
244 git config --get nextsection.nonewline !for
247 test_expect_success 'non-match value' '
248 test_cmp_config wow --get nextsection.nonewline !for
251 test_expect_success 'multi-valued get returns final one' '
252 test_cmp_config "wow2 for me" --get nextsection.nonewline
255 test_expect_success 'multi-valued get-all returns all' '
256 cat >expect <<-\EOF &&
258 wow2 for me
260 git config --get-all nextsection.nonewline >actual &&
261 test_cmp expect actual
264 cat > expect << EOF
265 [beta] ; silly comment # another comment
266 noIndent= sillyValue ; 'nother silly comment
268 # empty line
269 ; comment
270 [nextSection]
271 nonewline = wow3
272 NoNewLine = wow2 for me
274 test_expect_success 'multivar replace' '
275 git config nextsection.nonewline "wow3" "wow$" &&
276 test_cmp expect .git/config
279 test_expect_success 'ambiguous unset' '
280 test_must_fail git config --unset nextsection.nonewline
283 test_expect_success 'invalid unset' '
284 test_must_fail git config --unset somesection.nonewline
287 cat > expect << EOF
288 [beta] ; silly comment # another comment
289 noIndent= sillyValue ; 'nother silly comment
291 # empty line
292 ; comment
293 [nextSection]
294 NoNewLine = wow2 for me
297 test_expect_success 'multivar unset' '
298 git config --unset nextsection.nonewline "wow3$" &&
299 test_cmp expect .git/config
302 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
304 test_expect_success 'correct key' 'git config 123456.a123 987'
306 test_expect_success 'hierarchical section' '
307 git config Version.1.2.3eX.Alpha beta
310 cat > expect << EOF
311 [beta] ; silly comment # another comment
312 noIndent= sillyValue ; 'nother silly comment
314 # empty line
315 ; comment
316 [nextSection]
317 NoNewLine = wow2 for me
318 [123456]
319 a123 = 987
320 [Version "1.2.3eX"]
321 Alpha = beta
324 test_expect_success 'hierarchical section value' '
325 test_cmp expect .git/config
328 cat > expect << EOF
329 beta.noindent=sillyValue
330 nextsection.nonewline=wow2 for me
331 123456.a123=987
332 version.1.2.3eX.alpha=beta
335 test_expect_success 'working --list' '
336 git config --list > output &&
337 test_cmp expect output
339 test_expect_success '--list without repo produces empty output' '
340 git --git-dir=nonexistent config --list >output &&
341 test_must_be_empty output
344 cat > expect << EOF
345 beta.noindent
346 nextsection.nonewline
347 123456.a123
348 version.1.2.3eX.alpha
351 test_expect_success '--name-only --list' '
352 git config --name-only --list >output &&
353 test_cmp expect output
356 cat > expect << EOF
357 beta.noindent sillyValue
358 nextsection.nonewline wow2 for me
361 test_expect_success '--get-regexp' '
362 git config --get-regexp in >output &&
363 test_cmp expect output
366 cat > expect << EOF
367 beta.noindent
368 nextsection.nonewline
371 test_expect_success '--name-only --get-regexp' '
372 git config --name-only --get-regexp in >output &&
373 test_cmp expect output
376 cat > expect << EOF
377 wow2 for me
378 wow4 for you
381 test_expect_success '--add' '
382 git config --add nextsection.nonewline "wow4 for you" &&
383 git config --get-all nextsection.nonewline > output &&
384 test_cmp expect output
387 cat > .git/config << EOF
388 [novalue]
389 variable
390 [emptyvalue]
391 variable =
394 test_expect_success 'get variable with no value' '
395 git config --get novalue.variable ^$
398 test_expect_success 'get variable with empty value' '
399 git config --get emptyvalue.variable ^$
402 echo novalue.variable > expect
404 test_expect_success 'get-regexp variable with no value' '
405 git config --get-regexp novalue > output &&
406 test_cmp expect output
409 echo 'novalue.variable true' > expect
411 test_expect_success 'get-regexp --bool variable with no value' '
412 git config --bool --get-regexp novalue > output &&
413 test_cmp expect output
416 echo 'emptyvalue.variable ' > expect
418 test_expect_success 'get-regexp variable with empty value' '
419 git config --get-regexp emptyvalue > output &&
420 test_cmp expect output
423 echo true > expect
425 test_expect_success 'get bool variable with no value' '
426 git config --bool novalue.variable > output &&
427 test_cmp expect output
430 echo false > expect
432 test_expect_success 'get bool variable with empty value' '
433 git config --bool emptyvalue.variable > output &&
434 test_cmp expect output
437 test_expect_success 'no arguments, but no crash' '
438 test_must_fail git config >output 2>&1 &&
439 test_i18ngrep usage output
442 cat > .git/config << EOF
443 [a.b]
444 c = d
447 cat > expect << EOF
448 [a.b]
449 c = d
451 x = y
454 test_expect_success 'new section is partial match of another' '
455 git config a.x y &&
456 test_cmp expect .git/config
459 cat > expect << EOF
460 [a.b]
461 c = d
463 x = y
464 b = c
466 x = y
469 test_expect_success 'new variable inserts into proper section' '
470 git config b.x y &&
471 git config a.b c &&
472 test_cmp expect .git/config
475 test_expect_success 'alternative --file (non-existing file should fail)' '
476 test_must_fail git config --file non-existing-config -l &&
477 test_must_fail git config --file non-existing-config test.xyzzy
480 cat > other-config << EOF
481 [ein]
482 bahn = strasse
485 cat > expect << EOF
486 ein.bahn=strasse
489 test_expect_success 'alternative GIT_CONFIG' '
490 GIT_CONFIG=other-config git config --list >output &&
491 test_cmp expect output
494 test_expect_success 'alternative GIT_CONFIG (--file)' '
495 git config --file other-config --list >output &&
496 test_cmp expect output
499 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
500 git config --file - --list <other-config >output &&
501 test_cmp expect output
504 test_expect_success 'setting a value in stdin is an error' '
505 test_must_fail git config --file - some.value foo
508 test_expect_success 'editing stdin is an error' '
509 test_must_fail git config --file - --edit
512 test_expect_success 'refer config from subdirectory' '
513 mkdir x &&
514 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
517 cat > expect << EOF
518 [ein]
519 bahn = strasse
520 [anwohner]
521 park = ausweis
524 test_expect_success '--set in alternative file' '
525 git config --file=other-config anwohner.park ausweis &&
526 test_cmp expect other-config
529 cat > .git/config << EOF
530 # Hallo
531 #Bello
532 [branch "eins"]
533 x = 1
534 [branch.eins]
535 y = 1
536 [branch "1 234 blabl/a"]
537 weird
540 test_expect_success 'rename section' '
541 git config --rename-section branch.eins branch.zwei
544 cat > expect << EOF
545 # Hallo
546 #Bello
547 [branch "zwei"]
548 x = 1
549 [branch "zwei"]
550 y = 1
551 [branch "1 234 blabl/a"]
552 weird
555 test_expect_success 'rename succeeded' '
556 test_cmp expect .git/config
559 test_expect_success 'rename non-existing section' '
560 test_must_fail git config --rename-section \
561 branch."world domination" branch.drei
564 test_expect_success 'rename succeeded' '
565 test_cmp expect .git/config
568 test_expect_success 'rename another section' '
569 git config --rename-section branch."1 234 blabl/a" branch.drei
572 cat > expect << EOF
573 # Hallo
574 #Bello
575 [branch "zwei"]
576 x = 1
577 [branch "zwei"]
578 y = 1
579 [branch "drei"]
580 weird
583 test_expect_success 'rename succeeded' '
584 test_cmp expect .git/config
587 cat >> .git/config << EOF
588 [branch "vier"] z = 1
591 test_expect_success 'rename a section with a var on the same line' '
592 git config --rename-section branch.vier branch.zwei
595 cat > expect << EOF
596 # Hallo
597 #Bello
598 [branch "zwei"]
599 x = 1
600 [branch "zwei"]
601 y = 1
602 [branch "drei"]
603 weird
604 [branch "zwei"]
605 z = 1
608 test_expect_success 'rename succeeded' '
609 test_cmp expect .git/config
612 test_expect_success 'renaming empty section name is rejected' '
613 test_must_fail git config --rename-section branch.zwei ""
616 test_expect_success 'renaming to bogus section is rejected' '
617 test_must_fail git config --rename-section branch.zwei "bogus name"
620 cat >> .git/config << EOF
621 [branch "zwei"] a = 1 [branch "vier"]
624 test_expect_success 'remove section' '
625 git config --remove-section branch.zwei
628 cat > expect << EOF
629 # Hallo
630 #Bello
631 [branch "drei"]
632 weird
635 test_expect_success 'section was removed properly' '
636 test_cmp expect .git/config
639 cat > expect << EOF
640 [gitcvs]
641 enabled = true
642 dbname = %Ggitcvs2.%a.%m.sqlite
643 [gitcvs "ext"]
644 dbname = %Ggitcvs1.%a.%m.sqlite
647 test_expect_success 'section ending' '
648 rm -f .git/config &&
649 git config gitcvs.enabled true &&
650 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
651 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
652 test_cmp expect .git/config
656 test_expect_success numbers '
657 git config kilo.gram 1k &&
658 git config mega.ton 1m &&
659 echo 1024 >expect &&
660 echo 1048576 >>expect &&
661 git config --int --get kilo.gram >actual &&
662 git config --int --get mega.ton >>actual &&
663 test_cmp expect actual
666 test_expect_success '--int is at least 64 bits' '
667 git config giga.watts 121g &&
668 echo >expect &&
669 test_cmp_config 129922760704 --int --get giga.watts
672 test_expect_success 'invalid unit' '
673 git config aninvalid.unit "1auto" &&
674 test_cmp_config 1auto aninvalid.unit &&
675 test_must_fail git config --int --get aninvalid.unit 2>actual &&
676 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
679 test_expect_success 'invalid unit boolean' '
680 git config commit.gpgsign "1true" &&
681 test_cmp_config 1true commit.gpgsign &&
682 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
683 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
686 test_expect_success 'line number is reported correctly' '
687 printf "[bool]\n\tvar\n" >invalid &&
688 test_must_fail git config -f invalid --path bool.var 2>actual &&
689 test_i18ngrep "line 2" actual
692 test_expect_success 'invalid stdin config' '
693 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
694 test_i18ngrep "bad config line 1 in standard input" output
697 cat > expect << EOF
698 true
699 false
700 true
701 false
702 true
703 false
704 true
705 false
708 test_expect_success bool '
710 git config bool.true1 01 &&
711 git config bool.true2 -1 &&
712 git config bool.true3 YeS &&
713 git config bool.true4 true &&
714 git config bool.false1 000 &&
715 git config bool.false2 "" &&
716 git config bool.false3 nO &&
717 git config bool.false4 FALSE &&
718 rm -f result &&
719 for i in 1 2 3 4
721 git config --bool --get bool.true$i >>result &&
722 git config --bool --get bool.false$i >>result || return 1
723 done &&
724 test_cmp expect result'
726 test_expect_success 'invalid bool (--get)' '
728 git config bool.nobool foobar &&
729 test_must_fail git config --bool --get bool.nobool'
731 test_expect_success 'invalid bool (set)' '
733 test_must_fail git config --bool bool.nobool foobar'
735 cat > expect <<\EOF
736 [bool]
737 true1 = true
738 true2 = true
739 true3 = true
740 true4 = true
741 false1 = false
742 false2 = false
743 false3 = false
744 false4 = false
747 test_expect_success 'set --bool' '
749 rm -f .git/config &&
750 git config --bool bool.true1 01 &&
751 git config --bool bool.true2 -1 &&
752 git config --bool bool.true3 YeS &&
753 git config --bool bool.true4 true &&
754 git config --bool bool.false1 000 &&
755 git config --bool bool.false2 "" &&
756 git config --bool bool.false3 nO &&
757 git config --bool bool.false4 FALSE &&
758 test_cmp expect .git/config'
760 cat > expect <<\EOF
761 [int]
762 val1 = 1
763 val2 = -1
764 val3 = 5242880
767 test_expect_success 'set --int' '
769 rm -f .git/config &&
770 git config --int int.val1 01 &&
771 git config --int int.val2 -1 &&
772 git config --int int.val3 5m &&
773 test_cmp expect .git/config
776 test_expect_success 'get --bool-or-int' '
777 cat >.git/config <<-\EOF &&
778 [bool]
779 true1
780 true2 = true
781 false = false
782 [int]
783 int1 = 0
784 int2 = 1
785 int3 = -1
787 cat >expect <<-\EOF &&
788 true
789 true
790 false
796 git config --bool-or-int bool.true1 &&
797 git config --bool-or-int bool.true2 &&
798 git config --bool-or-int bool.false &&
799 git config --bool-or-int int.int1 &&
800 git config --bool-or-int int.int2 &&
801 git config --bool-or-int int.int3
802 } >actual &&
803 test_cmp expect actual
806 cat >expect <<\EOF
807 [bool]
808 true1 = true
809 false1 = false
810 true2 = true
811 false2 = false
812 [int]
813 int1 = 0
814 int2 = 1
815 int3 = -1
818 test_expect_success 'set --bool-or-int' '
819 rm -f .git/config &&
820 git config --bool-or-int bool.true1 true &&
821 git config --bool-or-int bool.false1 false &&
822 git config --bool-or-int bool.true2 yes &&
823 git config --bool-or-int bool.false2 no &&
824 git config --bool-or-int int.int1 0 &&
825 git config --bool-or-int int.int2 1 &&
826 git config --bool-or-int int.int3 -1 &&
827 test_cmp expect .git/config
830 cat >expect <<\EOF
831 [path]
832 home = ~/
833 normal = /dev/null
834 trailingtilde = foo~
837 test_expect_success !MINGW 'set --path' '
838 rm -f .git/config &&
839 git config --path path.home "~/" &&
840 git config --path path.normal "/dev/null" &&
841 git config --path path.trailingtilde "foo~" &&
842 test_cmp expect .git/config'
844 if test_have_prereq !MINGW && test "${HOME+set}"
845 then
846 test_set_prereq HOMEVAR
849 cat >expect <<EOF
850 $HOME/
851 /dev/null
852 foo~
855 test_expect_success HOMEVAR 'get --path' '
856 git config --get --path path.home > result &&
857 git config --get --path path.normal >> result &&
858 git config --get --path path.trailingtilde >> result &&
859 test_cmp expect result
862 cat >expect <<\EOF
863 /dev/null
864 foo~
867 test_expect_success !MINGW 'get --path copes with unset $HOME' '
869 sane_unset HOME &&
870 test_must_fail git config --get --path path.home \
871 >result 2>msg &&
872 git config --get --path path.normal >>result &&
873 git config --get --path path.trailingtilde >>result
874 ) &&
875 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
876 test_cmp expect result
879 test_expect_success 'get --path barfs on boolean variable' '
880 echo "[path]bool" >.git/config &&
881 test_must_fail git config --get --path path.bool
884 test_expect_success 'get --expiry-date' '
885 rel="3.weeks.5.days.00:00" &&
886 rel_out="$rel ->" &&
887 cat >.git/config <<-\EOF &&
888 [date]
889 valid1 = "3.weeks.5.days 00:00"
890 valid2 = "Fri Jun 4 15:46:55 2010"
891 valid3 = "2017/11/11 11:11:11PM"
892 valid4 = "2017/11/10 09:08:07 PM"
893 valid5 = "never"
894 invalid1 = "abc"
896 cat >expect <<-EOF &&
897 $(test-tool date timestamp $rel)
898 1275666415
899 1510441871
900 1510348087
903 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
905 echo "$rel_out $(git config --expiry-date date.valid1)" &&
906 git config --expiry-date date.valid2 &&
907 git config --expiry-date date.valid3 &&
908 git config --expiry-date date.valid4 &&
909 git config --expiry-date date.valid5
910 } >actual &&
911 test_cmp expect actual &&
912 test_must_fail git config --expiry-date date.invalid1
915 test_expect_success 'get --type=color' '
916 rm .git/config &&
917 git config foo.color "red" &&
918 git config --get --type=color foo.color >actual.raw &&
919 test_decode_color <actual.raw >actual &&
920 echo "<RED>" >expect &&
921 test_cmp expect actual
924 cat >expect << EOF
925 [foo]
926 color = red
929 test_expect_success 'set --type=color' '
930 rm .git/config &&
931 git config --type=color foo.color "red" &&
932 test_cmp expect .git/config
935 test_expect_success 'get --type=color barfs on non-color' '
936 echo "[foo]bar=not-a-color" >.git/config &&
937 test_must_fail git config --get --type=color foo.bar
940 test_expect_success 'set --type=color barfs on non-color' '
941 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
942 test_i18ngrep "cannot parse color" error
945 cat > expect << EOF
946 [quote]
947 leading = " test"
948 ending = "test "
949 semicolon = "test;test"
950 hash = "test#test"
952 test_expect_success 'quoting' '
953 rm -f .git/config &&
954 git config quote.leading " test" &&
955 git config quote.ending "test " &&
956 git config quote.semicolon "test;test" &&
957 git config quote.hash "test#test" &&
958 test_cmp expect .git/config
961 test_expect_success 'key with newline' '
962 test_must_fail git config "key.with
963 newline" 123'
965 test_expect_success 'value with newline' 'git config key.sub value.with\\\
966 newline'
968 cat > .git/config <<\EOF
969 [section]
970 ; comment \
971 continued = cont\
972 inued
973 noncont = not continued ; \
974 quotecont = "cont;\
975 inued"
978 cat > expect <<\EOF
979 section.continued=continued
980 section.noncont=not continued
981 section.quotecont=cont;inued
984 test_expect_success 'value continued on next line' '
985 git config --list > result &&
986 test_cmp expect result
989 cat > .git/config <<\EOF
990 [section "sub=section"]
991 val1 = foo=bar
992 val2 = foo\nbar
993 val3 = \n\n
994 val4 =
995 val5
998 cat > expect <<\EOF
999 section.sub=section.val1
1000 foo=barQsection.sub=section.val2
1002 barQsection.sub=section.val3
1005 Qsection.sub=section.val4
1006 Qsection.sub=section.val5Q
1008 test_expect_success '--null --list' '
1009 git config --null --list >result.raw &&
1010 nul_to_q <result.raw >result &&
1011 echo >>result &&
1012 test_cmp expect result
1015 test_expect_success '--null --get-regexp' '
1016 git config --null --get-regexp "val[0-9]" >result.raw &&
1017 nul_to_q <result.raw >result &&
1018 echo >>result &&
1019 test_cmp expect result
1022 test_expect_success 'inner whitespace kept verbatim' '
1023 git config section.val "foo bar" &&
1024 test_cmp_config "foo bar" section.val
1027 test_expect_success SYMLINKS 'symlinked configuration' '
1028 ln -s notyet myconfig &&
1029 git config --file=myconfig test.frotz nitfol &&
1030 test -h myconfig &&
1031 test -f notyet &&
1032 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1033 git config --file=myconfig test.xyzzy rezrov &&
1034 test -h myconfig &&
1035 test -f notyet &&
1036 cat >expect <<-\EOF &&
1037 nitfol
1038 rezrov
1041 git config --file=notyet test.frotz &&
1042 git config --file=notyet test.xyzzy
1043 } >actual &&
1044 test_cmp expect actual
1047 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1048 ln -s doesnotexist linktonada &&
1049 ln -s linktonada linktolinktonada &&
1050 test_must_fail git config --file=linktonada --list &&
1051 test_must_fail git config --file=linktolinktonada --list
1054 test_expect_success 'check split_cmdline return' "
1055 git config alias.split-cmdline-fix 'echo \"' &&
1056 test_must_fail git split-cmdline-fix &&
1057 echo foo > foo &&
1058 git add foo &&
1059 git commit -m 'initial commit' &&
1060 git config branch.main.mergeoptions 'echo \"' &&
1061 test_must_fail git merge main
1064 test_expect_success 'git -c "key=value" support' '
1065 cat >expect <<-\EOF &&
1066 value
1067 value
1068 true
1071 git -c section.name=value config section.name &&
1072 git -c foo.CamelCase=value config foo.camelcase &&
1073 git -c foo.flag config --bool foo.flag
1074 } >actual &&
1075 test_cmp expect actual &&
1076 test_must_fail git -c name=value config section.name
1079 # We just need a type-specifier here that cares about the
1080 # distinction internally between a NULL boolean and a real
1081 # string (because most of git's internal parsers do care).
1082 # Using "--path" works, but we do not otherwise care about
1083 # its semantics.
1084 test_expect_success 'git -c can represent empty string' '
1085 echo >expect &&
1086 git -c foo.empty= config --path foo.empty >actual &&
1087 test_cmp expect actual
1090 test_expect_success 'key sanity-checking' '
1091 test_must_fail git config foo=bar &&
1092 test_must_fail git config foo=.bar &&
1093 test_must_fail git config foo.ba=r &&
1094 test_must_fail git config foo.1bar &&
1095 test_must_fail git config foo."ba
1096 z".bar &&
1097 test_must_fail git config . false &&
1098 test_must_fail git config .foo false &&
1099 test_must_fail git config foo. false &&
1100 test_must_fail git config .foo. false &&
1101 git config foo.bar true &&
1102 git config foo."ba =z".bar false
1105 test_expect_success 'git -c works with aliases of builtins' '
1106 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1107 echo bar >expect &&
1108 git checkconfig >actual &&
1109 test_cmp expect actual
1112 test_expect_success 'aliases can be CamelCased' '
1113 test_config alias.CamelCased "rev-parse HEAD" &&
1114 git CamelCased >out &&
1115 git rev-parse HEAD >expect &&
1116 test_cmp expect out
1119 test_expect_success 'git -c does not split values on equals' '
1120 echo "value with = in it" >expect &&
1121 git -c section.foo="value with = in it" config section.foo >actual &&
1122 test_cmp expect actual
1125 test_expect_success 'git -c dies on bogus config' '
1126 test_must_fail git -c core.bare=foo rev-parse
1129 test_expect_success 'git -c complains about empty key' '
1130 test_must_fail git -c "=foo" rev-parse
1133 test_expect_success 'git -c complains about empty key and value' '
1134 test_must_fail git -c "" rev-parse
1137 test_expect_success 'multiple git -c appends config' '
1138 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1139 cat >expect <<-\EOF &&
1140 x.one 1
1141 x.two 2
1143 git -c x.one=1 x >actual &&
1144 test_cmp expect actual
1147 test_expect_success 'last one wins: two level vars' '
1149 # sec.var and sec.VAR are the same variable, as the first
1150 # and the last level of a configuration variable name is
1151 # case insensitive.
1153 echo VAL >expect &&
1155 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1156 test_cmp expect actual &&
1157 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1158 test_cmp expect actual &&
1160 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1161 test_cmp expect actual &&
1162 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1163 test_cmp expect actual
1166 test_expect_success 'last one wins: three level vars' '
1168 # v.a.r and v.A.r are not the same variable, as the middle
1169 # level of a three-level configuration variable name is
1170 # case sensitive.
1172 echo val >expect &&
1173 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1174 test_cmp expect actual &&
1175 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1176 test_cmp expect actual &&
1178 # v.a.r and V.a.R are the same variable, as the first
1179 # and the last level of a configuration variable name is
1180 # case insensitive.
1182 echo VAL >expect &&
1183 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1184 test_cmp expect actual &&
1185 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1186 test_cmp expect actual &&
1187 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1188 test_cmp expect actual &&
1189 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1190 test_cmp expect actual
1193 test_expect_success 'old-fashioned settings are case insensitive' '
1194 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1196 cat >testConfig_actual <<-EOF &&
1197 [V.A]
1198 r = value1
1200 q_to_tab >testConfig_expect <<-EOF &&
1201 [V.A]
1202 Qr = value2
1204 git config -f testConfig_actual "v.a.r" value2 &&
1205 test_cmp testConfig_expect testConfig_actual &&
1207 cat >testConfig_actual <<-EOF &&
1208 [V.A]
1209 r = value1
1211 q_to_tab >testConfig_expect <<-EOF &&
1212 [V.A]
1213 QR = value2
1215 git config -f testConfig_actual "V.a.R" value2 &&
1216 test_cmp testConfig_expect testConfig_actual &&
1218 cat >testConfig_actual <<-EOF &&
1219 [V.A]
1220 r = value1
1222 q_to_tab >testConfig_expect <<-EOF &&
1223 [V.A]
1224 r = value1
1225 Qr = value2
1227 git config -f testConfig_actual "V.A.r" value2 &&
1228 test_cmp testConfig_expect testConfig_actual &&
1230 cat >testConfig_actual <<-EOF &&
1231 [V.A]
1232 r = value1
1234 q_to_tab >testConfig_expect <<-EOF &&
1235 [V.A]
1236 r = value1
1237 Qr = value2
1239 git config -f testConfig_actual "v.A.r" value2 &&
1240 test_cmp testConfig_expect testConfig_actual
1243 test_expect_success 'setting different case sensitive subsections ' '
1244 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1246 cat >testConfig_actual <<-EOF &&
1247 [V "A"]
1248 R = v1
1249 [K "E"]
1250 Y = v1
1251 [a "b"]
1252 c = v1
1253 [d "e"]
1254 f = v1
1256 q_to_tab >testConfig_expect <<-EOF &&
1257 [V "A"]
1258 Qr = v2
1259 [K "E"]
1260 Qy = v2
1261 [a "b"]
1262 Qc = v2
1263 [d "e"]
1264 f = v1
1265 [d "E"]
1266 Qf = v2
1268 # exact match
1269 git config -f testConfig_actual a.b.c v2 &&
1270 # match section and subsection, key is cased differently.
1271 git config -f testConfig_actual K.E.y v2 &&
1272 # section and key are matched case insensitive, but subsection needs
1273 # to match; When writing out new values only the key is adjusted
1274 git config -f testConfig_actual v.A.r v2 &&
1275 # subsection is not matched:
1276 git config -f testConfig_actual d.E.f v2 &&
1277 test_cmp testConfig_expect testConfig_actual
1280 for VAR in a .a a. a.0b a."b c". a."b c".0d
1282 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1283 test_must_fail git -c "$VAR=VAL" config -l
1285 done
1287 for VAR in a.b a."b c".d
1289 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1290 echo VAL >expect &&
1291 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1292 test_cmp expect actual
1294 done
1296 test_expect_success 'git -c is not confused by empty environment' '
1297 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1300 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1301 v="${SQ}key.one=foo${SQ}" &&
1302 v="$v ${SQ}key.two=bar${SQ}" &&
1303 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1304 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1305 cat >expect <<-EOF &&
1306 key.one foo
1307 key.two bar
1308 key.ambiguous section.whatever=value
1310 test_cmp expect actual
1313 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1314 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1315 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1316 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1317 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1318 cat >expect <<-EOF &&
1319 key.one foo
1320 key.two bar
1321 key.ambiguous=section.whatever value
1323 test_cmp expect actual
1326 test_expect_success 'old and new-style entries can mix' '
1327 v="${SQ}key.oldone=oldfoo${SQ}" &&
1328 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1329 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1330 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1331 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1332 cat >expect <<-EOF &&
1333 key.oldone oldfoo
1334 key.newone newfoo
1335 key.oldtwo oldbar
1336 key.newtwo newbar
1338 test_cmp expect actual
1341 test_expect_success 'old and new bools with ambiguous subsection' '
1342 v="${SQ}key.with=equals.oldbool${SQ}" &&
1343 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1344 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1345 cat >expect <<-EOF &&
1346 key.with equals.oldbool
1347 key.with=equals.newbool
1349 test_cmp expect actual
1352 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1353 cat >expect <<-\EOF &&
1354 env.one one
1355 env.two two
1357 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1358 git config --get-regexp "env.*" >actual &&
1359 test_cmp expect actual &&
1361 cat >expect <<-EOF &&
1362 env.one one${SQ}
1363 env.two two
1365 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1366 git config --get-regexp "env.*" >actual &&
1367 test_cmp expect actual &&
1369 test_must_fail env \
1370 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1371 git config --get-regexp "env.*"
1374 test_expect_success 'git --config-env=key=envvar support' '
1375 cat >expect <<-\EOF &&
1376 value
1377 value
1378 value
1379 value
1380 false
1381 false
1384 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1385 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1386 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1387 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1388 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1389 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1390 } >actual &&
1391 test_cmp expect actual
1394 test_expect_success 'git --config-env with missing value' '
1395 test_must_fail env ENVVAR=value git --config-env 2>error &&
1396 grep "no config key given for --config-env" error &&
1397 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1398 grep "invalid config format: config" error
1401 test_expect_success 'git --config-env fails with invalid parameters' '
1402 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1403 test_i18ngrep "invalid config format: foo.flag" error &&
1404 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1405 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1406 sane_unset NONEXISTENT &&
1407 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1408 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1411 test_expect_success 'git -c and --config-env work together' '
1412 cat >expect <<-\EOF &&
1413 bar.cmd cmd-value
1414 bar.env env-value
1416 ENVVAR=env-value git \
1417 -c bar.cmd=cmd-value \
1418 --config-env=bar.env=ENVVAR \
1419 config --get-regexp "^bar.*" >actual &&
1420 test_cmp expect actual
1423 test_expect_success 'git -c and --config-env override each other' '
1424 cat >expect <<-\EOF &&
1429 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1430 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1431 } >actual &&
1432 test_cmp expect actual
1435 test_expect_success '--config-env handles keys with equals' '
1436 echo value=with=equals >expect &&
1437 ENVVAR=value=with=equals git \
1438 --config-env=section.subsection=with=equals.key=ENVVAR \
1439 config section.subsection=with=equals.key >actual &&
1440 test_cmp expect actual
1443 test_expect_success 'git config handles environment config pairs' '
1444 GIT_CONFIG_COUNT=2 \
1445 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1446 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1447 git config --get-regexp "pair.*" >actual &&
1448 cat >expect <<-EOF &&
1449 pair.one foo
1450 pair.two bar
1452 test_cmp expect actual
1455 test_expect_success 'git config ignores pairs without count' '
1456 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1457 git config pair.one 2>error &&
1458 test_must_be_empty error
1461 test_expect_success 'git config ignores pairs with zero count' '
1462 test_must_fail env \
1463 GIT_CONFIG_COUNT=0 \
1464 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1465 git config pair.one
1468 test_expect_success 'git config ignores pairs exceeding count' '
1469 GIT_CONFIG_COUNT=1 \
1470 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1471 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1472 git config --get-regexp "pair.*" >actual &&
1473 cat >expect <<-EOF &&
1474 pair.one value
1476 test_cmp expect actual
1479 test_expect_success 'git config ignores pairs with zero count' '
1480 test_must_fail env \
1481 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1482 git config pair.one >error &&
1483 test_must_be_empty error
1486 test_expect_success 'git config ignores pairs with empty count' '
1487 test_must_fail env \
1488 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1489 git config pair.one >error &&
1490 test_must_be_empty error
1493 test_expect_success 'git config fails with invalid count' '
1494 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1495 test_i18ngrep "bogus count" error &&
1496 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1497 test_i18ngrep "too many entries" error
1500 test_expect_success 'git config fails with missing config key' '
1501 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1502 git config --list 2>error &&
1503 test_i18ngrep "missing config key" error
1506 test_expect_success 'git config fails with missing config value' '
1507 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1508 git config --list 2>error &&
1509 test_i18ngrep "missing config value" error
1512 test_expect_success 'git config fails with invalid config pair key' '
1513 test_must_fail env GIT_CONFIG_COUNT=1 \
1514 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1515 git config --list &&
1516 test_must_fail env GIT_CONFIG_COUNT=1 \
1517 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1518 git config --list
1521 test_expect_success 'environment overrides config file' '
1522 test_when_finished "rm -f .git/config" &&
1523 cat >.git/config <<-EOF &&
1524 [pair]
1525 one = value
1527 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1528 git config pair.one >actual &&
1529 cat >expect <<-EOF &&
1530 override
1532 test_cmp expect actual
1535 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1536 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1537 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1538 git config pair.one >actual &&
1539 cat >expect <<-EOF &&
1540 override
1542 test_cmp expect actual
1545 test_expect_success 'command line overrides environment config' '
1546 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1547 git -c pair.one=override config pair.one >actual &&
1548 cat >expect <<-EOF &&
1549 override
1551 test_cmp expect actual
1554 test_expect_success 'git config --edit works' '
1555 git config -f tmp test.value no &&
1556 echo test.value=yes >expect &&
1557 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1558 git config -f tmp --list >actual &&
1559 test_cmp expect actual
1562 test_expect_success 'git config --edit respects core.editor' '
1563 git config -f tmp test.value no &&
1564 echo test.value=yes >expect &&
1565 test_config core.editor "echo [test]value=yes >" &&
1566 git config -f tmp --edit &&
1567 git config -f tmp --list >actual &&
1568 test_cmp expect actual
1571 # malformed configuration files
1572 test_expect_success 'barf on syntax error' '
1573 cat >.git/config <<-\EOF &&
1574 # broken section line
1575 [section]
1576 key garbage
1578 test_must_fail git config --get section.key >actual 2>error &&
1579 test_i18ngrep " line 3 " error
1582 test_expect_success 'barf on incomplete section header' '
1583 cat >.git/config <<-\EOF &&
1584 # broken section line
1585 [section
1586 key = value
1588 test_must_fail git config --get section.key >actual 2>error &&
1589 test_i18ngrep " line 2 " error
1592 test_expect_success 'barf on incomplete string' '
1593 cat >.git/config <<-\EOF &&
1594 # broken section line
1595 [section]
1596 key = "value string
1598 test_must_fail git config --get section.key >actual 2>error &&
1599 test_i18ngrep " line 3 " error
1602 test_expect_success 'urlmatch' '
1603 cat >.git/config <<-\EOF &&
1604 [http]
1605 sslVerify
1606 [http "https://weak.example.com"]
1607 sslVerify = false
1608 cookieFile = /tmp/cookie.txt
1611 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1612 test_must_be_empty actual &&
1614 echo true >expect &&
1615 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1616 test_cmp expect actual &&
1618 echo false >expect &&
1619 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1620 test_cmp expect actual &&
1623 echo http.cookiefile /tmp/cookie.txt &&
1624 echo http.sslverify false
1625 } >expect &&
1626 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1627 test_cmp expect actual
1630 test_expect_success 'urlmatch favors more specific URLs' '
1631 cat >.git/config <<-\EOF &&
1632 [http "https://example.com/"]
1633 cookieFile = /tmp/root.txt
1634 [http "https://example.com/subdirectory"]
1635 cookieFile = /tmp/subdirectory.txt
1636 [http "https://user@example.com/"]
1637 cookieFile = /tmp/user.txt
1638 [http "https://averylonguser@example.com/"]
1639 cookieFile = /tmp/averylonguser.txt
1640 [http "https://preceding.example.com"]
1641 cookieFile = /tmp/preceding.txt
1642 [http "https://*.example.com"]
1643 cookieFile = /tmp/wildcard.txt
1644 [http "https://*.example.com/wildcardwithsubdomain"]
1645 cookieFile = /tmp/wildcardwithsubdomain.txt
1646 [http "https://*.example.*"]
1647 cookieFile = /tmp/multiwildcard.txt
1648 [http "https://trailing.example.com"]
1649 cookieFile = /tmp/trailing.txt
1650 [http "https://user@*.example.com/"]
1651 cookieFile = /tmp/wildcardwithuser.txt
1652 [http "https://sub.example.com/"]
1653 cookieFile = /tmp/sub.txt
1656 echo http.cookiefile /tmp/root.txt >expect &&
1657 git config --get-urlmatch HTTP https://example.com >actual &&
1658 test_cmp expect actual &&
1660 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1661 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1662 test_cmp expect actual &&
1664 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1665 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1666 test_cmp expect actual &&
1668 echo http.cookiefile /tmp/user.txt >expect &&
1669 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1670 test_cmp expect actual &&
1672 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1673 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1674 test_cmp expect actual &&
1676 echo http.cookiefile /tmp/preceding.txt >expect &&
1677 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1678 test_cmp expect actual &&
1680 echo http.cookiefile /tmp/wildcard.txt >expect &&
1681 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1682 test_cmp expect actual &&
1684 echo http.cookiefile /tmp/sub.txt >expect &&
1685 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1686 test_cmp expect actual &&
1688 echo http.cookiefile /tmp/trailing.txt >expect &&
1689 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1690 test_cmp expect actual &&
1692 echo http.cookiefile /tmp/sub.txt >expect &&
1693 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1694 test_cmp expect actual &&
1696 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1697 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1698 test_cmp expect actual
1701 test_expect_success 'urlmatch with wildcard' '
1702 cat >.git/config <<-\EOF &&
1703 [http]
1704 sslVerify
1705 [http "https://*.example.com"]
1706 sslVerify = false
1707 cookieFile = /tmp/cookie.txt
1710 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1711 test_must_be_empty actual &&
1713 echo true >expect &&
1714 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1715 test_cmp expect actual &&
1717 echo true >expect &&
1718 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1719 test_cmp expect actual &&
1721 echo true >expect &&
1722 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1723 test_cmp expect actual &&
1725 echo false >expect &&
1726 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1727 test_cmp expect actual &&
1730 echo http.cookiefile /tmp/cookie.txt &&
1731 echo http.sslverify false
1732 } >expect &&
1733 git config --get-urlmatch HTTP https://good.example.com >actual &&
1734 test_cmp expect actual &&
1736 echo http.sslverify >expect &&
1737 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1738 test_cmp expect actual
1741 # good section hygiene
1742 test_expect_success '--unset last key removes section (except if commented)' '
1743 cat >.git/config <<-\EOF &&
1744 # some generic comment on the configuration file itself
1745 # a comment specific to this "section" section.
1746 [section]
1747 # some intervening lines
1748 # that should also be dropped
1750 key = value
1751 # please be careful when you update the above variable
1754 cat >expect <<-\EOF &&
1755 # some generic comment on the configuration file itself
1756 # a comment specific to this "section" section.
1757 [section]
1758 # some intervening lines
1759 # that should also be dropped
1761 # please be careful when you update the above variable
1764 git config --unset section.key &&
1765 test_cmp expect .git/config &&
1767 cat >.git/config <<-\EOF &&
1768 [section]
1769 key = value
1770 [next-section]
1773 cat >expect <<-\EOF &&
1774 [next-section]
1777 git config --unset section.key &&
1778 test_cmp expect .git/config &&
1780 q_to_tab >.git/config <<-\EOF &&
1781 [one]
1782 Qkey = "multiline \
1783 QQ# with comment"
1784 [two]
1785 key = true
1787 git config --unset two.key &&
1788 ! grep two .git/config &&
1790 q_to_tab >.git/config <<-\EOF &&
1791 [one]
1792 Qkey = "multiline \
1793 QQ# with comment"
1794 [one]
1795 key = true
1797 git config --unset-all one.key &&
1798 test_line_count = 0 .git/config &&
1800 q_to_tab >.git/config <<-\EOF &&
1801 [one]
1802 Qkey = true
1803 Q# a comment not at the start
1804 [two]
1805 Qkey = true
1807 git config --unset two.key &&
1808 grep two .git/config &&
1810 q_to_tab >.git/config <<-\EOF &&
1811 [one]
1812 Qkey = not [two "subsection"]
1813 [two "subsection"]
1814 [two "subsection"]
1815 Qkey = true
1816 [TWO "subsection"]
1817 [one]
1819 git config --unset two.subsection.key &&
1820 test "not [two subsection]" = "$(git config one.key)" &&
1821 test_line_count = 3 .git/config
1824 test_expect_success '--unset-all removes section if empty & uncommented' '
1825 cat >.git/config <<-\EOF &&
1826 [section]
1827 key = value1
1828 key = value2
1831 git config --unset-all section.key &&
1832 test_line_count = 0 .git/config
1835 test_expect_success 'adding a key into an empty section reuses header' '
1836 cat >.git/config <<-\EOF &&
1837 [section]
1840 q_to_tab >expect <<-\EOF &&
1841 [section]
1842 Qkey = value
1845 git config section.key value &&
1846 test_cmp expect .git/config
1849 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1850 chmod 0600 .git/config &&
1851 git config imap.pass Hunter2 &&
1852 perl -e \
1853 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1854 git config --rename-section imap pop &&
1855 perl -e \
1856 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1859 ! test_have_prereq MINGW ||
1860 HOME="$(pwd)" # convert to Windows path
1862 test_expect_success 'set up --show-origin tests' '
1863 INCLUDE_DIR="$HOME/include" &&
1864 mkdir -p "$INCLUDE_DIR" &&
1865 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1866 [user]
1867 absolute = include
1869 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1870 [user]
1871 relative = include
1873 cat >"$HOME"/.gitconfig <<-EOF &&
1874 [user]
1875 global = true
1876 override = global
1877 [include]
1878 path = "$INCLUDE_DIR/absolute.include"
1880 cat >.git/config <<-\EOF
1881 [user]
1882 local = true
1883 override = local
1884 [include]
1885 path = ../include/relative.include
1889 test_expect_success '--show-origin with --list' '
1890 cat >expect <<-EOF &&
1891 file:$HOME/.gitconfig user.global=true
1892 file:$HOME/.gitconfig user.override=global
1893 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1894 file:$INCLUDE_DIR/absolute.include user.absolute=include
1895 file:.git/config user.local=true
1896 file:.git/config user.override=local
1897 file:.git/config include.path=../include/relative.include
1898 file:.git/../include/relative.include user.relative=include
1899 command line: user.environ=true
1900 command line: user.cmdline=true
1902 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1903 git -c user.cmdline=true config --list --show-origin >output &&
1904 test_cmp expect output
1907 test_expect_success '--show-origin with --list --null' '
1908 cat >expect <<-EOF &&
1909 file:$HOME/.gitconfigQuser.global
1910 trueQfile:$HOME/.gitconfigQuser.override
1911 globalQfile:$HOME/.gitconfigQinclude.path
1912 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1913 includeQfile:.git/configQuser.local
1914 trueQfile:.git/configQuser.override
1915 localQfile:.git/configQinclude.path
1916 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1917 includeQcommand line:Quser.cmdline
1918 trueQ
1920 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1921 nul_to_q <output.raw >output &&
1922 # The here-doc above adds a newline that the --null output would not
1923 # include. Add it here to make the two comparable.
1924 echo >>output &&
1925 test_cmp expect output
1928 test_expect_success '--show-origin with single file' '
1929 cat >expect <<-\EOF &&
1930 file:.git/config user.local=true
1931 file:.git/config user.override=local
1932 file:.git/config include.path=../include/relative.include
1934 git config --local --list --show-origin >output &&
1935 test_cmp expect output
1938 test_expect_success '--show-origin with --get-regexp' '
1939 cat >expect <<-EOF &&
1940 file:$HOME/.gitconfig user.global true
1941 file:.git/config user.local true
1943 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1944 test_cmp expect output
1947 test_expect_success '--show-origin getting a single key' '
1948 cat >expect <<-\EOF &&
1949 file:.git/config local
1951 git config --show-origin user.override >output &&
1952 test_cmp expect output
1955 test_expect_success 'set up custom config file' '
1956 CUSTOM_CONFIG_FILE="custom.conf" &&
1957 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1958 [user]
1959 custom = true
1963 test_expect_success !MINGW 'set up custom config file with special name characters' '
1964 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
1965 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
1968 test_expect_success !MINGW '--show-origin escape special file name characters' '
1969 cat >expect <<-\EOF &&
1970 file:"file\" (dq) and spaces.conf" user.custom=true
1972 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
1973 test_cmp expect output
1976 test_expect_success '--show-origin stdin' '
1977 cat >expect <<-\EOF &&
1978 standard input: user.custom=true
1980 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1981 test_cmp expect output
1984 test_expect_success '--show-origin stdin with file include' '
1985 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1986 [user]
1987 stdin = include
1989 cat >expect <<-EOF &&
1990 file:$INCLUDE_DIR/stdin.include include
1992 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
1993 git config --show-origin --includes --file - user.stdin >output &&
1995 test_cmp expect output
1998 test_expect_success '--show-origin blob' '
1999 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2000 cat >expect <<-EOF &&
2001 blob:$blob user.custom=true
2003 git config --blob=$blob --show-origin --list >output &&
2004 test_cmp expect output
2007 test_expect_success '--show-origin blob ref' '
2008 cat >expect <<-\EOF &&
2009 blob:main:custom.conf user.custom=true
2011 git add "$CUSTOM_CONFIG_FILE" &&
2012 git commit -m "new config file" &&
2013 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2014 test_cmp expect output
2017 test_expect_success '--show-scope with --list' '
2018 cat >expect <<-EOF &&
2019 global user.global=true
2020 global user.override=global
2021 global include.path=$INCLUDE_DIR/absolute.include
2022 global user.absolute=include
2023 local user.local=true
2024 local user.override=local
2025 local include.path=../include/relative.include
2026 local user.relative=include
2027 local core.repositoryformatversion=1
2028 local extensions.worktreeconfig=true
2029 worktree user.worktree=true
2030 command user.cmdline=true
2032 git worktree add wt1 &&
2033 # We need these to test for worktree scope, but outside of this
2034 # test, this is just noise
2035 test_config core.repositoryformatversion 1 &&
2036 test_config extensions.worktreeConfig true &&
2037 git config --worktree user.worktree true &&
2038 git -c user.cmdline=true config --list --show-scope >output &&
2039 test_cmp expect output
2042 test_expect_success !MINGW '--show-scope with --blob' '
2043 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2044 cat >expect <<-EOF &&
2045 command user.custom=true
2047 git config --blob=$blob --show-scope --list >output &&
2048 test_cmp expect output
2051 test_expect_success '--show-scope with --local' '
2052 cat >expect <<-\EOF &&
2053 local user.local=true
2054 local user.override=local
2055 local include.path=../include/relative.include
2057 git config --local --list --show-scope >output &&
2058 test_cmp expect output
2061 test_expect_success '--show-scope getting a single value' '
2062 cat >expect <<-\EOF &&
2063 local true
2065 git config --show-scope --get user.local >output &&
2066 test_cmp expect output
2069 test_expect_success '--show-scope with --show-origin' '
2070 cat >expect <<-EOF &&
2071 global file:$HOME/.gitconfig user.global=true
2072 global file:$HOME/.gitconfig user.override=global
2073 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2074 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2075 local file:.git/config user.local=true
2076 local file:.git/config user.override=local
2077 local file:.git/config include.path=../include/relative.include
2078 local file:.git/../include/relative.include user.relative=include
2079 command command line: user.cmdline=true
2081 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2082 test_cmp expect output
2085 test_expect_success 'override global and system config' '
2086 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2087 cat >"$HOME"/.gitconfig <<-EOF &&
2088 [home]
2089 config = true
2092 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2093 mkdir -p "$HOME"/.config/git &&
2094 cat >"$HOME"/.config/git/config <<-EOF &&
2095 [xdg]
2096 config = true
2098 cat >.git/config <<-EOF &&
2099 [local]
2100 config = true
2102 cat >custom-global-config <<-EOF &&
2103 [global]
2104 config = true
2106 cat >custom-system-config <<-EOF &&
2107 [system]
2108 config = true
2111 cat >expect <<-EOF &&
2112 global xdg.config=true
2113 global home.config=true
2114 local local.config=true
2116 git config --show-scope --list >output &&
2117 test_cmp expect output &&
2119 cat >expect <<-EOF &&
2120 system system.config=true
2121 global global.config=true
2122 local local.config=true
2124 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2125 git config --show-scope --list >output &&
2126 test_cmp expect output &&
2128 cat >expect <<-EOF &&
2129 local local.config=true
2131 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2132 git config --show-scope --list >output &&
2133 test_cmp expect output
2136 test_expect_success 'override global and system config with missing file' '
2137 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2138 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2139 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2142 test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2143 # `git config --system` has different semantics compared to other
2144 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2145 # variable has an effect via a different proxy.
2146 cat >alias-config <<-EOF &&
2147 [alias]
2148 hello-world = !echo "hello world"
2150 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2151 git hello-world &&
2152 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2153 git hello-world >actual &&
2154 echo "hello world" >expect &&
2155 test_cmp expect actual
2158 test_expect_success 'write to overridden global and system config' '
2159 cat >expect <<EOF &&
2160 [config]
2161 key = value
2164 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2165 test_cmp expect write-to-global &&
2167 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2168 test_cmp expect write-to-system
2171 for opt in --local --worktree
2173 test_expect_success "$opt requires a repo" '
2174 # we expect 128 to ensure that we do not simply
2175 # fail to find anything and return code "1"
2176 test_expect_code 128 nongit git config $opt foo.bar
2178 done
2180 cat >.git/config <<-\EOF &&
2181 [section]
2182 foo = true
2183 number = 10
2184 big = 1M
2187 test_expect_success 'identical modern --type specifiers are allowed' '
2188 test_cmp_config 1048576 --type=int --type=int section.big
2191 test_expect_success 'identical legacy --type specifiers are allowed' '
2192 test_cmp_config 1048576 --int --int section.big
2195 test_expect_success 'identical mixed --type specifiers are allowed' '
2196 test_cmp_config 1048576 --int --type=int section.big
2199 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2200 test_must_fail git config --type=int --type=bool section.big 2>error &&
2201 test_i18ngrep "only one type at a time" error
2204 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2205 test_must_fail git config --int --bool section.big 2>error &&
2206 test_i18ngrep "only one type at a time" error
2209 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2210 test_must_fail git config --type=int --bool section.big 2>error &&
2211 test_i18ngrep "only one type at a time" error
2214 test_expect_success '--type allows valid type specifiers' '
2215 test_cmp_config true --type=bool section.foo
2218 test_expect_success '--no-type unsets type specifiers' '
2219 test_cmp_config 10 --type=bool --no-type section.number
2222 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2223 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2226 test_expect_success '--type rejects unknown specifiers' '
2227 test_must_fail git config --type=nonsense section.foo 2>error &&
2228 test_i18ngrep "unrecognized --type argument" error
2231 test_expect_success '--type=int requires at least one digit' '
2232 test_must_fail git config --type int --default m some.key >out 2>error &&
2233 grep "bad numeric config value" error &&
2234 test_must_be_empty out
2237 test_expect_success '--replace-all does not invent newlines' '
2238 q_to_tab >.git/config <<-\EOF &&
2239 [abc]key
2240 QkeepSection
2241 [xyz]
2242 Qkey = 1
2243 [abc]
2244 Qkey = a
2246 q_to_tab >expect <<-\EOF &&
2247 [abc]
2248 QkeepSection
2249 [xyz]
2250 Qkey = 1
2251 [abc]
2252 Qkey = b
2254 git config --replace-all abc.key b &&
2255 test_cmp expect .git/config
2258 test_expect_success 'set all config with value-pattern' '
2259 test_when_finished rm -f config initial &&
2260 git config --file=initial abc.key one &&
2262 # no match => add new entry
2263 cp initial config &&
2264 git config --file=config abc.key two a+ &&
2265 git config --file=config --list >actual &&
2266 cat >expect <<-\EOF &&
2267 abc.key=one
2268 abc.key=two
2270 test_cmp expect actual &&
2272 # multiple matches => failure
2273 test_must_fail git config --file=config abc.key three o+ 2>err &&
2274 test_i18ngrep "has multiple values" err &&
2276 # multiple values, no match => add
2277 git config --file=config abc.key three a+ &&
2278 git config --file=config --list >actual &&
2279 cat >expect <<-\EOF &&
2280 abc.key=one
2281 abc.key=two
2282 abc.key=three
2284 test_cmp expect actual &&
2286 # single match => replace
2287 git config --file=config abc.key four h+ &&
2288 git config --file=config --list >actual &&
2289 cat >expect <<-\EOF &&
2290 abc.key=one
2291 abc.key=two
2292 abc.key=four
2294 test_cmp expect actual
2297 test_expect_success '--replace-all and value-pattern' '
2298 test_when_finished rm -f config &&
2299 git config --file=config --add abc.key one &&
2300 git config --file=config --add abc.key two &&
2301 git config --file=config --add abc.key three &&
2302 git config --file=config --replace-all abc.key four "o+" &&
2303 git config --file=config --list >actual &&
2304 cat >expect <<-\EOF &&
2305 abc.key=four
2306 abc.key=three
2308 test_cmp expect actual
2311 test_expect_success 'refuse --fixed-value for incompatible actions' '
2312 test_when_finished rm -f config &&
2313 git config --file=config dev.null bogus &&
2315 # These modes do not allow --fixed-value at all
2316 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2317 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2318 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2319 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2320 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2321 test_must_fail git config --file=config --fixed-value --list &&
2322 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2323 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2325 # These modes complain when --fixed-value has no value-pattern
2326 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2327 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2328 test_must_fail git config --file=config --fixed-value --get dev.null &&
2329 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2330 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2331 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2332 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2335 test_expect_success '--fixed-value uses exact string matching' '
2336 test_when_finished rm -f config initial &&
2337 META="a+b*c?d[e]f.g" &&
2338 git config --file=initial fixed.test "$META" &&
2340 cp initial config &&
2341 git config --file=config fixed.test bogus "$META" &&
2342 git config --file=config --list >actual &&
2343 cat >expect <<-EOF &&
2344 fixed.test=$META
2345 fixed.test=bogus
2347 test_cmp expect actual &&
2349 cp initial config &&
2350 git config --file=config --fixed-value fixed.test bogus "$META" &&
2351 git config --file=config --list >actual &&
2352 cat >expect <<-\EOF &&
2353 fixed.test=bogus
2355 test_cmp expect actual &&
2357 cp initial config &&
2358 test_must_fail git config --file=config --unset fixed.test "$META" &&
2359 git config --file=config --fixed-value --unset fixed.test "$META" &&
2360 test_must_fail git config --file=config fixed.test &&
2362 cp initial config &&
2363 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2364 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2365 test_must_fail git config --file=config fixed.test &&
2367 cp initial config &&
2368 git config --file=config --replace-all fixed.test bogus "$META" &&
2369 git config --file=config --list >actual &&
2370 cat >expect <<-EOF &&
2371 fixed.test=$META
2372 fixed.test=bogus
2374 test_cmp expect actual &&
2376 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2377 git config --file=config --list >actual &&
2378 cat >expect <<-EOF &&
2379 fixed.test=bogus
2380 fixed.test=bogus
2382 test_cmp expect actual
2385 test_expect_success '--get and --get-all with --fixed-value' '
2386 test_when_finished rm -f config &&
2387 META="a+b*c?d[e]f.g" &&
2388 git config --file=config fixed.test bogus &&
2389 git config --file=config --add fixed.test "$META" &&
2391 git config --file=config --get fixed.test bogus &&
2392 test_must_fail git config --file=config --get fixed.test "$META" &&
2393 git config --file=config --get --fixed-value fixed.test "$META" &&
2394 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2396 git config --file=config --get-all fixed.test bogus &&
2397 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2398 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2399 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2401 git config --file=config --get-regexp fixed+ bogus &&
2402 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2403 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2404 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2407 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2408 git init hasremoteurlTest &&
2409 test_when_finished "rm -rf hasremoteurlTest" &&
2411 cat >include-this <<-\EOF &&
2412 [user]
2413 this = this-is-included
2415 cat >dont-include-that <<-\EOF &&
2416 [user]
2417 that = that-is-not-included
2419 cat >>hasremoteurlTest/.git/config <<-EOF &&
2420 [includeIf "hasconfig:remote.*.url:foourl"]
2421 path = "$(pwd)/include-this"
2422 [includeIf "hasconfig:remote.*.url:barurl"]
2423 path = "$(pwd)/dont-include-that"
2424 [remote "foo"]
2425 url = foourl
2428 echo this-is-included >expect-this &&
2429 git -C hasremoteurlTest config --get user.this >actual-this &&
2430 test_cmp expect-this actual-this &&
2432 test_must_fail git -C hasremoteurlTest config --get user.that
2435 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2436 git init hasremoteurlTest &&
2437 test_when_finished "rm -rf hasremoteurlTest" &&
2439 cat >include-two-three <<-\EOF &&
2440 [user]
2441 two = included-config
2442 three = included-config
2444 cat >>hasremoteurlTest/.git/config <<-EOF &&
2445 [remote "foo"]
2446 url = foourl
2447 [user]
2448 one = main-config
2449 two = main-config
2450 [includeIf "hasconfig:remote.*.url:foourl"]
2451 path = "$(pwd)/include-two-three"
2452 [user]
2453 three = main-config
2456 echo main-config >expect-main-config &&
2457 echo included-config >expect-included-config &&
2459 git -C hasremoteurlTest config --get user.one >actual &&
2460 test_cmp expect-main-config actual &&
2462 git -C hasremoteurlTest config --get user.two >actual &&
2463 test_cmp expect-included-config actual &&
2465 git -C hasremoteurlTest config --get user.three >actual &&
2466 test_cmp expect-main-config actual
2469 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2470 git init hasremoteurlTest &&
2471 test_when_finished "rm -rf hasremoteurlTest" &&
2473 printf "[user]\ndss = yes\n" >double-star-start &&
2474 printf "[user]\ndse = yes\n" >double-star-end &&
2475 printf "[user]\ndsm = yes\n" >double-star-middle &&
2476 printf "[user]\nssm = yes\n" >single-star-middle &&
2477 printf "[user]\nno = no\n" >no &&
2479 cat >>hasremoteurlTest/.git/config <<-EOF &&
2480 [remote "foo"]
2481 url = https://foo/bar/baz
2482 [includeIf "hasconfig:remote.*.url:**/baz"]
2483 path = "$(pwd)/double-star-start"
2484 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2485 path = "$(pwd)/no"
2486 [includeIf "hasconfig:remote.*.url:https:/**"]
2487 path = "$(pwd)/double-star-end"
2488 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2489 path = "$(pwd)/no"
2490 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2491 path = "$(pwd)/double-star-middle"
2492 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2493 path = "$(pwd)/no"
2494 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2495 path = "$(pwd)/single-star-middle"
2496 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2497 path = "$(pwd)/no"
2500 git -C hasremoteurlTest config --get user.dss &&
2501 git -C hasremoteurlTest config --get user.dse &&
2502 git -C hasremoteurlTest config --get user.dsm &&
2503 git -C hasremoteurlTest config --get user.ssm &&
2504 test_must_fail git -C hasremoteurlTest config --get user.no
2507 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2508 git init hasremoteurlTest &&
2509 test_when_finished "rm -rf hasremoteurlTest" &&
2511 cat >include-with-url <<-\EOF &&
2512 [remote "bar"]
2513 url = barurl
2515 cat >>hasremoteurlTest/.git/config <<-EOF &&
2516 [includeIf "hasconfig:remote.*.url:foourl"]
2517 path = "$(pwd)/include-with-url"
2520 # test with any Git command
2521 test_must_fail git -C hasremoteurlTest status 2>err &&
2522 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err
2525 test_done