sequencer: handle multi-byte comment characters when writing todo list
[git.git] / t / t1300-config.sh
blob31c38786870849e7a815f32a08933f059c9c8ffb
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 test_missing_key () {
102 local key="$1" &&
103 local title="$2" &&
104 test_expect_success "value for $title is not printed" '
105 test_must_fail git config "$key" >out 2>err &&
106 test_must_be_empty out &&
107 test_must_be_empty err
111 test_missing_key 'missingsection.missingkey' 'missing section and missing key'
112 test_missing_key 'missingsection.penguin' 'missing section and existing key'
113 test_missing_key 'section.missingkey' 'existing section and missing key'
114 test_missing_key 'section.MissingSubSection.missingkey' 'missing subsection and missing key'
115 test_missing_key 'section.SubSection.missingkey' 'existing subsection and missing key'
116 test_missing_key 'section.MissingSubSection.key' 'missing subsection and existing key'
118 cat > .git/config <<\EOF
119 [alpha]
120 bar = foo
121 [beta]
122 baz = multiple \
123 lines
124 foo = bar
127 test_expect_success 'unset with cont. lines' '
128 git config --unset beta.baz
131 cat > expect <<\EOF
132 [alpha]
133 bar = foo
134 [beta]
135 foo = bar
138 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
140 cat > .git/config << EOF
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
144 # empty line
145 ; comment
146 haha ="beta" # last silly comment
147 haha = hello
148 haha = bello
149 [nextSection] noNewline = ouch
152 cp .git/config .git/config2
154 test_expect_success 'multiple unset' '
155 git config --unset-all beta.haha
158 cat > expect << EOF
159 [beta] ; silly comment # another comment
160 noIndent= sillyValue ; 'nother silly comment
162 # empty line
163 ; comment
164 [nextSection] noNewline = ouch
167 test_expect_success 'multiple unset is correct' '
168 test_cmp expect .git/config
171 cp .git/config2 .git/config
173 test_expect_success '--replace-all missing value' '
174 test_must_fail git config --replace-all beta.haha &&
175 test_cmp .git/config2 .git/config
178 rm .git/config2
180 test_expect_success '--replace-all' '
181 git config --replace-all beta.haha gamma
184 cat > expect << EOF
185 [beta] ; silly comment # another comment
186 noIndent= sillyValue ; 'nother silly comment
188 # empty line
189 ; comment
190 haha = gamma
191 [nextSection] noNewline = ouch
194 test_expect_success 'all replaced' '
195 test_cmp expect .git/config
198 cat > expect << EOF
199 [beta] ; silly comment # another comment
200 noIndent= sillyValue ; 'nother silly comment
202 # empty line
203 ; comment
204 haha = alpha
205 [nextSection] noNewline = ouch
207 test_expect_success 'really mean test' '
208 git config beta.haha alpha &&
209 test_cmp expect .git/config
212 cat > expect << EOF
213 [beta] ; silly comment # another comment
214 noIndent= sillyValue ; 'nother silly comment
216 # empty line
217 ; comment
218 haha = alpha
219 [nextSection]
220 nonewline = wow
222 test_expect_success 'really really mean test' '
223 git config nextsection.nonewline wow &&
224 test_cmp expect .git/config
227 test_expect_success 'get value' '
228 test_cmp_config alpha beta.haha
231 cat > expect << EOF
232 [beta] ; silly comment # another comment
233 noIndent= sillyValue ; 'nother silly comment
235 # empty line
236 ; comment
237 [nextSection]
238 nonewline = wow
240 test_expect_success 'unset' '
241 git config --unset beta.haha &&
242 test_cmp expect .git/config
245 cat > expect << EOF
246 [beta] ; silly comment # another comment
247 noIndent= sillyValue ; 'nother silly comment
249 # empty line
250 ; comment
251 [nextSection]
252 nonewline = wow
253 NoNewLine = wow2 for me
255 test_expect_success 'multivar' '
256 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
257 test_cmp expect .git/config
260 test_expect_success 'non-match' '
261 git config --get nextsection.nonewline !for
264 test_expect_success 'non-match value' '
265 test_cmp_config wow --get nextsection.nonewline !for
268 test_expect_success 'multi-valued get returns final one' '
269 test_cmp_config "wow2 for me" --get nextsection.nonewline
272 test_expect_success 'multi-valued get-all returns all' '
273 cat >expect <<-\EOF &&
275 wow2 for me
277 git config --get-all nextsection.nonewline >actual &&
278 test_cmp expect actual
281 cat > expect << EOF
282 [beta] ; silly comment # another comment
283 noIndent= sillyValue ; 'nother silly comment
285 # empty line
286 ; comment
287 [nextSection]
288 nonewline = wow3
289 NoNewLine = wow2 for me
291 test_expect_success 'multivar replace' '
292 git config nextsection.nonewline "wow3" "wow$" &&
293 test_cmp expect .git/config
296 test_expect_success 'ambiguous unset' '
297 test_must_fail git config --unset nextsection.nonewline
300 test_expect_success 'invalid unset' '
301 test_must_fail git config --unset somesection.nonewline
304 cat > expect << EOF
305 [beta] ; silly comment # another comment
306 noIndent= sillyValue ; 'nother silly comment
308 # empty line
309 ; comment
310 [nextSection]
311 NoNewLine = wow2 for me
314 test_expect_success 'multivar unset' '
315 git config --unset nextsection.nonewline "wow3$" &&
316 test_cmp expect .git/config
319 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
321 test_expect_success 'correct key' 'git config 123456.a123 987'
323 test_expect_success 'hierarchical section' '
324 git config Version.1.2.3eX.Alpha beta
327 cat > expect << EOF
328 [beta] ; silly comment # another comment
329 noIndent= sillyValue ; 'nother silly comment
331 # empty line
332 ; comment
333 [nextSection]
334 NoNewLine = wow2 for me
335 [123456]
336 a123 = 987
337 [Version "1.2.3eX"]
338 Alpha = beta
341 test_expect_success 'hierarchical section value' '
342 test_cmp expect .git/config
345 cat > expect << EOF
346 beta.noindent=sillyValue
347 nextsection.nonewline=wow2 for me
348 123456.a123=987
349 version.1.2.3eX.alpha=beta
352 test_expect_success 'working --list' '
353 git config --list > output &&
354 test_cmp expect output
356 test_expect_success '--list without repo produces empty output' '
357 git --git-dir=nonexistent config --list >output &&
358 test_must_be_empty output
361 cat > expect << EOF
362 beta.noindent
363 nextsection.nonewline
364 123456.a123
365 version.1.2.3eX.alpha
368 test_expect_success '--name-only --list' '
369 git config --name-only --list >output &&
370 test_cmp expect output
373 cat > expect << EOF
374 beta.noindent sillyValue
375 nextsection.nonewline wow2 for me
378 test_expect_success '--get-regexp' '
379 git config --get-regexp in >output &&
380 test_cmp expect output
383 cat > expect << EOF
384 beta.noindent
385 nextsection.nonewline
388 test_expect_success '--name-only --get-regexp' '
389 git config --name-only --get-regexp in >output &&
390 test_cmp expect output
393 cat > expect << EOF
394 wow2 for me
395 wow4 for you
398 test_expect_success '--add' '
399 git config --add nextsection.nonewline "wow4 for you" &&
400 git config --get-all nextsection.nonewline > output &&
401 test_cmp expect output
404 cat > .git/config << EOF
405 [novalue]
406 variable
407 [emptyvalue]
408 variable =
411 test_expect_success 'get variable with no value' '
412 git config --get novalue.variable ^$
415 test_expect_success 'get variable with empty value' '
416 git config --get emptyvalue.variable ^$
419 echo novalue.variable > expect
421 test_expect_success 'get-regexp variable with no value' '
422 git config --get-regexp novalue > output &&
423 test_cmp expect output
426 echo 'novalue.variable true' > expect
428 test_expect_success 'get-regexp --bool variable with no value' '
429 git config --bool --get-regexp novalue > output &&
430 test_cmp expect output
433 echo 'emptyvalue.variable ' > expect
435 test_expect_success 'get-regexp variable with empty value' '
436 git config --get-regexp emptyvalue > output &&
437 test_cmp expect output
440 echo true > expect
442 test_expect_success 'get bool variable with no value' '
443 git config --bool novalue.variable > output &&
444 test_cmp expect output
447 echo false > expect
449 test_expect_success 'get bool variable with empty value' '
450 git config --bool emptyvalue.variable > output &&
451 test_cmp expect output
454 test_expect_success 'no arguments, but no crash' '
455 test_must_fail git config >output 2>&1 &&
456 test_grep usage output
459 cat > .git/config << EOF
460 [a.b]
461 c = d
464 cat > expect << EOF
465 [a.b]
466 c = d
468 x = y
471 test_expect_success 'new section is partial match of another' '
472 git config a.x y &&
473 test_cmp expect .git/config
476 cat > expect << EOF
477 [a.b]
478 c = d
480 x = y
481 b = c
483 x = y
486 test_expect_success 'new variable inserts into proper section' '
487 git config b.x y &&
488 git config a.b c &&
489 test_cmp expect .git/config
492 test_expect_success 'alternative --file (non-existing file should fail)' '
493 test_must_fail git config --file non-existing-config -l &&
494 test_must_fail git config --file non-existing-config test.xyzzy
497 cat > other-config << EOF
498 [ein]
499 bahn = strasse
502 cat > expect << EOF
503 ein.bahn=strasse
506 test_expect_success 'alternative GIT_CONFIG' '
507 GIT_CONFIG=other-config git config --list >output &&
508 test_cmp expect output
511 test_expect_success 'alternative GIT_CONFIG (--file)' '
512 git config --file other-config --list >output &&
513 test_cmp expect output
516 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
517 git config --file - --list <other-config >output &&
518 test_cmp expect output
521 test_expect_success 'setting a value in stdin is an error' '
522 test_must_fail git config --file - some.value foo
525 test_expect_success 'editing stdin is an error' '
526 test_must_fail git config --file - --edit
529 test_expect_success 'refer config from subdirectory' '
530 mkdir x &&
531 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
534 cat > expect << EOF
535 [ein]
536 bahn = strasse
537 [anwohner]
538 park = ausweis
541 test_expect_success '--set in alternative file' '
542 git config --file=other-config anwohner.park ausweis &&
543 test_cmp expect other-config
546 cat > .git/config << EOF
547 # Hallo
548 #Bello
549 [branch "eins"]
550 x = 1
551 [branch.eins]
552 y = 1
553 [branch "1 234 blabl/a"]
554 weird
557 test_expect_success 'rename section' '
558 git config --rename-section branch.eins branch.zwei
561 cat > expect << EOF
562 # Hallo
563 #Bello
564 [branch "zwei"]
565 x = 1
566 [branch "zwei"]
567 y = 1
568 [branch "1 234 blabl/a"]
569 weird
572 test_expect_success 'rename succeeded' '
573 test_cmp expect .git/config
576 test_expect_success 'rename non-existing section' '
577 test_must_fail git config --rename-section \
578 branch."world domination" branch.drei
581 test_expect_success 'rename succeeded' '
582 test_cmp expect .git/config
585 test_expect_success 'rename another section' '
586 git config --rename-section branch."1 234 blabl/a" branch.drei
589 cat > expect << EOF
590 # Hallo
591 #Bello
592 [branch "zwei"]
593 x = 1
594 [branch "zwei"]
595 y = 1
596 [branch "drei"]
597 weird
600 test_expect_success 'rename succeeded' '
601 test_cmp expect .git/config
604 cat >> .git/config << EOF
605 [branch "vier"] z = 1
608 test_expect_success 'rename a section with a var on the same line' '
609 git config --rename-section branch.vier branch.zwei
612 cat > expect << EOF
613 # Hallo
614 #Bello
615 [branch "zwei"]
616 x = 1
617 [branch "zwei"]
618 y = 1
619 [branch "drei"]
620 weird
621 [branch "zwei"]
622 z = 1
625 test_expect_success 'rename succeeded' '
626 test_cmp expect .git/config
629 test_expect_success 'renaming empty section name is rejected' '
630 test_must_fail git config --rename-section branch.zwei ""
633 test_expect_success 'renaming to bogus section is rejected' '
634 test_must_fail git config --rename-section branch.zwei "bogus name"
637 test_expect_success 'renaming a section with a long line' '
639 printf "[b]\\n" &&
640 printf " c = d %1024s [a] e = f\\n" " " &&
641 printf "[a] g = h\\n"
642 } >y &&
643 git config -f y --rename-section a xyz &&
644 test_must_fail git config -f y b.e
647 test_expect_success 'renaming an embedded section with a long line' '
649 printf "[b]\\n" &&
650 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
651 printf "[a] g = h\\n"
652 } >y &&
653 git config -f y --rename-section a xyz &&
654 test_must_fail git config -f y foo.e
657 test_expect_success 'renaming a section with an overly-long line' '
659 printf "[b]\\n" &&
660 printf " c = d %525000s e" " " &&
661 printf "[a] g = h\\n"
662 } >y &&
663 test_must_fail git config -f y --rename-section a xyz 2>err &&
664 grep "refusing to work with overly long line in .y. on line 2" err
667 cat >> .git/config << EOF
668 [branch "zwei"] a = 1 [branch "vier"]
671 test_expect_success 'remove section' '
672 git config --remove-section branch.zwei
675 cat > expect << EOF
676 # Hallo
677 #Bello
678 [branch "drei"]
679 weird
682 test_expect_success 'section was removed properly' '
683 test_cmp expect .git/config
686 cat > expect << EOF
687 [gitcvs]
688 enabled = true
689 dbname = %Ggitcvs2.%a.%m.sqlite
690 [gitcvs "ext"]
691 dbname = %Ggitcvs1.%a.%m.sqlite
694 test_expect_success 'section ending' '
695 rm -f .git/config &&
696 git config gitcvs.enabled true &&
697 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
698 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
699 test_cmp expect .git/config
703 test_expect_success numbers '
704 git config kilo.gram 1k &&
705 git config mega.ton 1m &&
706 echo 1024 >expect &&
707 echo 1048576 >>expect &&
708 git config --int --get kilo.gram >actual &&
709 git config --int --get mega.ton >>actual &&
710 test_cmp expect actual
713 test_expect_success '--int is at least 64 bits' '
714 git config giga.watts 121g &&
715 echo >expect &&
716 test_cmp_config 129922760704 --int --get giga.watts
719 test_expect_success 'invalid unit' '
720 git config aninvalid.unit "1auto" &&
721 test_cmp_config 1auto aninvalid.unit &&
722 test_must_fail git config --int --get aninvalid.unit 2>actual &&
723 test_grep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
726 test_expect_success 'invalid unit boolean' '
727 git config commit.gpgsign "1true" &&
728 test_cmp_config 1true commit.gpgsign &&
729 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
730 test_grep "bad boolean config value .1true. for .commit.gpgsign." actual
733 test_expect_success 'line number is reported correctly' '
734 printf "[bool]\n\tvar\n" >invalid &&
735 test_must_fail git config -f invalid --path bool.var 2>actual &&
736 test_grep "line 2" actual
739 test_expect_success 'invalid stdin config' '
740 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
741 test_grep "bad config line 1 in standard input" output
744 cat > expect << EOF
745 true
746 false
747 true
748 false
749 true
750 false
751 true
752 false
755 test_expect_success bool '
757 git config bool.true1 01 &&
758 git config bool.true2 -1 &&
759 git config bool.true3 YeS &&
760 git config bool.true4 true &&
761 git config bool.false1 000 &&
762 git config bool.false2 "" &&
763 git config bool.false3 nO &&
764 git config bool.false4 FALSE &&
765 rm -f result &&
766 for i in 1 2 3 4
768 git config --bool --get bool.true$i >>result &&
769 git config --bool --get bool.false$i >>result || return 1
770 done &&
771 test_cmp expect result'
773 test_expect_success 'invalid bool (--get)' '
775 git config bool.nobool foobar &&
776 test_must_fail git config --bool --get bool.nobool'
778 test_expect_success 'invalid bool (set)' '
780 test_must_fail git config --bool bool.nobool foobar'
782 cat > expect <<\EOF
783 [bool]
784 true1 = true
785 true2 = true
786 true3 = true
787 true4 = true
788 false1 = false
789 false2 = false
790 false3 = false
791 false4 = false
794 test_expect_success 'set --bool' '
796 rm -f .git/config &&
797 git config --bool bool.true1 01 &&
798 git config --bool bool.true2 -1 &&
799 git config --bool bool.true3 YeS &&
800 git config --bool bool.true4 true &&
801 git config --bool bool.false1 000 &&
802 git config --bool bool.false2 "" &&
803 git config --bool bool.false3 nO &&
804 git config --bool bool.false4 FALSE &&
805 test_cmp expect .git/config'
807 cat > expect <<\EOF
808 [int]
809 val1 = 1
810 val2 = -1
811 val3 = 5242880
814 test_expect_success 'set --int' '
816 rm -f .git/config &&
817 git config --int int.val1 01 &&
818 git config --int int.val2 -1 &&
819 git config --int int.val3 5m &&
820 test_cmp expect .git/config
823 test_expect_success 'get --bool-or-int' '
824 cat >.git/config <<-\EOF &&
825 [bool]
826 true1
827 true2 = true
828 false = false
829 [int]
830 int1 = 0
831 int2 = 1
832 int3 = -1
834 cat >expect <<-\EOF &&
835 true
836 true
837 false
843 git config --bool-or-int bool.true1 &&
844 git config --bool-or-int bool.true2 &&
845 git config --bool-or-int bool.false &&
846 git config --bool-or-int int.int1 &&
847 git config --bool-or-int int.int2 &&
848 git config --bool-or-int int.int3
849 } >actual &&
850 test_cmp expect actual
853 cat >expect <<\EOF
854 [bool]
855 true1 = true
856 false1 = false
857 true2 = true
858 false2 = false
859 [int]
860 int1 = 0
861 int2 = 1
862 int3 = -1
865 test_expect_success 'set --bool-or-int' '
866 rm -f .git/config &&
867 git config --bool-or-int bool.true1 true &&
868 git config --bool-or-int bool.false1 false &&
869 git config --bool-or-int bool.true2 yes &&
870 git config --bool-or-int bool.false2 no &&
871 git config --bool-or-int int.int1 0 &&
872 git config --bool-or-int int.int2 1 &&
873 git config --bool-or-int int.int3 -1 &&
874 test_cmp expect .git/config
877 cat >expect <<\EOF
878 [path]
879 home = ~/
880 normal = /dev/null
881 trailingtilde = foo~
884 test_expect_success !MINGW 'set --path' '
885 rm -f .git/config &&
886 git config --path path.home "~/" &&
887 git config --path path.normal "/dev/null" &&
888 git config --path path.trailingtilde "foo~" &&
889 test_cmp expect .git/config'
891 if test_have_prereq !MINGW && test "${HOME+set}"
892 then
893 test_set_prereq HOMEVAR
896 cat >expect <<EOF
897 $HOME/
898 /dev/null
899 foo~
902 test_expect_success HOMEVAR 'get --path' '
903 git config --get --path path.home > result &&
904 git config --get --path path.normal >> result &&
905 git config --get --path path.trailingtilde >> result &&
906 test_cmp expect result
909 cat >expect <<\EOF
910 /dev/null
911 foo~
914 test_expect_success !MINGW 'get --path copes with unset $HOME' '
916 sane_unset HOME &&
917 test_must_fail git config --get --path path.home \
918 >result 2>msg &&
919 git config --get --path path.normal >>result &&
920 git config --get --path path.trailingtilde >>result
921 ) &&
922 test_grep "[Ff]ailed to expand.*~/" msg &&
923 test_cmp expect result
926 test_expect_success 'get --path barfs on boolean variable' '
927 echo "[path]bool" >.git/config &&
928 test_must_fail git config --get --path path.bool
931 test_expect_success 'get --expiry-date' '
932 rel="3.weeks.5.days.00:00" &&
933 rel_out="$rel ->" &&
934 cat >.git/config <<-\EOF &&
935 [date]
936 valid1 = "3.weeks.5.days 00:00"
937 valid2 = "Fri Jun 4 15:46:55 2010"
938 valid3 = "2017/11/11 11:11:11PM"
939 valid4 = "2017/11/10 09:08:07 PM"
940 valid5 = "never"
941 invalid1 = "abc"
943 cat >expect <<-EOF &&
944 $(test-tool date timestamp $rel)
945 1275666415
946 1510441871
947 1510348087
950 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
952 echo "$rel_out $(git config --expiry-date date.valid1)" &&
953 git config --expiry-date date.valid2 &&
954 git config --expiry-date date.valid3 &&
955 git config --expiry-date date.valid4 &&
956 git config --expiry-date date.valid5
957 } >actual &&
958 test_cmp expect actual &&
959 test_must_fail git config --expiry-date date.invalid1
962 test_expect_success 'get --type=color' '
963 rm .git/config &&
964 git config foo.color "red" &&
965 git config --get --type=color foo.color >actual.raw &&
966 test_decode_color <actual.raw >actual &&
967 echo "<RED>" >expect &&
968 test_cmp expect actual
971 cat >expect << EOF
972 [foo]
973 color = red
976 test_expect_success 'set --type=color' '
977 rm .git/config &&
978 git config --type=color foo.color "red" &&
979 test_cmp expect .git/config
982 test_expect_success 'get --type=color barfs on non-color' '
983 echo "[foo]bar=not-a-color" >.git/config &&
984 test_must_fail git config --get --type=color foo.bar
987 test_expect_success 'set --type=color barfs on non-color' '
988 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
989 test_grep "cannot parse color" error
992 cat > expect << EOF
993 [quote]
994 leading = " test"
995 ending = "test "
996 semicolon = "test;test"
997 hash = "test#test"
999 test_expect_success 'quoting' '
1000 rm -f .git/config &&
1001 git config quote.leading " test" &&
1002 git config quote.ending "test " &&
1003 git config quote.semicolon "test;test" &&
1004 git config quote.hash "test#test" &&
1005 test_cmp expect .git/config
1008 test_expect_success 'key with newline' '
1009 test_must_fail git config "key.with
1010 newline" 123'
1012 test_expect_success 'value with newline' 'git config key.sub value.with\\\
1013 newline'
1015 cat > .git/config <<\EOF
1016 [section]
1017 ; comment \
1018 continued = cont\
1019 inued
1020 noncont = not continued ; \
1021 quotecont = "cont;\
1022 inued"
1025 cat > expect <<\EOF
1026 section.continued=continued
1027 section.noncont=not continued
1028 section.quotecont=cont;inued
1031 test_expect_success 'value continued on next line' '
1032 git config --list > result &&
1033 test_cmp expect result
1036 cat > .git/config <<\EOF
1037 [section "sub=section"]
1038 val1 = foo=bar
1039 val2 = foo\nbar
1040 val3 = \n\n
1041 val4 =
1042 val5
1045 cat > expect <<\EOF
1046 section.sub=section.val1
1047 foo=barQsection.sub=section.val2
1049 barQsection.sub=section.val3
1052 Qsection.sub=section.val4
1053 Qsection.sub=section.val5Q
1055 test_expect_success '--null --list' '
1056 git config --null --list >result.raw &&
1057 nul_to_q <result.raw >result &&
1058 echo >>result &&
1059 test_cmp expect result
1062 test_expect_success '--null --get-regexp' '
1063 git config --null --get-regexp "val[0-9]" >result.raw &&
1064 nul_to_q <result.raw >result &&
1065 echo >>result &&
1066 test_cmp expect result
1069 test_expect_success 'inner whitespace kept verbatim' '
1070 git config section.val "foo bar" &&
1071 test_cmp_config "foo bar" section.val
1074 test_expect_success SYMLINKS 'symlinked configuration' '
1075 ln -s notyet myconfig &&
1076 git config --file=myconfig test.frotz nitfol &&
1077 test -h myconfig &&
1078 test -f notyet &&
1079 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1080 git config --file=myconfig test.xyzzy rezrov &&
1081 test -h myconfig &&
1082 test -f notyet &&
1083 cat >expect <<-\EOF &&
1084 nitfol
1085 rezrov
1088 git config --file=notyet test.frotz &&
1089 git config --file=notyet test.xyzzy
1090 } >actual &&
1091 test_cmp expect actual
1094 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1095 ln -s doesnotexist linktonada &&
1096 ln -s linktonada linktolinktonada &&
1097 test_must_fail git config --file=linktonada --list &&
1098 test_must_fail git config --file=linktolinktonada --list
1101 test_expect_success 'check split_cmdline return' '
1102 test_when_finished "rm -rf repo" &&
1103 git init repo &&
1105 cd repo &&
1106 git config alias.split-cmdline-fix "echo \"" &&
1107 test_must_fail git split-cmdline-fix &&
1108 echo foo >foo &&
1109 git add foo &&
1110 git commit -m "initial commit" &&
1111 git config branch.main.mergeoptions "echo \"" &&
1112 test_must_fail git merge main
1116 test_expect_success 'git -c "key=value" support' '
1117 cat >expect <<-\EOF &&
1118 value
1119 value
1120 true
1123 git -c section.name=value config section.name &&
1124 git -c foo.CamelCase=value config foo.camelcase &&
1125 git -c foo.flag config --bool foo.flag
1126 } >actual &&
1127 test_cmp expect actual &&
1128 test_must_fail git -c name=value config section.name
1131 # We just need a type-specifier here that cares about the
1132 # distinction internally between a NULL boolean and a real
1133 # string (because most of git's internal parsers do care).
1134 # Using "--path" works, but we do not otherwise care about
1135 # its semantics.
1136 test_expect_success 'git -c can represent empty string' '
1137 echo >expect &&
1138 git -c foo.empty= config --path foo.empty >actual &&
1139 test_cmp expect actual
1142 test_expect_success 'key sanity-checking' '
1143 test_must_fail git config foo=bar &&
1144 test_must_fail git config foo=.bar &&
1145 test_must_fail git config foo.ba=r &&
1146 test_must_fail git config foo.1bar &&
1147 test_must_fail git config foo."ba
1148 z".bar &&
1149 test_must_fail git config . false &&
1150 test_must_fail git config .foo false &&
1151 test_must_fail git config foo. false &&
1152 test_must_fail git config .foo. false &&
1153 git config foo.bar true &&
1154 git config foo."ba =z".bar false
1157 test_expect_success 'git -c works with aliases of builtins' '
1158 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1159 echo bar >expect &&
1160 git checkconfig >actual &&
1161 test_cmp expect actual
1164 test_expect_success 'aliases can be CamelCased' '
1165 test_when_finished "rm -rf repo" &&
1166 git init repo &&
1168 cd repo &&
1169 test_commit A &&
1170 git config alias.CamelCased "rev-parse HEAD" &&
1171 git CamelCased >out &&
1172 git rev-parse HEAD >expect &&
1173 test_cmp expect out
1177 test_expect_success 'git -c does not split values on equals' '
1178 echo "value with = in it" >expect &&
1179 git -c section.foo="value with = in it" config section.foo >actual &&
1180 test_cmp expect actual
1183 test_expect_success 'git -c dies on bogus config' '
1184 test_must_fail git -c core.bare=foo rev-parse
1187 test_expect_success 'git -c complains about empty key' '
1188 test_must_fail git -c "=foo" rev-parse
1191 test_expect_success 'git -c complains about empty key and value' '
1192 test_must_fail git -c "" rev-parse
1195 test_expect_success 'multiple git -c appends config' '
1196 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1197 cat >expect <<-\EOF &&
1198 x.one 1
1199 x.two 2
1201 git -c x.one=1 x >actual &&
1202 test_cmp expect actual
1205 test_expect_success 'last one wins: two level vars' '
1207 # sec.var and sec.VAR are the same variable, as the first
1208 # and the last level of a configuration variable name is
1209 # case insensitive.
1211 echo VAL >expect &&
1213 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1214 test_cmp expect actual &&
1215 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1216 test_cmp expect actual &&
1218 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1219 test_cmp expect actual &&
1220 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1221 test_cmp expect actual
1224 test_expect_success 'last one wins: three level vars' '
1226 # v.a.r and v.A.r are not the same variable, as the middle
1227 # level of a three-level configuration variable name is
1228 # case sensitive.
1230 echo val >expect &&
1231 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1232 test_cmp expect actual &&
1233 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1234 test_cmp expect actual &&
1236 # v.a.r and V.a.R are the same variable, as the first
1237 # and the last level of a configuration variable name is
1238 # case insensitive.
1240 echo VAL >expect &&
1241 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1242 test_cmp expect actual &&
1243 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1244 test_cmp expect actual &&
1245 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1246 test_cmp expect actual &&
1247 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1248 test_cmp expect actual
1251 test_expect_success 'old-fashioned settings are case insensitive' '
1252 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1254 cat >testConfig_actual <<-EOF &&
1255 [V.A]
1256 r = value1
1258 q_to_tab >testConfig_expect <<-EOF &&
1259 [V.A]
1260 Qr = value2
1262 git config -f testConfig_actual "v.a.r" value2 &&
1263 test_cmp testConfig_expect testConfig_actual &&
1265 cat >testConfig_actual <<-EOF &&
1266 [V.A]
1267 r = value1
1269 q_to_tab >testConfig_expect <<-EOF &&
1270 [V.A]
1271 QR = value2
1273 git config -f testConfig_actual "V.a.R" value2 &&
1274 test_cmp testConfig_expect testConfig_actual &&
1276 cat >testConfig_actual <<-EOF &&
1277 [V.A]
1278 r = value1
1280 q_to_tab >testConfig_expect <<-EOF &&
1281 [V.A]
1282 r = value1
1283 Qr = value2
1285 git config -f testConfig_actual "V.A.r" value2 &&
1286 test_cmp testConfig_expect testConfig_actual &&
1288 cat >testConfig_actual <<-EOF &&
1289 [V.A]
1290 r = value1
1292 q_to_tab >testConfig_expect <<-EOF &&
1293 [V.A]
1294 r = value1
1295 Qr = value2
1297 git config -f testConfig_actual "v.A.r" value2 &&
1298 test_cmp testConfig_expect testConfig_actual
1301 test_expect_success 'setting different case sensitive subsections ' '
1302 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1304 cat >testConfig_actual <<-EOF &&
1305 [V "A"]
1306 R = v1
1307 [K "E"]
1308 Y = v1
1309 [a "b"]
1310 c = v1
1311 [d "e"]
1312 f = v1
1314 q_to_tab >testConfig_expect <<-EOF &&
1315 [V "A"]
1316 Qr = v2
1317 [K "E"]
1318 Qy = v2
1319 [a "b"]
1320 Qc = v2
1321 [d "e"]
1322 f = v1
1323 [d "E"]
1324 Qf = v2
1326 # exact match
1327 git config -f testConfig_actual a.b.c v2 &&
1328 # match section and subsection, key is cased differently.
1329 git config -f testConfig_actual K.E.y v2 &&
1330 # section and key are matched case insensitive, but subsection needs
1331 # to match; When writing out new values only the key is adjusted
1332 git config -f testConfig_actual v.A.r v2 &&
1333 # subsection is not matched:
1334 git config -f testConfig_actual d.E.f v2 &&
1335 test_cmp testConfig_expect testConfig_actual
1338 for VAR in a .a a. a.0b a."b c". a."b c".0d
1340 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1341 test_must_fail git -c "$VAR=VAL" config -l
1343 done
1345 for VAR in a.b a."b c".d
1347 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1348 echo VAL >expect &&
1349 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1350 test_cmp expect actual
1352 done
1354 test_expect_success 'git -c is not confused by empty environment' '
1355 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1358 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1359 v="${SQ}key.one=foo${SQ}" &&
1360 v="$v ${SQ}key.two=bar${SQ}" &&
1361 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1362 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1363 cat >expect <<-EOF &&
1364 key.one foo
1365 key.two bar
1366 key.ambiguous section.whatever=value
1368 test_cmp expect actual
1371 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1372 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1373 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1374 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1375 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1376 cat >expect <<-EOF &&
1377 key.one foo
1378 key.two bar
1379 key.ambiguous=section.whatever value
1381 test_cmp expect actual
1384 test_expect_success 'old and new-style entries can mix' '
1385 v="${SQ}key.oldone=oldfoo${SQ}" &&
1386 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1387 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1388 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1389 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1390 cat >expect <<-EOF &&
1391 key.oldone oldfoo
1392 key.newone newfoo
1393 key.oldtwo oldbar
1394 key.newtwo newbar
1396 test_cmp expect actual
1399 test_expect_success 'old and new bools with ambiguous subsection' '
1400 v="${SQ}key.with=equals.oldbool${SQ}" &&
1401 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1402 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1403 cat >expect <<-EOF &&
1404 key.with equals.oldbool
1405 key.with=equals.newbool
1407 test_cmp expect actual
1410 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1411 cat >expect <<-\EOF &&
1412 env.one one
1413 env.two two
1415 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1416 git config --get-regexp "env.*" >actual &&
1417 test_cmp expect actual &&
1419 cat >expect <<-EOF &&
1420 env.one one${SQ}
1421 env.two two
1423 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1424 git config --get-regexp "env.*" >actual &&
1425 test_cmp expect actual &&
1427 test_must_fail env \
1428 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1429 git config --get-regexp "env.*"
1432 test_expect_success 'git --config-env=key=envvar support' '
1433 cat >expect <<-\EOF &&
1434 value
1435 value
1436 value
1437 value
1438 false
1439 false
1442 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1443 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1444 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1445 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1446 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1447 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1448 } >actual &&
1449 test_cmp expect actual
1452 test_expect_success 'git --config-env with missing value' '
1453 test_must_fail env ENVVAR=value git --config-env 2>error &&
1454 grep "no config key given for --config-env" error &&
1455 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1456 grep "invalid config format: config" error
1459 test_expect_success 'git --config-env fails with invalid parameters' '
1460 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1461 test_grep "invalid config format: foo.flag" error &&
1462 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1463 test_grep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1464 sane_unset NONEXISTENT &&
1465 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1466 test_grep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1469 test_expect_success 'git -c and --config-env work together' '
1470 cat >expect <<-\EOF &&
1471 bar.cmd cmd-value
1472 bar.env env-value
1474 ENVVAR=env-value git \
1475 -c bar.cmd=cmd-value \
1476 --config-env=bar.env=ENVVAR \
1477 config --get-regexp "^bar.*" >actual &&
1478 test_cmp expect actual
1481 test_expect_success 'git -c and --config-env override each other' '
1482 cat >expect <<-\EOF &&
1487 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1488 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1489 } >actual &&
1490 test_cmp expect actual
1493 test_expect_success '--config-env handles keys with equals' '
1494 echo value=with=equals >expect &&
1495 ENVVAR=value=with=equals git \
1496 --config-env=section.subsection=with=equals.key=ENVVAR \
1497 config section.subsection=with=equals.key >actual &&
1498 test_cmp expect actual
1501 test_expect_success 'git config handles environment config pairs' '
1502 GIT_CONFIG_COUNT=2 \
1503 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1504 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1505 git config --get-regexp "pair.*" >actual &&
1506 cat >expect <<-EOF &&
1507 pair.one foo
1508 pair.two bar
1510 test_cmp expect actual
1513 test_expect_success 'git config ignores pairs without count' '
1514 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1515 git config pair.one 2>error &&
1516 test_must_be_empty error
1519 test_expect_success 'git config ignores pairs exceeding count' '
1520 GIT_CONFIG_COUNT=1 \
1521 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1522 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1523 git config --get-regexp "pair.*" >actual 2>error &&
1524 cat >expect <<-EOF &&
1525 pair.one value
1527 test_cmp expect actual &&
1528 test_must_be_empty error
1531 test_expect_success 'git config ignores pairs with zero count' '
1532 test_must_fail env \
1533 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1534 git config pair.one 2>error &&
1535 test_must_be_empty error
1538 test_expect_success 'git config ignores pairs with empty count' '
1539 test_must_fail env \
1540 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1541 git config pair.one 2>error &&
1542 test_must_be_empty error
1545 test_expect_success 'git config fails with invalid count' '
1546 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1547 test_grep "bogus count" error &&
1548 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1549 test_grep "too many entries" error
1552 test_expect_success 'git config fails with missing config key' '
1553 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1554 git config --list 2>error &&
1555 test_grep "missing config key" error
1558 test_expect_success 'git config fails with missing config value' '
1559 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1560 git config --list 2>error &&
1561 test_grep "missing config value" error
1564 test_expect_success 'git config fails with invalid config pair key' '
1565 test_must_fail env GIT_CONFIG_COUNT=1 \
1566 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1567 git config --list &&
1568 test_must_fail env GIT_CONFIG_COUNT=1 \
1569 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1570 git config --list
1573 test_expect_success 'environment overrides config file' '
1574 test_when_finished "rm -f .git/config" &&
1575 cat >.git/config <<-EOF &&
1576 [pair]
1577 one = value
1579 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1580 git config pair.one >actual &&
1581 cat >expect <<-EOF &&
1582 override
1584 test_cmp expect actual
1587 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1588 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1589 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1590 git config pair.one >actual &&
1591 cat >expect <<-EOF &&
1592 override
1594 test_cmp expect actual
1597 test_expect_success 'command line overrides environment config' '
1598 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1599 git -c pair.one=override config pair.one >actual &&
1600 cat >expect <<-EOF &&
1601 override
1603 test_cmp expect actual
1606 test_expect_success 'git config --edit works' '
1607 git config -f tmp test.value no &&
1608 echo test.value=yes >expect &&
1609 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1610 git config -f tmp --list >actual &&
1611 test_cmp expect actual
1614 test_expect_success 'git config --edit respects core.editor' '
1615 git config -f tmp test.value no &&
1616 echo test.value=yes >expect &&
1617 test_config core.editor "echo [test]value=yes >" &&
1618 git config -f tmp --edit &&
1619 git config -f tmp --list >actual &&
1620 test_cmp expect actual
1623 # malformed configuration files
1624 test_expect_success 'barf on syntax error' '
1625 cat >.git/config <<-\EOF &&
1626 # broken key=value
1627 [section]
1628 key garbage
1630 test_must_fail git config --get section.key 2>error &&
1631 test_grep " line 3 " error
1634 test_expect_success 'barf on incomplete section header' '
1635 cat >.git/config <<-\EOF &&
1636 # broken section line
1637 [section
1638 key = value
1640 test_must_fail git config --get section.key 2>error &&
1641 test_grep " line 2 " error
1644 test_expect_success 'barf on incomplete string' '
1645 cat >.git/config <<-\EOF &&
1646 # broken value string
1647 [section]
1648 key = "value string
1650 test_must_fail git config --get section.key 2>error &&
1651 test_grep " line 3 " error
1654 test_expect_success 'urlmatch' '
1655 cat >.git/config <<-\EOF &&
1656 [http]
1657 sslVerify
1658 [http "https://weak.example.com"]
1659 sslVerify = false
1660 cookieFile = /tmp/cookie.txt
1663 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1664 test_must_be_empty actual &&
1666 echo true >expect &&
1667 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1668 test_cmp expect actual &&
1670 echo false >expect &&
1671 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1672 test_cmp expect actual &&
1675 echo http.cookiefile /tmp/cookie.txt &&
1676 echo http.sslverify false
1677 } >expect &&
1678 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1679 test_cmp expect actual
1682 test_expect_success 'urlmatch with --show-scope' '
1683 cat >.git/config <<-\EOF &&
1684 [http "https://weak.example.com"]
1685 sslVerify = false
1686 cookieFile = /tmp/cookie.txt
1689 cat >expect <<-EOF &&
1690 local http.cookiefile /tmp/cookie.txt
1691 local http.sslverify false
1693 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1694 test_cmp expect actual
1697 test_expect_success 'urlmatch favors more specific URLs' '
1698 cat >.git/config <<-\EOF &&
1699 [http "https://example.com/"]
1700 cookieFile = /tmp/root.txt
1701 [http "https://example.com/subdirectory"]
1702 cookieFile = /tmp/subdirectory.txt
1703 [http "https://user@example.com/"]
1704 cookieFile = /tmp/user.txt
1705 [http "https://averylonguser@example.com/"]
1706 cookieFile = /tmp/averylonguser.txt
1707 [http "https://preceding.example.com"]
1708 cookieFile = /tmp/preceding.txt
1709 [http "https://*.example.com"]
1710 cookieFile = /tmp/wildcard.txt
1711 [http "https://*.example.com/wildcardwithsubdomain"]
1712 cookieFile = /tmp/wildcardwithsubdomain.txt
1713 [http "https://*.example.*"]
1714 cookieFile = /tmp/multiwildcard.txt
1715 [http "https://trailing.example.com"]
1716 cookieFile = /tmp/trailing.txt
1717 [http "https://user@*.example.com/"]
1718 cookieFile = /tmp/wildcardwithuser.txt
1719 [http "https://sub.example.com/"]
1720 cookieFile = /tmp/sub.txt
1723 echo http.cookiefile /tmp/root.txt >expect &&
1724 git config --get-urlmatch HTTP https://example.com >actual &&
1725 test_cmp expect actual &&
1727 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1728 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1729 test_cmp expect actual &&
1731 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1732 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1733 test_cmp expect actual &&
1735 echo http.cookiefile /tmp/user.txt >expect &&
1736 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1737 test_cmp expect actual &&
1739 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1740 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1741 test_cmp expect actual &&
1743 echo http.cookiefile /tmp/preceding.txt >expect &&
1744 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1745 test_cmp expect actual &&
1747 echo http.cookiefile /tmp/wildcard.txt >expect &&
1748 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1749 test_cmp expect actual &&
1751 echo http.cookiefile /tmp/sub.txt >expect &&
1752 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1753 test_cmp expect actual &&
1755 echo http.cookiefile /tmp/trailing.txt >expect &&
1756 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1757 test_cmp expect actual &&
1759 echo http.cookiefile /tmp/sub.txt >expect &&
1760 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1761 test_cmp expect actual &&
1763 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1764 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1765 test_cmp expect actual
1768 test_expect_success 'urlmatch with wildcard' '
1769 cat >.git/config <<-\EOF &&
1770 [http]
1771 sslVerify
1772 [http "https://*.example.com"]
1773 sslVerify = false
1774 cookieFile = /tmp/cookie.txt
1777 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1778 test_must_be_empty actual &&
1780 echo true >expect &&
1781 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1782 test_cmp expect actual &&
1784 echo true >expect &&
1785 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1786 test_cmp expect actual &&
1788 echo true >expect &&
1789 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1790 test_cmp expect actual &&
1792 echo false >expect &&
1793 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1794 test_cmp expect actual &&
1797 echo http.cookiefile /tmp/cookie.txt &&
1798 echo http.sslverify false
1799 } >expect &&
1800 git config --get-urlmatch HTTP https://good.example.com >actual &&
1801 test_cmp expect actual &&
1803 echo http.sslverify >expect &&
1804 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1805 test_cmp expect actual
1808 # good section hygiene
1809 test_expect_success '--unset last key removes section (except if commented)' '
1810 cat >.git/config <<-\EOF &&
1811 # some generic comment on the configuration file itself
1812 # a comment specific to this "section" section.
1813 [section]
1814 # some intervening lines
1815 # that should also be dropped
1817 key = value
1818 # please be careful when you update the above variable
1821 cat >expect <<-\EOF &&
1822 # some generic comment on the configuration file itself
1823 # a comment specific to this "section" section.
1824 [section]
1825 # some intervening lines
1826 # that should also be dropped
1828 # please be careful when you update the above variable
1831 git config --unset section.key &&
1832 test_cmp expect .git/config &&
1834 cat >.git/config <<-\EOF &&
1835 [section]
1836 key = value
1837 [next-section]
1840 cat >expect <<-\EOF &&
1841 [next-section]
1844 git config --unset section.key &&
1845 test_cmp expect .git/config &&
1847 q_to_tab >.git/config <<-\EOF &&
1848 [one]
1849 Qkey = "multiline \
1850 QQ# with comment"
1851 [two]
1852 key = true
1854 git config --unset two.key &&
1855 ! grep two .git/config &&
1857 q_to_tab >.git/config <<-\EOF &&
1858 [one]
1859 Qkey = "multiline \
1860 QQ# with comment"
1861 [one]
1862 key = true
1864 git config --unset-all one.key &&
1865 test_line_count = 0 .git/config &&
1867 q_to_tab >.git/config <<-\EOF &&
1868 [one]
1869 Qkey = true
1870 Q# a comment not at the start
1871 [two]
1872 Qkey = true
1874 git config --unset two.key &&
1875 grep two .git/config &&
1877 q_to_tab >.git/config <<-\EOF &&
1878 [one]
1879 Qkey = not [two "subsection"]
1880 [two "subsection"]
1881 [two "subsection"]
1882 Qkey = true
1883 [TWO "subsection"]
1884 [one]
1886 git config --unset two.subsection.key &&
1887 test "not [two subsection]" = "$(git config one.key)" &&
1888 test_line_count = 3 .git/config
1891 test_expect_success '--unset-all removes section if empty & uncommented' '
1892 cat >.git/config <<-\EOF &&
1893 [section]
1894 key = value1
1895 key = value2
1898 git config --unset-all section.key &&
1899 test_line_count = 0 .git/config
1902 test_expect_success 'adding a key into an empty section reuses header' '
1903 cat >.git/config <<-\EOF &&
1904 [section]
1907 q_to_tab >expect <<-\EOF &&
1908 [section]
1909 Qkey = value
1912 git config section.key value &&
1913 test_cmp expect .git/config
1916 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1917 chmod 0600 .git/config &&
1918 git config imap.pass Hunter2 &&
1919 perl -e \
1920 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1921 git config --rename-section imap pop &&
1922 perl -e \
1923 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1926 ! test_have_prereq MINGW ||
1927 HOME="$(pwd)" # convert to Windows path
1929 test_expect_success 'set up --show-origin tests' '
1930 INCLUDE_DIR="$HOME/include" &&
1931 mkdir -p "$INCLUDE_DIR" &&
1932 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1933 [user]
1934 absolute = include
1936 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1937 [user]
1938 relative = include
1940 cat >"$HOME"/.gitconfig <<-EOF &&
1941 [user]
1942 global = true
1943 override = global
1944 [include]
1945 path = "$INCLUDE_DIR/absolute.include"
1947 cat >.git/config <<-\EOF
1948 [user]
1949 local = true
1950 override = local
1951 [include]
1952 path = ../include/relative.include
1956 test_expect_success '--show-origin with --list' '
1957 cat >expect <<-EOF &&
1958 file:$HOME/.gitconfig user.global=true
1959 file:$HOME/.gitconfig user.override=global
1960 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1961 file:$INCLUDE_DIR/absolute.include user.absolute=include
1962 file:.git/config user.local=true
1963 file:.git/config user.override=local
1964 file:.git/config include.path=../include/relative.include
1965 file:.git/../include/relative.include user.relative=include
1966 command line: user.environ=true
1967 command line: user.cmdline=true
1969 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1970 git -c user.cmdline=true config --list --show-origin >output &&
1971 test_cmp expect output
1974 test_expect_success '--show-origin with --list --null' '
1975 cat >expect <<-EOF &&
1976 file:$HOME/.gitconfigQuser.global
1977 trueQfile:$HOME/.gitconfigQuser.override
1978 globalQfile:$HOME/.gitconfigQinclude.path
1979 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1980 includeQfile:.git/configQuser.local
1981 trueQfile:.git/configQuser.override
1982 localQfile:.git/configQinclude.path
1983 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1984 includeQcommand line:Quser.cmdline
1985 trueQ
1987 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1988 nul_to_q <output.raw >output &&
1989 # The here-doc above adds a newline that the --null output would not
1990 # include. Add it here to make the two comparable.
1991 echo >>output &&
1992 test_cmp expect output
1995 test_expect_success '--show-origin with single file' '
1996 cat >expect <<-\EOF &&
1997 file:.git/config user.local=true
1998 file:.git/config user.override=local
1999 file:.git/config include.path=../include/relative.include
2001 git config --local --list --show-origin >output &&
2002 test_cmp expect output
2005 test_expect_success '--show-origin with --get-regexp' '
2006 cat >expect <<-EOF &&
2007 file:$HOME/.gitconfig user.global true
2008 file:.git/config user.local true
2010 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
2011 test_cmp expect output
2014 test_expect_success '--show-origin getting a single key' '
2015 cat >expect <<-\EOF &&
2016 file:.git/config local
2018 git config --show-origin user.override >output &&
2019 test_cmp expect output
2022 test_expect_success 'set up custom config file' '
2023 cat >"custom.conf" <<-\EOF &&
2024 [user]
2025 custom = true
2027 CUSTOM_CONFIG_FILE="$(test-tool path-utils real_path custom.conf)"
2030 test_expect_success !MINGW 'set up custom config file with special name characters' '
2031 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2032 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2035 test_expect_success !MINGW '--show-origin escape special file name characters' '
2036 cat >expect <<-\EOF &&
2037 file:"file\" (dq) and spaces.conf" user.custom=true
2039 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2040 test_cmp expect output
2043 test_expect_success '--show-origin stdin' '
2044 cat >expect <<-\EOF &&
2045 standard input: user.custom=true
2047 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2048 test_cmp expect output
2051 test_expect_success '--show-origin stdin with file include' '
2052 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2053 [user]
2054 stdin = include
2056 cat >expect <<-EOF &&
2057 file:$INCLUDE_DIR/stdin.include include
2059 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2060 git config --show-origin --includes --file - user.stdin >output &&
2062 test_cmp expect output
2065 test_expect_success '--show-origin blob' '
2066 test_when_finished "rm -rf repo" &&
2067 git init repo &&
2069 cd repo &&
2070 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2071 cat >expect <<-EOF &&
2072 blob:$blob user.custom=true
2074 git config --blob=$blob --show-origin --list >output &&
2075 test_cmp expect output
2079 test_expect_success '--show-origin blob ref' '
2080 test_when_finished "rm -rf repo" &&
2081 git init repo &&
2083 cd repo &&
2084 cat >expect <<-\EOF &&
2085 blob:main:custom.conf user.custom=true
2087 cp "$CUSTOM_CONFIG_FILE" custom.conf &&
2088 git add custom.conf &&
2089 git commit -m "new config file" &&
2090 git config --blob=main:custom.conf --show-origin --list >output &&
2091 test_cmp expect output
2095 test_expect_success '--show-origin with --default' '
2096 git config --show-origin --default foo some.key >actual &&
2097 echo "command line: foo" >expect &&
2098 test_cmp expect actual
2101 test_expect_success '--show-scope with --list' '
2102 cat >expect <<-EOF &&
2103 global user.global=true
2104 global user.override=global
2105 global include.path=$INCLUDE_DIR/absolute.include
2106 global user.absolute=include
2107 local user.local=true
2108 local user.override=local
2109 local include.path=../include/relative.include
2110 local user.relative=include
2111 local core.repositoryformatversion=1
2112 local extensions.worktreeconfig=true
2113 worktree user.worktree=true
2114 command user.cmdline=true
2116 git worktree add wt1 &&
2117 # We need these to test for worktree scope, but outside of this
2118 # test, this is just noise
2119 test_config core.repositoryformatversion 1 &&
2120 test_config extensions.worktreeConfig true &&
2121 git config --worktree user.worktree true &&
2122 git -c user.cmdline=true config --list --show-scope >output &&
2123 test_cmp expect output
2126 test_expect_success !MINGW '--show-scope with --blob' '
2127 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2128 cat >expect <<-EOF &&
2129 command user.custom=true
2131 git config --blob=$blob --show-scope --list >output &&
2132 test_cmp expect output
2135 test_expect_success '--show-scope with --local' '
2136 cat >expect <<-\EOF &&
2137 local user.local=true
2138 local user.override=local
2139 local include.path=../include/relative.include
2141 git config --local --list --show-scope >output &&
2142 test_cmp expect output
2145 test_expect_success '--show-scope getting a single value' '
2146 cat >expect <<-\EOF &&
2147 local true
2149 git config --show-scope --get user.local >output &&
2150 test_cmp expect output
2153 test_expect_success '--show-scope with --show-origin' '
2154 cat >expect <<-EOF &&
2155 global file:$HOME/.gitconfig user.global=true
2156 global file:$HOME/.gitconfig user.override=global
2157 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2158 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2159 local file:.git/config user.local=true
2160 local file:.git/config user.override=local
2161 local file:.git/config include.path=../include/relative.include
2162 local file:.git/../include/relative.include user.relative=include
2163 command command line: user.cmdline=true
2165 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2166 test_cmp expect output
2169 test_expect_success '--show-scope with --default' '
2170 git config --show-scope --default foo some.key >actual &&
2171 echo "command foo" >expect &&
2172 test_cmp expect actual
2175 test_expect_success 'override global and system config' '
2176 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2177 cat >"$HOME"/.gitconfig <<-EOF &&
2178 [home]
2179 config = true
2182 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2183 mkdir -p "$HOME"/.config/git &&
2184 cat >"$HOME"/.config/git/config <<-EOF &&
2185 [xdg]
2186 config = true
2188 cat >.git/config <<-EOF &&
2189 [local]
2190 config = true
2192 cat >custom-global-config <<-EOF &&
2193 [global]
2194 config = true
2196 cat >custom-system-config <<-EOF &&
2197 [system]
2198 config = true
2201 cat >expect <<-EOF &&
2202 global xdg.config=true
2203 global home.config=true
2204 local local.config=true
2206 git config --show-scope --list >output &&
2207 test_cmp expect output &&
2209 cat >expect <<-EOF &&
2210 system system.config=true
2211 global global.config=true
2212 local local.config=true
2214 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2215 git config --show-scope --list >output &&
2216 test_cmp expect output &&
2218 cat >expect <<-EOF &&
2219 local local.config=true
2221 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2222 git config --show-scope --list >output &&
2223 test_cmp expect output
2226 test_expect_success 'override global and system config with missing file' '
2227 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2228 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2229 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2232 test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2233 # `git config --system` has different semantics compared to other
2234 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2235 # variable has an effect via a different proxy.
2236 cat >alias-config <<-EOF &&
2237 [alias]
2238 hello-world = !echo "hello world"
2240 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2241 git hello-world &&
2242 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2243 git hello-world >actual &&
2244 echo "hello world" >expect &&
2245 test_cmp expect actual
2248 test_expect_success 'write to overridden global and system config' '
2249 cat >expect <<EOF &&
2250 [config]
2251 key = value
2254 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2255 test_cmp expect write-to-global &&
2257 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2258 test_cmp expect write-to-system
2261 for opt in --local --worktree
2263 test_expect_success "$opt requires a repo" '
2264 # we expect 128 to ensure that we do not simply
2265 # fail to find anything and return code "1"
2266 test_expect_code 128 nongit git config $opt foo.bar
2268 done
2270 cat >.git/config <<-\EOF &&
2271 [section]
2272 foo = true
2273 number = 10
2274 big = 1M
2277 test_expect_success 'identical modern --type specifiers are allowed' '
2278 test_cmp_config 1048576 --type=int --type=int section.big
2281 test_expect_success 'identical legacy --type specifiers are allowed' '
2282 test_cmp_config 1048576 --int --int section.big
2285 test_expect_success 'identical mixed --type specifiers are allowed' '
2286 test_cmp_config 1048576 --int --type=int section.big
2289 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2290 test_must_fail git config --type=int --type=bool section.big 2>error &&
2291 test_grep "only one type at a time" error
2294 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2295 test_must_fail git config --int --bool section.big 2>error &&
2296 test_grep "only one type at a time" error
2299 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2300 test_must_fail git config --type=int --bool section.big 2>error &&
2301 test_grep "only one type at a time" error
2304 test_expect_success '--type allows valid type specifiers' '
2305 test_cmp_config true --type=bool section.foo
2308 test_expect_success '--no-type unsets type specifiers' '
2309 test_cmp_config 10 --type=bool --no-type section.number
2312 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2313 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2316 test_expect_success '--type rejects unknown specifiers' '
2317 test_must_fail git config --type=nonsense section.foo 2>error &&
2318 test_grep "unrecognized --type argument" error
2321 test_expect_success '--type=int requires at least one digit' '
2322 test_must_fail git config --type int --default m some.key >out 2>error &&
2323 grep "bad numeric config value" error &&
2324 test_must_be_empty out
2327 test_expect_success '--replace-all does not invent newlines' '
2328 q_to_tab >.git/config <<-\EOF &&
2329 [abc]key
2330 QkeepSection
2331 [xyz]
2332 Qkey = 1
2333 [abc]
2334 Qkey = a
2336 q_to_tab >expect <<-\EOF &&
2337 [abc]
2338 QkeepSection
2339 [xyz]
2340 Qkey = 1
2341 [abc]
2342 Qkey = b
2344 git config --replace-all abc.key b &&
2345 test_cmp expect .git/config
2348 test_expect_success 'set all config with value-pattern' '
2349 test_when_finished rm -f config initial &&
2350 git config --file=initial abc.key one &&
2352 # no match => add new entry
2353 cp initial config &&
2354 git config --file=config abc.key two a+ &&
2355 git config --file=config --list >actual &&
2356 cat >expect <<-\EOF &&
2357 abc.key=one
2358 abc.key=two
2360 test_cmp expect actual &&
2362 # multiple matches => failure
2363 test_must_fail git config --file=config abc.key three o+ 2>err &&
2364 test_grep "has multiple values" err &&
2366 # multiple values, no match => add
2367 git config --file=config abc.key three a+ &&
2368 git config --file=config --list >actual &&
2369 cat >expect <<-\EOF &&
2370 abc.key=one
2371 abc.key=two
2372 abc.key=three
2374 test_cmp expect actual &&
2376 # single match => replace
2377 git config --file=config abc.key four h+ &&
2378 git config --file=config --list >actual &&
2379 cat >expect <<-\EOF &&
2380 abc.key=one
2381 abc.key=two
2382 abc.key=four
2384 test_cmp expect actual
2387 test_expect_success '--replace-all and value-pattern' '
2388 test_when_finished rm -f config &&
2389 git config --file=config --add abc.key one &&
2390 git config --file=config --add abc.key two &&
2391 git config --file=config --add abc.key three &&
2392 git config --file=config --replace-all abc.key four "o+" &&
2393 git config --file=config --list >actual &&
2394 cat >expect <<-\EOF &&
2395 abc.key=four
2396 abc.key=three
2398 test_cmp expect actual
2401 test_expect_success 'refuse --fixed-value for incompatible actions' '
2402 test_when_finished rm -f config &&
2403 git config --file=config dev.null bogus &&
2405 # These modes do not allow --fixed-value at all
2406 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2407 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2408 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2409 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2410 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2411 test_must_fail git config --file=config --fixed-value --list &&
2412 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2413 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2415 # These modes complain when --fixed-value has no value-pattern
2416 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2417 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2418 test_must_fail git config --file=config --fixed-value --get dev.null &&
2419 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2420 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2421 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2422 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2425 test_expect_success '--fixed-value uses exact string matching' '
2426 test_when_finished rm -f config initial &&
2427 META="a+b*c?d[e]f.g" &&
2428 git config --file=initial fixed.test "$META" &&
2430 cp initial config &&
2431 git config --file=config fixed.test bogus "$META" &&
2432 git config --file=config --list >actual &&
2433 cat >expect <<-EOF &&
2434 fixed.test=$META
2435 fixed.test=bogus
2437 test_cmp expect actual &&
2439 cp initial config &&
2440 git config --file=config --fixed-value fixed.test bogus "$META" &&
2441 git config --file=config --list >actual &&
2442 cat >expect <<-\EOF &&
2443 fixed.test=bogus
2445 test_cmp expect actual &&
2447 cp initial config &&
2448 test_must_fail git config --file=config --unset fixed.test "$META" &&
2449 git config --file=config --fixed-value --unset fixed.test "$META" &&
2450 test_must_fail git config --file=config fixed.test &&
2452 cp initial config &&
2453 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2454 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2455 test_must_fail git config --file=config fixed.test &&
2457 cp initial config &&
2458 git config --file=config --replace-all fixed.test bogus "$META" &&
2459 git config --file=config --list >actual &&
2460 cat >expect <<-EOF &&
2461 fixed.test=$META
2462 fixed.test=bogus
2464 test_cmp expect actual &&
2466 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2467 git config --file=config --list >actual &&
2468 cat >expect <<-EOF &&
2469 fixed.test=bogus
2470 fixed.test=bogus
2472 test_cmp expect actual
2475 test_expect_success '--get and --get-all with --fixed-value' '
2476 test_when_finished rm -f config &&
2477 META="a+b*c?d[e]f.g" &&
2478 git config --file=config fixed.test bogus &&
2479 git config --file=config --add fixed.test "$META" &&
2481 git config --file=config --get fixed.test bogus &&
2482 test_must_fail git config --file=config --get fixed.test "$META" &&
2483 git config --file=config --get --fixed-value fixed.test "$META" &&
2484 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2486 git config --file=config --get-all fixed.test bogus &&
2487 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2488 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2489 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2491 git config --file=config --get-regexp fixed+ bogus &&
2492 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2493 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2494 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2497 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2498 git init hasremoteurlTest &&
2499 test_when_finished "rm -rf hasremoteurlTest" &&
2501 cat >include-this <<-\EOF &&
2502 [user]
2503 this = this-is-included
2505 cat >dont-include-that <<-\EOF &&
2506 [user]
2507 that = that-is-not-included
2509 cat >>hasremoteurlTest/.git/config <<-EOF &&
2510 [includeIf "hasconfig:remote.*.url:foourl"]
2511 path = "$(pwd)/include-this"
2512 [includeIf "hasconfig:remote.*.url:barurl"]
2513 path = "$(pwd)/dont-include-that"
2514 [remote "foo"]
2515 url = foourl
2518 echo this-is-included >expect-this &&
2519 git -C hasremoteurlTest config --get user.this >actual-this &&
2520 test_cmp expect-this actual-this &&
2522 test_must_fail git -C hasremoteurlTest config --get user.that
2525 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2526 git init hasremoteurlTest &&
2527 test_when_finished "rm -rf hasremoteurlTest" &&
2529 cat >include-two-three <<-\EOF &&
2530 [user]
2531 two = included-config
2532 three = included-config
2534 cat >>hasremoteurlTest/.git/config <<-EOF &&
2535 [remote "foo"]
2536 url = foourl
2537 [user]
2538 one = main-config
2539 two = main-config
2540 [includeIf "hasconfig:remote.*.url:foourl"]
2541 path = "$(pwd)/include-two-three"
2542 [user]
2543 three = main-config
2546 echo main-config >expect-main-config &&
2547 echo included-config >expect-included-config &&
2549 git -C hasremoteurlTest config --get user.one >actual &&
2550 test_cmp expect-main-config actual &&
2552 git -C hasremoteurlTest config --get user.two >actual &&
2553 test_cmp expect-included-config actual &&
2555 git -C hasremoteurlTest config --get user.three >actual &&
2556 test_cmp expect-main-config actual
2559 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2560 git init hasremoteurlTest &&
2561 test_when_finished "rm -rf hasremoteurlTest" &&
2563 printf "[user]\ndss = yes\n" >double-star-start &&
2564 printf "[user]\ndse = yes\n" >double-star-end &&
2565 printf "[user]\ndsm = yes\n" >double-star-middle &&
2566 printf "[user]\nssm = yes\n" >single-star-middle &&
2567 printf "[user]\nno = no\n" >no &&
2569 cat >>hasremoteurlTest/.git/config <<-EOF &&
2570 [remote "foo"]
2571 url = https://foo/bar/baz
2572 [includeIf "hasconfig:remote.*.url:**/baz"]
2573 path = "$(pwd)/double-star-start"
2574 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2575 path = "$(pwd)/no"
2576 [includeIf "hasconfig:remote.*.url:https:/**"]
2577 path = "$(pwd)/double-star-end"
2578 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2579 path = "$(pwd)/no"
2580 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2581 path = "$(pwd)/double-star-middle"
2582 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2583 path = "$(pwd)/no"
2584 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2585 path = "$(pwd)/single-star-middle"
2586 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2587 path = "$(pwd)/no"
2590 git -C hasremoteurlTest config --get user.dss &&
2591 git -C hasremoteurlTest config --get user.dse &&
2592 git -C hasremoteurlTest config --get user.dsm &&
2593 git -C hasremoteurlTest config --get user.ssm &&
2594 test_must_fail git -C hasremoteurlTest config --get user.no
2597 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2598 git init hasremoteurlTest &&
2599 test_when_finished "rm -rf hasremoteurlTest" &&
2601 cat >include-with-url <<-\EOF &&
2602 [remote "bar"]
2603 url = barurl
2605 cat >>hasremoteurlTest/.git/config <<-EOF &&
2606 [includeIf "hasconfig:remote.*.url:foourl"]
2607 path = "$(pwd)/include-with-url"
2610 # test with any Git command
2611 test_must_fail git -C hasremoteurlTest status 2>err &&
2612 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err
2615 test_done