surround %s with quotes when failed to lookup commit
[git/debian.git] / t / t1300-config.sh
blob86bfbc2b3642da97083e25c5cff280c0431a0dc2
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_i18ngrep 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_i18ngrep "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_i18ngrep "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_i18ngrep "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_i18ngrep "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_i18ngrep "[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_i18ngrep "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 git config alias.split-cmdline-fix 'echo \"' &&
1103 test_must_fail git split-cmdline-fix &&
1104 echo foo > foo &&
1105 git add foo &&
1106 git commit -m 'initial commit' &&
1107 git config branch.main.mergeoptions 'echo \"' &&
1108 test_must_fail git merge main
1111 test_expect_success 'git -c "key=value" support' '
1112 cat >expect <<-\EOF &&
1113 value
1114 value
1115 true
1118 git -c section.name=value config section.name &&
1119 git -c foo.CamelCase=value config foo.camelcase &&
1120 git -c foo.flag config --bool foo.flag
1121 } >actual &&
1122 test_cmp expect actual &&
1123 test_must_fail git -c name=value config section.name
1126 # We just need a type-specifier here that cares about the
1127 # distinction internally between a NULL boolean and a real
1128 # string (because most of git's internal parsers do care).
1129 # Using "--path" works, but we do not otherwise care about
1130 # its semantics.
1131 test_expect_success 'git -c can represent empty string' '
1132 echo >expect &&
1133 git -c foo.empty= config --path foo.empty >actual &&
1134 test_cmp expect actual
1137 test_expect_success 'key sanity-checking' '
1138 test_must_fail git config foo=bar &&
1139 test_must_fail git config foo=.bar &&
1140 test_must_fail git config foo.ba=r &&
1141 test_must_fail git config foo.1bar &&
1142 test_must_fail git config foo."ba
1143 z".bar &&
1144 test_must_fail git config . false &&
1145 test_must_fail git config .foo false &&
1146 test_must_fail git config foo. false &&
1147 test_must_fail git config .foo. false &&
1148 git config foo.bar true &&
1149 git config foo."ba =z".bar false
1152 test_expect_success 'git -c works with aliases of builtins' '
1153 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1154 echo bar >expect &&
1155 git checkconfig >actual &&
1156 test_cmp expect actual
1159 test_expect_success 'aliases can be CamelCased' '
1160 test_config alias.CamelCased "rev-parse HEAD" &&
1161 git CamelCased >out &&
1162 git rev-parse HEAD >expect &&
1163 test_cmp expect out
1166 test_expect_success 'git -c does not split values on equals' '
1167 echo "value with = in it" >expect &&
1168 git -c section.foo="value with = in it" config section.foo >actual &&
1169 test_cmp expect actual
1172 test_expect_success 'git -c dies on bogus config' '
1173 test_must_fail git -c core.bare=foo rev-parse
1176 test_expect_success 'git -c complains about empty key' '
1177 test_must_fail git -c "=foo" rev-parse
1180 test_expect_success 'git -c complains about empty key and value' '
1181 test_must_fail git -c "" rev-parse
1184 test_expect_success 'multiple git -c appends config' '
1185 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1186 cat >expect <<-\EOF &&
1187 x.one 1
1188 x.two 2
1190 git -c x.one=1 x >actual &&
1191 test_cmp expect actual
1194 test_expect_success 'last one wins: two level vars' '
1196 # sec.var and sec.VAR are the same variable, as the first
1197 # and the last level of a configuration variable name is
1198 # case insensitive.
1200 echo VAL >expect &&
1202 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1203 test_cmp expect actual &&
1204 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1205 test_cmp expect actual &&
1207 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1208 test_cmp expect actual &&
1209 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1210 test_cmp expect actual
1213 test_expect_success 'last one wins: three level vars' '
1215 # v.a.r and v.A.r are not the same variable, as the middle
1216 # level of a three-level configuration variable name is
1217 # case sensitive.
1219 echo val >expect &&
1220 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1221 test_cmp expect actual &&
1222 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1223 test_cmp expect actual &&
1225 # v.a.r and V.a.R are the same variable, as the first
1226 # and the last level of a configuration variable name is
1227 # case insensitive.
1229 echo VAL >expect &&
1230 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1231 test_cmp expect actual &&
1232 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1233 test_cmp expect actual &&
1234 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1235 test_cmp expect actual &&
1236 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1237 test_cmp expect actual
1240 test_expect_success 'old-fashioned settings are case insensitive' '
1241 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1243 cat >testConfig_actual <<-EOF &&
1244 [V.A]
1245 r = value1
1247 q_to_tab >testConfig_expect <<-EOF &&
1248 [V.A]
1249 Qr = value2
1251 git config -f testConfig_actual "v.a.r" value2 &&
1252 test_cmp 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 r = value1
1272 Qr = value2
1274 git config -f testConfig_actual "V.A.r" value2 &&
1275 test_cmp testConfig_expect testConfig_actual &&
1277 cat >testConfig_actual <<-EOF &&
1278 [V.A]
1279 r = value1
1281 q_to_tab >testConfig_expect <<-EOF &&
1282 [V.A]
1283 r = value1
1284 Qr = value2
1286 git config -f testConfig_actual "v.A.r" value2 &&
1287 test_cmp testConfig_expect testConfig_actual
1290 test_expect_success 'setting different case sensitive subsections ' '
1291 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1293 cat >testConfig_actual <<-EOF &&
1294 [V "A"]
1295 R = v1
1296 [K "E"]
1297 Y = v1
1298 [a "b"]
1299 c = v1
1300 [d "e"]
1301 f = v1
1303 q_to_tab >testConfig_expect <<-EOF &&
1304 [V "A"]
1305 Qr = v2
1306 [K "E"]
1307 Qy = v2
1308 [a "b"]
1309 Qc = v2
1310 [d "e"]
1311 f = v1
1312 [d "E"]
1313 Qf = v2
1315 # exact match
1316 git config -f testConfig_actual a.b.c v2 &&
1317 # match section and subsection, key is cased differently.
1318 git config -f testConfig_actual K.E.y v2 &&
1319 # section and key are matched case insensitive, but subsection needs
1320 # to match; When writing out new values only the key is adjusted
1321 git config -f testConfig_actual v.A.r v2 &&
1322 # subsection is not matched:
1323 git config -f testConfig_actual d.E.f v2 &&
1324 test_cmp testConfig_expect testConfig_actual
1327 for VAR in a .a a. a.0b a."b c". a."b c".0d
1329 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1330 test_must_fail git -c "$VAR=VAL" config -l
1332 done
1334 for VAR in a.b a."b c".d
1336 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1337 echo VAL >expect &&
1338 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1339 test_cmp expect actual
1341 done
1343 test_expect_success 'git -c is not confused by empty environment' '
1344 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1347 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1348 v="${SQ}key.one=foo${SQ}" &&
1349 v="$v ${SQ}key.two=bar${SQ}" &&
1350 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1351 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1352 cat >expect <<-EOF &&
1353 key.one foo
1354 key.two bar
1355 key.ambiguous section.whatever=value
1357 test_cmp expect actual
1360 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1361 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1362 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1363 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1364 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1365 cat >expect <<-EOF &&
1366 key.one foo
1367 key.two bar
1368 key.ambiguous=section.whatever value
1370 test_cmp expect actual
1373 test_expect_success 'old and new-style entries can mix' '
1374 v="${SQ}key.oldone=oldfoo${SQ}" &&
1375 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1376 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1377 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1378 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1379 cat >expect <<-EOF &&
1380 key.oldone oldfoo
1381 key.newone newfoo
1382 key.oldtwo oldbar
1383 key.newtwo newbar
1385 test_cmp expect actual
1388 test_expect_success 'old and new bools with ambiguous subsection' '
1389 v="${SQ}key.with=equals.oldbool${SQ}" &&
1390 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1391 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1392 cat >expect <<-EOF &&
1393 key.with equals.oldbool
1394 key.with=equals.newbool
1396 test_cmp expect actual
1399 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1400 cat >expect <<-\EOF &&
1401 env.one one
1402 env.two two
1404 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1405 git config --get-regexp "env.*" >actual &&
1406 test_cmp expect actual &&
1408 cat >expect <<-EOF &&
1409 env.one one${SQ}
1410 env.two two
1412 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1413 git config --get-regexp "env.*" >actual &&
1414 test_cmp expect actual &&
1416 test_must_fail env \
1417 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1418 git config --get-regexp "env.*"
1421 test_expect_success 'git --config-env=key=envvar support' '
1422 cat >expect <<-\EOF &&
1423 value
1424 value
1425 value
1426 value
1427 false
1428 false
1431 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1432 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1433 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1434 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1435 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1436 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1437 } >actual &&
1438 test_cmp expect actual
1441 test_expect_success 'git --config-env with missing value' '
1442 test_must_fail env ENVVAR=value git --config-env 2>error &&
1443 grep "no config key given for --config-env" error &&
1444 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1445 grep "invalid config format: config" error
1448 test_expect_success 'git --config-env fails with invalid parameters' '
1449 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1450 test_i18ngrep "invalid config format: foo.flag" error &&
1451 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1452 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1453 sane_unset NONEXISTENT &&
1454 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1455 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1458 test_expect_success 'git -c and --config-env work together' '
1459 cat >expect <<-\EOF &&
1460 bar.cmd cmd-value
1461 bar.env env-value
1463 ENVVAR=env-value git \
1464 -c bar.cmd=cmd-value \
1465 --config-env=bar.env=ENVVAR \
1466 config --get-regexp "^bar.*" >actual &&
1467 test_cmp expect actual
1470 test_expect_success 'git -c and --config-env override each other' '
1471 cat >expect <<-\EOF &&
1476 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1477 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1478 } >actual &&
1479 test_cmp expect actual
1482 test_expect_success '--config-env handles keys with equals' '
1483 echo value=with=equals >expect &&
1484 ENVVAR=value=with=equals git \
1485 --config-env=section.subsection=with=equals.key=ENVVAR \
1486 config section.subsection=with=equals.key >actual &&
1487 test_cmp expect actual
1490 test_expect_success 'git config handles environment config pairs' '
1491 GIT_CONFIG_COUNT=2 \
1492 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1493 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1494 git config --get-regexp "pair.*" >actual &&
1495 cat >expect <<-EOF &&
1496 pair.one foo
1497 pair.two bar
1499 test_cmp expect actual
1502 test_expect_success 'git config ignores pairs without count' '
1503 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1504 git config pair.one 2>error &&
1505 test_must_be_empty error
1508 test_expect_success 'git config ignores pairs exceeding count' '
1509 GIT_CONFIG_COUNT=1 \
1510 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1511 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1512 git config --get-regexp "pair.*" >actual 2>error &&
1513 cat >expect <<-EOF &&
1514 pair.one value
1516 test_cmp expect actual &&
1517 test_must_be_empty error
1520 test_expect_success 'git config ignores pairs with zero count' '
1521 test_must_fail env \
1522 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1523 git config pair.one 2>error &&
1524 test_must_be_empty error
1527 test_expect_success 'git config ignores pairs with empty count' '
1528 test_must_fail env \
1529 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1530 git config pair.one 2>error &&
1531 test_must_be_empty error
1534 test_expect_success 'git config fails with invalid count' '
1535 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1536 test_i18ngrep "bogus count" error &&
1537 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1538 test_i18ngrep "too many entries" error
1541 test_expect_success 'git config fails with missing config key' '
1542 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1543 git config --list 2>error &&
1544 test_i18ngrep "missing config key" error
1547 test_expect_success 'git config fails with missing config value' '
1548 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1549 git config --list 2>error &&
1550 test_i18ngrep "missing config value" error
1553 test_expect_success 'git config fails with invalid config pair key' '
1554 test_must_fail env GIT_CONFIG_COUNT=1 \
1555 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1556 git config --list &&
1557 test_must_fail env GIT_CONFIG_COUNT=1 \
1558 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1559 git config --list
1562 test_expect_success 'environment overrides config file' '
1563 test_when_finished "rm -f .git/config" &&
1564 cat >.git/config <<-EOF &&
1565 [pair]
1566 one = value
1568 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1569 git config pair.one >actual &&
1570 cat >expect <<-EOF &&
1571 override
1573 test_cmp expect actual
1576 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1577 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1578 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1579 git config pair.one >actual &&
1580 cat >expect <<-EOF &&
1581 override
1583 test_cmp expect actual
1586 test_expect_success 'command line overrides environment config' '
1587 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1588 git -c pair.one=override config pair.one >actual &&
1589 cat >expect <<-EOF &&
1590 override
1592 test_cmp expect actual
1595 test_expect_success 'git config --edit works' '
1596 git config -f tmp test.value no &&
1597 echo test.value=yes >expect &&
1598 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1599 git config -f tmp --list >actual &&
1600 test_cmp expect actual
1603 test_expect_success 'git config --edit respects core.editor' '
1604 git config -f tmp test.value no &&
1605 echo test.value=yes >expect &&
1606 test_config core.editor "echo [test]value=yes >" &&
1607 git config -f tmp --edit &&
1608 git config -f tmp --list >actual &&
1609 test_cmp expect actual
1612 # malformed configuration files
1613 test_expect_success 'barf on syntax error' '
1614 cat >.git/config <<-\EOF &&
1615 # broken key=value
1616 [section]
1617 key garbage
1619 test_must_fail git config --get section.key 2>error &&
1620 test_i18ngrep " line 3 " error
1623 test_expect_success 'barf on incomplete section header' '
1624 cat >.git/config <<-\EOF &&
1625 # broken section line
1626 [section
1627 key = value
1629 test_must_fail git config --get section.key 2>error &&
1630 test_i18ngrep " line 2 " error
1633 test_expect_success 'barf on incomplete string' '
1634 cat >.git/config <<-\EOF &&
1635 # broken value string
1636 [section]
1637 key = "value string
1639 test_must_fail git config --get section.key 2>error &&
1640 test_i18ngrep " line 3 " error
1643 test_expect_success 'urlmatch' '
1644 cat >.git/config <<-\EOF &&
1645 [http]
1646 sslVerify
1647 [http "https://weak.example.com"]
1648 sslVerify = false
1649 cookieFile = /tmp/cookie.txt
1652 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1653 test_must_be_empty actual &&
1655 echo true >expect &&
1656 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1657 test_cmp expect actual &&
1659 echo false >expect &&
1660 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1661 test_cmp expect actual &&
1664 echo http.cookiefile /tmp/cookie.txt &&
1665 echo http.sslverify false
1666 } >expect &&
1667 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1668 test_cmp expect actual
1671 test_expect_success 'urlmatch favors more specific URLs' '
1672 cat >.git/config <<-\EOF &&
1673 [http "https://example.com/"]
1674 cookieFile = /tmp/root.txt
1675 [http "https://example.com/subdirectory"]
1676 cookieFile = /tmp/subdirectory.txt
1677 [http "https://user@example.com/"]
1678 cookieFile = /tmp/user.txt
1679 [http "https://averylonguser@example.com/"]
1680 cookieFile = /tmp/averylonguser.txt
1681 [http "https://preceding.example.com"]
1682 cookieFile = /tmp/preceding.txt
1683 [http "https://*.example.com"]
1684 cookieFile = /tmp/wildcard.txt
1685 [http "https://*.example.com/wildcardwithsubdomain"]
1686 cookieFile = /tmp/wildcardwithsubdomain.txt
1687 [http "https://*.example.*"]
1688 cookieFile = /tmp/multiwildcard.txt
1689 [http "https://trailing.example.com"]
1690 cookieFile = /tmp/trailing.txt
1691 [http "https://user@*.example.com/"]
1692 cookieFile = /tmp/wildcardwithuser.txt
1693 [http "https://sub.example.com/"]
1694 cookieFile = /tmp/sub.txt
1697 echo http.cookiefile /tmp/root.txt >expect &&
1698 git config --get-urlmatch HTTP https://example.com >actual &&
1699 test_cmp expect actual &&
1701 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1702 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1703 test_cmp expect actual &&
1705 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1706 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1707 test_cmp expect actual &&
1709 echo http.cookiefile /tmp/user.txt >expect &&
1710 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1711 test_cmp expect actual &&
1713 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1714 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1715 test_cmp expect actual &&
1717 echo http.cookiefile /tmp/preceding.txt >expect &&
1718 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1719 test_cmp expect actual &&
1721 echo http.cookiefile /tmp/wildcard.txt >expect &&
1722 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1723 test_cmp expect actual &&
1725 echo http.cookiefile /tmp/sub.txt >expect &&
1726 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1727 test_cmp expect actual &&
1729 echo http.cookiefile /tmp/trailing.txt >expect &&
1730 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1731 test_cmp expect actual &&
1733 echo http.cookiefile /tmp/sub.txt >expect &&
1734 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1735 test_cmp expect actual &&
1737 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1738 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1739 test_cmp expect actual
1742 test_expect_success 'urlmatch with wildcard' '
1743 cat >.git/config <<-\EOF &&
1744 [http]
1745 sslVerify
1746 [http "https://*.example.com"]
1747 sslVerify = false
1748 cookieFile = /tmp/cookie.txt
1751 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1752 test_must_be_empty actual &&
1754 echo true >expect &&
1755 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1756 test_cmp expect actual &&
1758 echo true >expect &&
1759 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1760 test_cmp expect actual &&
1762 echo true >expect &&
1763 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1764 test_cmp expect actual &&
1766 echo false >expect &&
1767 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1768 test_cmp expect actual &&
1771 echo http.cookiefile /tmp/cookie.txt &&
1772 echo http.sslverify false
1773 } >expect &&
1774 git config --get-urlmatch HTTP https://good.example.com >actual &&
1775 test_cmp expect actual &&
1777 echo http.sslverify >expect &&
1778 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1779 test_cmp expect actual
1782 # good section hygiene
1783 test_expect_success '--unset last key removes section (except if commented)' '
1784 cat >.git/config <<-\EOF &&
1785 # some generic comment on the configuration file itself
1786 # a comment specific to this "section" section.
1787 [section]
1788 # some intervening lines
1789 # that should also be dropped
1791 key = value
1792 # please be careful when you update the above variable
1795 cat >expect <<-\EOF &&
1796 # some generic comment on the configuration file itself
1797 # a comment specific to this "section" section.
1798 [section]
1799 # some intervening lines
1800 # that should also be dropped
1802 # please be careful when you update the above variable
1805 git config --unset section.key &&
1806 test_cmp expect .git/config &&
1808 cat >.git/config <<-\EOF &&
1809 [section]
1810 key = value
1811 [next-section]
1814 cat >expect <<-\EOF &&
1815 [next-section]
1818 git config --unset section.key &&
1819 test_cmp expect .git/config &&
1821 q_to_tab >.git/config <<-\EOF &&
1822 [one]
1823 Qkey = "multiline \
1824 QQ# with comment"
1825 [two]
1826 key = true
1828 git config --unset two.key &&
1829 ! grep two .git/config &&
1831 q_to_tab >.git/config <<-\EOF &&
1832 [one]
1833 Qkey = "multiline \
1834 QQ# with comment"
1835 [one]
1836 key = true
1838 git config --unset-all one.key &&
1839 test_line_count = 0 .git/config &&
1841 q_to_tab >.git/config <<-\EOF &&
1842 [one]
1843 Qkey = true
1844 Q# a comment not at the start
1845 [two]
1846 Qkey = true
1848 git config --unset two.key &&
1849 grep two .git/config &&
1851 q_to_tab >.git/config <<-\EOF &&
1852 [one]
1853 Qkey = not [two "subsection"]
1854 [two "subsection"]
1855 [two "subsection"]
1856 Qkey = true
1857 [TWO "subsection"]
1858 [one]
1860 git config --unset two.subsection.key &&
1861 test "not [two subsection]" = "$(git config one.key)" &&
1862 test_line_count = 3 .git/config
1865 test_expect_success '--unset-all removes section if empty & uncommented' '
1866 cat >.git/config <<-\EOF &&
1867 [section]
1868 key = value1
1869 key = value2
1872 git config --unset-all section.key &&
1873 test_line_count = 0 .git/config
1876 test_expect_success 'adding a key into an empty section reuses header' '
1877 cat >.git/config <<-\EOF &&
1878 [section]
1881 q_to_tab >expect <<-\EOF &&
1882 [section]
1883 Qkey = value
1886 git config section.key value &&
1887 test_cmp expect .git/config
1890 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1891 chmod 0600 .git/config &&
1892 git config imap.pass Hunter2 &&
1893 perl -e \
1894 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1895 git config --rename-section imap pop &&
1896 perl -e \
1897 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1900 ! test_have_prereq MINGW ||
1901 HOME="$(pwd)" # convert to Windows path
1903 test_expect_success 'set up --show-origin tests' '
1904 INCLUDE_DIR="$HOME/include" &&
1905 mkdir -p "$INCLUDE_DIR" &&
1906 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1907 [user]
1908 absolute = include
1910 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1911 [user]
1912 relative = include
1914 cat >"$HOME"/.gitconfig <<-EOF &&
1915 [user]
1916 global = true
1917 override = global
1918 [include]
1919 path = "$INCLUDE_DIR/absolute.include"
1921 cat >.git/config <<-\EOF
1922 [user]
1923 local = true
1924 override = local
1925 [include]
1926 path = ../include/relative.include
1930 test_expect_success '--show-origin with --list' '
1931 cat >expect <<-EOF &&
1932 file:$HOME/.gitconfig user.global=true
1933 file:$HOME/.gitconfig user.override=global
1934 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1935 file:$INCLUDE_DIR/absolute.include user.absolute=include
1936 file:.git/config user.local=true
1937 file:.git/config user.override=local
1938 file:.git/config include.path=../include/relative.include
1939 file:.git/../include/relative.include user.relative=include
1940 command line: user.environ=true
1941 command line: user.cmdline=true
1943 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1944 git -c user.cmdline=true config --list --show-origin >output &&
1945 test_cmp expect output
1948 test_expect_success '--show-origin with --list --null' '
1949 cat >expect <<-EOF &&
1950 file:$HOME/.gitconfigQuser.global
1951 trueQfile:$HOME/.gitconfigQuser.override
1952 globalQfile:$HOME/.gitconfigQinclude.path
1953 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1954 includeQfile:.git/configQuser.local
1955 trueQfile:.git/configQuser.override
1956 localQfile:.git/configQinclude.path
1957 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1958 includeQcommand line:Quser.cmdline
1959 trueQ
1961 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1962 nul_to_q <output.raw >output &&
1963 # The here-doc above adds a newline that the --null output would not
1964 # include. Add it here to make the two comparable.
1965 echo >>output &&
1966 test_cmp expect output
1969 test_expect_success '--show-origin with single file' '
1970 cat >expect <<-\EOF &&
1971 file:.git/config user.local=true
1972 file:.git/config user.override=local
1973 file:.git/config include.path=../include/relative.include
1975 git config --local --list --show-origin >output &&
1976 test_cmp expect output
1979 test_expect_success '--show-origin with --get-regexp' '
1980 cat >expect <<-EOF &&
1981 file:$HOME/.gitconfig user.global true
1982 file:.git/config user.local true
1984 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1985 test_cmp expect output
1988 test_expect_success '--show-origin getting a single key' '
1989 cat >expect <<-\EOF &&
1990 file:.git/config local
1992 git config --show-origin user.override >output &&
1993 test_cmp expect output
1996 test_expect_success 'set up custom config file' '
1997 CUSTOM_CONFIG_FILE="custom.conf" &&
1998 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1999 [user]
2000 custom = true
2004 test_expect_success !MINGW 'set up custom config file with special name characters' '
2005 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2006 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2009 test_expect_success !MINGW '--show-origin escape special file name characters' '
2010 cat >expect <<-\EOF &&
2011 file:"file\" (dq) and spaces.conf" user.custom=true
2013 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
2014 test_cmp expect output
2017 test_expect_success '--show-origin stdin' '
2018 cat >expect <<-\EOF &&
2019 standard input: user.custom=true
2021 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2022 test_cmp expect output
2025 test_expect_success '--show-origin stdin with file include' '
2026 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
2027 [user]
2028 stdin = include
2030 cat >expect <<-EOF &&
2031 file:$INCLUDE_DIR/stdin.include include
2033 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2034 git config --show-origin --includes --file - user.stdin >output &&
2036 test_cmp expect output
2039 test_expect_success '--show-origin blob' '
2040 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2041 cat >expect <<-EOF &&
2042 blob:$blob user.custom=true
2044 git config --blob=$blob --show-origin --list >output &&
2045 test_cmp expect output
2048 test_expect_success '--show-origin blob ref' '
2049 cat >expect <<-\EOF &&
2050 blob:main:custom.conf user.custom=true
2052 git add "$CUSTOM_CONFIG_FILE" &&
2053 git commit -m "new config file" &&
2054 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2055 test_cmp expect output
2058 test_expect_success '--show-scope with --list' '
2059 cat >expect <<-EOF &&
2060 global user.global=true
2061 global user.override=global
2062 global include.path=$INCLUDE_DIR/absolute.include
2063 global user.absolute=include
2064 local user.local=true
2065 local user.override=local
2066 local include.path=../include/relative.include
2067 local user.relative=include
2068 local core.repositoryformatversion=1
2069 local extensions.worktreeconfig=true
2070 worktree user.worktree=true
2071 command user.cmdline=true
2073 git worktree add wt1 &&
2074 # We need these to test for worktree scope, but outside of this
2075 # test, this is just noise
2076 test_config core.repositoryformatversion 1 &&
2077 test_config extensions.worktreeConfig true &&
2078 git config --worktree user.worktree true &&
2079 git -c user.cmdline=true config --list --show-scope >output &&
2080 test_cmp expect output
2083 test_expect_success !MINGW '--show-scope with --blob' '
2084 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2085 cat >expect <<-EOF &&
2086 command user.custom=true
2088 git config --blob=$blob --show-scope --list >output &&
2089 test_cmp expect output
2092 test_expect_success '--show-scope with --local' '
2093 cat >expect <<-\EOF &&
2094 local user.local=true
2095 local user.override=local
2096 local include.path=../include/relative.include
2098 git config --local --list --show-scope >output &&
2099 test_cmp expect output
2102 test_expect_success '--show-scope getting a single value' '
2103 cat >expect <<-\EOF &&
2104 local true
2106 git config --show-scope --get user.local >output &&
2107 test_cmp expect output
2110 test_expect_success '--show-scope with --show-origin' '
2111 cat >expect <<-EOF &&
2112 global file:$HOME/.gitconfig user.global=true
2113 global file:$HOME/.gitconfig user.override=global
2114 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2115 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2116 local file:.git/config user.local=true
2117 local file:.git/config user.override=local
2118 local file:.git/config include.path=../include/relative.include
2119 local file:.git/../include/relative.include user.relative=include
2120 command command line: user.cmdline=true
2122 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2123 test_cmp expect output
2126 test_expect_success 'override global and system config' '
2127 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
2128 cat >"$HOME"/.gitconfig <<-EOF &&
2129 [home]
2130 config = true
2133 test_when_finished rm -rf \"\$HOME\"/.config/git &&
2134 mkdir -p "$HOME"/.config/git &&
2135 cat >"$HOME"/.config/git/config <<-EOF &&
2136 [xdg]
2137 config = true
2139 cat >.git/config <<-EOF &&
2140 [local]
2141 config = true
2143 cat >custom-global-config <<-EOF &&
2144 [global]
2145 config = true
2147 cat >custom-system-config <<-EOF &&
2148 [system]
2149 config = true
2152 cat >expect <<-EOF &&
2153 global xdg.config=true
2154 global home.config=true
2155 local local.config=true
2157 git config --show-scope --list >output &&
2158 test_cmp expect output &&
2160 cat >expect <<-EOF &&
2161 system system.config=true
2162 global global.config=true
2163 local local.config=true
2165 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2166 git config --show-scope --list >output &&
2167 test_cmp expect output &&
2169 cat >expect <<-EOF &&
2170 local local.config=true
2172 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2173 git config --show-scope --list >output &&
2174 test_cmp expect output
2177 test_expect_success 'override global and system config with missing file' '
2178 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2179 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2180 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2183 test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2184 # `git config --system` has different semantics compared to other
2185 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2186 # variable has an effect via a different proxy.
2187 cat >alias-config <<-EOF &&
2188 [alias]
2189 hello-world = !echo "hello world"
2191 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2192 git hello-world &&
2193 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2194 git hello-world >actual &&
2195 echo "hello world" >expect &&
2196 test_cmp expect actual
2199 test_expect_success 'write to overridden global and system config' '
2200 cat >expect <<EOF &&
2201 [config]
2202 key = value
2205 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2206 test_cmp expect write-to-global &&
2208 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2209 test_cmp expect write-to-system
2212 for opt in --local --worktree
2214 test_expect_success "$opt requires a repo" '
2215 # we expect 128 to ensure that we do not simply
2216 # fail to find anything and return code "1"
2217 test_expect_code 128 nongit git config $opt foo.bar
2219 done
2221 cat >.git/config <<-\EOF &&
2222 [section]
2223 foo = true
2224 number = 10
2225 big = 1M
2228 test_expect_success 'identical modern --type specifiers are allowed' '
2229 test_cmp_config 1048576 --type=int --type=int section.big
2232 test_expect_success 'identical legacy --type specifiers are allowed' '
2233 test_cmp_config 1048576 --int --int section.big
2236 test_expect_success 'identical mixed --type specifiers are allowed' '
2237 test_cmp_config 1048576 --int --type=int section.big
2240 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2241 test_must_fail git config --type=int --type=bool section.big 2>error &&
2242 test_i18ngrep "only one type at a time" error
2245 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2246 test_must_fail git config --int --bool section.big 2>error &&
2247 test_i18ngrep "only one type at a time" error
2250 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2251 test_must_fail git config --type=int --bool section.big 2>error &&
2252 test_i18ngrep "only one type at a time" error
2255 test_expect_success '--type allows valid type specifiers' '
2256 test_cmp_config true --type=bool section.foo
2259 test_expect_success '--no-type unsets type specifiers' '
2260 test_cmp_config 10 --type=bool --no-type section.number
2263 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2264 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2267 test_expect_success '--type rejects unknown specifiers' '
2268 test_must_fail git config --type=nonsense section.foo 2>error &&
2269 test_i18ngrep "unrecognized --type argument" error
2272 test_expect_success '--type=int requires at least one digit' '
2273 test_must_fail git config --type int --default m some.key >out 2>error &&
2274 grep "bad numeric config value" error &&
2275 test_must_be_empty out
2278 test_expect_success '--replace-all does not invent newlines' '
2279 q_to_tab >.git/config <<-\EOF &&
2280 [abc]key
2281 QkeepSection
2282 [xyz]
2283 Qkey = 1
2284 [abc]
2285 Qkey = a
2287 q_to_tab >expect <<-\EOF &&
2288 [abc]
2289 QkeepSection
2290 [xyz]
2291 Qkey = 1
2292 [abc]
2293 Qkey = b
2295 git config --replace-all abc.key b &&
2296 test_cmp expect .git/config
2299 test_expect_success 'set all config with value-pattern' '
2300 test_when_finished rm -f config initial &&
2301 git config --file=initial abc.key one &&
2303 # no match => add new entry
2304 cp initial config &&
2305 git config --file=config abc.key two a+ &&
2306 git config --file=config --list >actual &&
2307 cat >expect <<-\EOF &&
2308 abc.key=one
2309 abc.key=two
2311 test_cmp expect actual &&
2313 # multiple matches => failure
2314 test_must_fail git config --file=config abc.key three o+ 2>err &&
2315 test_i18ngrep "has multiple values" err &&
2317 # multiple values, no match => add
2318 git config --file=config abc.key three a+ &&
2319 git config --file=config --list >actual &&
2320 cat >expect <<-\EOF &&
2321 abc.key=one
2322 abc.key=two
2323 abc.key=three
2325 test_cmp expect actual &&
2327 # single match => replace
2328 git config --file=config abc.key four h+ &&
2329 git config --file=config --list >actual &&
2330 cat >expect <<-\EOF &&
2331 abc.key=one
2332 abc.key=two
2333 abc.key=four
2335 test_cmp expect actual
2338 test_expect_success '--replace-all and value-pattern' '
2339 test_when_finished rm -f config &&
2340 git config --file=config --add abc.key one &&
2341 git config --file=config --add abc.key two &&
2342 git config --file=config --add abc.key three &&
2343 git config --file=config --replace-all abc.key four "o+" &&
2344 git config --file=config --list >actual &&
2345 cat >expect <<-\EOF &&
2346 abc.key=four
2347 abc.key=three
2349 test_cmp expect actual
2352 test_expect_success 'refuse --fixed-value for incompatible actions' '
2353 test_when_finished rm -f config &&
2354 git config --file=config dev.null bogus &&
2356 # These modes do not allow --fixed-value at all
2357 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2358 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2359 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2360 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2361 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2362 test_must_fail git config --file=config --fixed-value --list &&
2363 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2364 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2366 # These modes complain when --fixed-value has no value-pattern
2367 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2368 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2369 test_must_fail git config --file=config --fixed-value --get dev.null &&
2370 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2371 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2372 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2373 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2376 test_expect_success '--fixed-value uses exact string matching' '
2377 test_when_finished rm -f config initial &&
2378 META="a+b*c?d[e]f.g" &&
2379 git config --file=initial fixed.test "$META" &&
2381 cp initial config &&
2382 git config --file=config fixed.test bogus "$META" &&
2383 git config --file=config --list >actual &&
2384 cat >expect <<-EOF &&
2385 fixed.test=$META
2386 fixed.test=bogus
2388 test_cmp expect actual &&
2390 cp initial config &&
2391 git config --file=config --fixed-value fixed.test bogus "$META" &&
2392 git config --file=config --list >actual &&
2393 cat >expect <<-\EOF &&
2394 fixed.test=bogus
2396 test_cmp expect actual &&
2398 cp initial config &&
2399 test_must_fail git config --file=config --unset fixed.test "$META" &&
2400 git config --file=config --fixed-value --unset fixed.test "$META" &&
2401 test_must_fail git config --file=config fixed.test &&
2403 cp initial config &&
2404 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2405 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2406 test_must_fail git config --file=config fixed.test &&
2408 cp initial config &&
2409 git config --file=config --replace-all fixed.test bogus "$META" &&
2410 git config --file=config --list >actual &&
2411 cat >expect <<-EOF &&
2412 fixed.test=$META
2413 fixed.test=bogus
2415 test_cmp expect actual &&
2417 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2418 git config --file=config --list >actual &&
2419 cat >expect <<-EOF &&
2420 fixed.test=bogus
2421 fixed.test=bogus
2423 test_cmp expect actual
2426 test_expect_success '--get and --get-all with --fixed-value' '
2427 test_when_finished rm -f config &&
2428 META="a+b*c?d[e]f.g" &&
2429 git config --file=config fixed.test bogus &&
2430 git config --file=config --add fixed.test "$META" &&
2432 git config --file=config --get fixed.test bogus &&
2433 test_must_fail git config --file=config --get fixed.test "$META" &&
2434 git config --file=config --get --fixed-value fixed.test "$META" &&
2435 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2437 git config --file=config --get-all fixed.test bogus &&
2438 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2439 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2440 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2442 git config --file=config --get-regexp fixed+ bogus &&
2443 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2444 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2445 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2448 test_expect_success 'includeIf.hasconfig:remote.*.url' '
2449 git init hasremoteurlTest &&
2450 test_when_finished "rm -rf hasremoteurlTest" &&
2452 cat >include-this <<-\EOF &&
2453 [user]
2454 this = this-is-included
2456 cat >dont-include-that <<-\EOF &&
2457 [user]
2458 that = that-is-not-included
2460 cat >>hasremoteurlTest/.git/config <<-EOF &&
2461 [includeIf "hasconfig:remote.*.url:foourl"]
2462 path = "$(pwd)/include-this"
2463 [includeIf "hasconfig:remote.*.url:barurl"]
2464 path = "$(pwd)/dont-include-that"
2465 [remote "foo"]
2466 url = foourl
2469 echo this-is-included >expect-this &&
2470 git -C hasremoteurlTest config --get user.this >actual-this &&
2471 test_cmp expect-this actual-this &&
2473 test_must_fail git -C hasremoteurlTest config --get user.that
2476 test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2477 git init hasremoteurlTest &&
2478 test_when_finished "rm -rf hasremoteurlTest" &&
2480 cat >include-two-three <<-\EOF &&
2481 [user]
2482 two = included-config
2483 three = included-config
2485 cat >>hasremoteurlTest/.git/config <<-EOF &&
2486 [remote "foo"]
2487 url = foourl
2488 [user]
2489 one = main-config
2490 two = main-config
2491 [includeIf "hasconfig:remote.*.url:foourl"]
2492 path = "$(pwd)/include-two-three"
2493 [user]
2494 three = main-config
2497 echo main-config >expect-main-config &&
2498 echo included-config >expect-included-config &&
2500 git -C hasremoteurlTest config --get user.one >actual &&
2501 test_cmp expect-main-config actual &&
2503 git -C hasremoteurlTest config --get user.two >actual &&
2504 test_cmp expect-included-config actual &&
2506 git -C hasremoteurlTest config --get user.three >actual &&
2507 test_cmp expect-main-config actual
2510 test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2511 git init hasremoteurlTest &&
2512 test_when_finished "rm -rf hasremoteurlTest" &&
2514 printf "[user]\ndss = yes\n" >double-star-start &&
2515 printf "[user]\ndse = yes\n" >double-star-end &&
2516 printf "[user]\ndsm = yes\n" >double-star-middle &&
2517 printf "[user]\nssm = yes\n" >single-star-middle &&
2518 printf "[user]\nno = no\n" >no &&
2520 cat >>hasremoteurlTest/.git/config <<-EOF &&
2521 [remote "foo"]
2522 url = https://foo/bar/baz
2523 [includeIf "hasconfig:remote.*.url:**/baz"]
2524 path = "$(pwd)/double-star-start"
2525 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2526 path = "$(pwd)/no"
2527 [includeIf "hasconfig:remote.*.url:https:/**"]
2528 path = "$(pwd)/double-star-end"
2529 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2530 path = "$(pwd)/no"
2531 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2532 path = "$(pwd)/double-star-middle"
2533 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2534 path = "$(pwd)/no"
2535 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2536 path = "$(pwd)/single-star-middle"
2537 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2538 path = "$(pwd)/no"
2541 git -C hasremoteurlTest config --get user.dss &&
2542 git -C hasremoteurlTest config --get user.dse &&
2543 git -C hasremoteurlTest config --get user.dsm &&
2544 git -C hasremoteurlTest config --get user.ssm &&
2545 test_must_fail git -C hasremoteurlTest config --get user.no
2548 test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2549 git init hasremoteurlTest &&
2550 test_when_finished "rm -rf hasremoteurlTest" &&
2552 cat >include-with-url <<-\EOF &&
2553 [remote "bar"]
2554 url = barurl
2556 cat >>hasremoteurlTest/.git/config <<-EOF &&
2557 [includeIf "hasconfig:remote.*.url:foourl"]
2558 path = "$(pwd)/include-with-url"
2561 # test with any Git command
2562 test_must_fail git -C hasremoteurlTest status 2>err &&
2563 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err
2566 test_done