Fourth batch
[git/raj.git] / t / t1300-config.sh
blob97ebfe1f9d5cea7b37d70d8f7069f00bb5045b8e
1 #!/bin/sh
3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test git config in different settings'
8 . ./test-lib.sh
10 test_expect_success 'clear default config' '
11 rm -f .git/config
14 cat > expect << EOF
15 [core]
16 penguin = little blue
17 EOF
18 test_expect_success 'initial' '
19 git config core.penguin "little blue" &&
20 test_cmp expect .git/config
23 cat > expect << EOF
24 [core]
25 penguin = little blue
26 Movie = BadPhysics
27 EOF
28 test_expect_success 'mixed case' '
29 git config Core.Movie BadPhysics &&
30 test_cmp expect .git/config
33 cat > expect << EOF
34 [core]
35 penguin = little blue
36 Movie = BadPhysics
37 [Cores]
38 WhatEver = Second
39 EOF
40 test_expect_success 'similar section' '
41 git config Cores.WhatEver Second &&
42 test_cmp expect .git/config
45 cat > expect << EOF
46 [core]
47 penguin = little blue
48 Movie = BadPhysics
49 UPPERCASE = true
50 [Cores]
51 WhatEver = Second
52 EOF
53 test_expect_success 'uppercase section' '
54 git config CORE.UPPERCASE true &&
55 test_cmp expect .git/config
58 test_expect_success 'replace with non-match' '
59 git config core.penguin kingpin !blue
62 test_expect_success 'replace with non-match (actually matching)' '
63 git config core.penguin "very blue" !kingpin
66 cat > expect << EOF
67 [core]
68 penguin = very blue
69 Movie = BadPhysics
70 UPPERCASE = true
71 penguin = kingpin
72 [Cores]
73 WhatEver = Second
74 EOF
76 test_expect_success 'non-match result' 'test_cmp expect .git/config'
78 test_expect_success 'find mixed-case key by canonical name' '
79 test_cmp_config Second cores.whatever
82 test_expect_success 'find mixed-case key by non-canonical name' '
83 test_cmp_config Second CoReS.WhAtEvEr
86 test_expect_success 'subsections are not canonicalized by git-config' '
87 cat >>.git/config <<-\EOF &&
88 [section.SubSection]
89 key = one
90 [section "SubSection"]
91 key = two
92 EOF
93 test_cmp_config one section.subsection.key &&
94 test_cmp_config two section.SubSection.key
97 cat > .git/config <<\EOF
98 [alpha]
99 bar = foo
100 [beta]
101 baz = multiple \
102 lines
103 foo = bar
106 test_expect_success 'unset with cont. lines' '
107 git config --unset beta.baz
110 cat > expect <<\EOF
111 [alpha]
112 bar = foo
113 [beta]
114 foo = bar
117 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
119 cat > .git/config << EOF
120 [beta] ; silly comment # another comment
121 noIndent= sillyValue ; 'nother silly comment
123 # empty line
124 ; comment
125 haha ="beta" # last silly comment
126 haha = hello
127 haha = bello
128 [nextSection] noNewline = ouch
131 cp .git/config .git/config2
133 test_expect_success 'multiple unset' '
134 git config --unset-all beta.haha
137 cat > expect << EOF
138 [beta] ; silly comment # another comment
139 noIndent= sillyValue ; 'nother silly comment
141 # empty line
142 ; comment
143 [nextSection] noNewline = ouch
146 test_expect_success 'multiple unset is correct' '
147 test_cmp expect .git/config
150 cp .git/config2 .git/config
152 test_expect_success '--replace-all missing value' '
153 test_must_fail git config --replace-all beta.haha &&
154 test_cmp .git/config2 .git/config
157 rm .git/config2
159 test_expect_success '--replace-all' '
160 git config --replace-all beta.haha gamma
163 cat > expect << EOF
164 [beta] ; silly comment # another comment
165 noIndent= sillyValue ; 'nother silly comment
167 # empty line
168 ; comment
169 haha = gamma
170 [nextSection] noNewline = ouch
173 test_expect_success 'all replaced' '
174 test_cmp expect .git/config
177 cat > expect << EOF
178 [beta] ; silly comment # another comment
179 noIndent= sillyValue ; 'nother silly comment
181 # empty line
182 ; comment
183 haha = alpha
184 [nextSection] noNewline = ouch
186 test_expect_success 'really mean test' '
187 git config beta.haha alpha &&
188 test_cmp expect .git/config
191 cat > expect << EOF
192 [beta] ; silly comment # another comment
193 noIndent= sillyValue ; 'nother silly comment
195 # empty line
196 ; comment
197 haha = alpha
198 [nextSection]
199 nonewline = wow
201 test_expect_success 'really really mean test' '
202 git config nextsection.nonewline wow &&
203 test_cmp expect .git/config
206 test_expect_success 'get value' '
207 test_cmp_config alpha beta.haha
210 cat > expect << EOF
211 [beta] ; silly comment # another comment
212 noIndent= sillyValue ; 'nother silly comment
214 # empty line
215 ; comment
216 [nextSection]
217 nonewline = wow
219 test_expect_success 'unset' '
220 git config --unset beta.haha &&
221 test_cmp expect .git/config
224 cat > expect << EOF
225 [beta] ; silly comment # another comment
226 noIndent= sillyValue ; 'nother silly comment
228 # empty line
229 ; comment
230 [nextSection]
231 nonewline = wow
232 NoNewLine = wow2 for me
234 test_expect_success 'multivar' '
235 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
236 test_cmp expect .git/config
239 test_expect_success 'non-match' '
240 git config --get nextsection.nonewline !for
243 test_expect_success 'non-match value' '
244 test_cmp_config wow --get nextsection.nonewline !for
247 test_expect_success 'multi-valued get returns final one' '
248 test_cmp_config "wow2 for me" --get nextsection.nonewline
251 test_expect_success 'multi-valued get-all returns all' '
252 cat >expect <<-\EOF &&
254 wow2 for me
256 git config --get-all nextsection.nonewline >actual &&
257 test_cmp expect actual
260 cat > expect << EOF
261 [beta] ; silly comment # another comment
262 noIndent= sillyValue ; 'nother silly comment
264 # empty line
265 ; comment
266 [nextSection]
267 nonewline = wow3
268 NoNewLine = wow2 for me
270 test_expect_success 'multivar replace' '
271 git config nextsection.nonewline "wow3" "wow$" &&
272 test_cmp expect .git/config
275 test_expect_success 'ambiguous unset' '
276 test_must_fail git config --unset nextsection.nonewline
279 test_expect_success 'invalid unset' '
280 test_must_fail git config --unset somesection.nonewline
283 cat > expect << EOF
284 [beta] ; silly comment # another comment
285 noIndent= sillyValue ; 'nother silly comment
287 # empty line
288 ; comment
289 [nextSection]
290 NoNewLine = wow2 for me
293 test_expect_success 'multivar unset' '
294 git config --unset nextsection.nonewline "wow3$" &&
295 test_cmp expect .git/config
298 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
300 test_expect_success 'correct key' 'git config 123456.a123 987'
302 test_expect_success 'hierarchical section' '
303 git config Version.1.2.3eX.Alpha beta
306 cat > expect << EOF
307 [beta] ; silly comment # another comment
308 noIndent= sillyValue ; 'nother silly comment
310 # empty line
311 ; comment
312 [nextSection]
313 NoNewLine = wow2 for me
314 [123456]
315 a123 = 987
316 [Version "1.2.3eX"]
317 Alpha = beta
320 test_expect_success 'hierarchical section value' '
321 test_cmp expect .git/config
324 cat > expect << EOF
325 beta.noindent=sillyValue
326 nextsection.nonewline=wow2 for me
327 123456.a123=987
328 version.1.2.3eX.alpha=beta
331 test_expect_success 'working --list' '
332 git config --list > output &&
333 test_cmp expect output
335 test_expect_success '--list without repo produces empty output' '
336 git --git-dir=nonexistent config --list >output &&
337 test_must_be_empty output
340 cat > expect << EOF
341 beta.noindent
342 nextsection.nonewline
343 123456.a123
344 version.1.2.3eX.alpha
347 test_expect_success '--name-only --list' '
348 git config --name-only --list >output &&
349 test_cmp expect output
352 cat > expect << EOF
353 beta.noindent sillyValue
354 nextsection.nonewline wow2 for me
357 test_expect_success '--get-regexp' '
358 git config --get-regexp in >output &&
359 test_cmp expect output
362 cat > expect << EOF
363 beta.noindent
364 nextsection.nonewline
367 test_expect_success '--name-only --get-regexp' '
368 git config --name-only --get-regexp in >output &&
369 test_cmp expect output
372 cat > expect << EOF
373 wow2 for me
374 wow4 for you
377 test_expect_success '--add' '
378 git config --add nextsection.nonewline "wow4 for you" &&
379 git config --get-all nextsection.nonewline > output &&
380 test_cmp expect output
383 cat > .git/config << EOF
384 [novalue]
385 variable
386 [emptyvalue]
387 variable =
390 test_expect_success 'get variable with no value' '
391 git config --get novalue.variable ^$
394 test_expect_success 'get variable with empty value' '
395 git config --get emptyvalue.variable ^$
398 echo novalue.variable > expect
400 test_expect_success 'get-regexp variable with no value' '
401 git config --get-regexp novalue > output &&
402 test_cmp expect output
405 echo 'novalue.variable true' > expect
407 test_expect_success 'get-regexp --bool variable with no value' '
408 git config --bool --get-regexp novalue > output &&
409 test_cmp expect output
412 echo 'emptyvalue.variable ' > expect
414 test_expect_success 'get-regexp variable with empty value' '
415 git config --get-regexp emptyvalue > output &&
416 test_cmp expect output
419 echo true > expect
421 test_expect_success 'get bool variable with no value' '
422 git config --bool novalue.variable > output &&
423 test_cmp expect output
426 echo false > expect
428 test_expect_success 'get bool variable with empty value' '
429 git config --bool emptyvalue.variable > output &&
430 test_cmp expect output
433 test_expect_success 'no arguments, but no crash' '
434 test_must_fail git config >output 2>&1 &&
435 test_i18ngrep usage output
438 cat > .git/config << EOF
439 [a.b]
440 c = d
443 cat > expect << EOF
444 [a.b]
445 c = d
447 x = y
450 test_expect_success 'new section is partial match of another' '
451 git config a.x y &&
452 test_cmp expect .git/config
455 cat > expect << EOF
456 [a.b]
457 c = d
459 x = y
460 b = c
462 x = y
465 test_expect_success 'new variable inserts into proper section' '
466 git config b.x y &&
467 git config a.b c &&
468 test_cmp expect .git/config
471 test_expect_success 'alternative --file (non-existing file should fail)' '
472 test_must_fail git config --file non-existing-config -l
475 cat > other-config << EOF
476 [ein]
477 bahn = strasse
480 cat > expect << EOF
481 ein.bahn=strasse
484 test_expect_success 'alternative GIT_CONFIG' '
485 GIT_CONFIG=other-config git config --list >output &&
486 test_cmp expect output
489 test_expect_success 'alternative GIT_CONFIG (--file)' '
490 git config --file other-config --list >output &&
491 test_cmp expect output
494 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
495 git config --file - --list <other-config >output &&
496 test_cmp expect output
499 test_expect_success 'setting a value in stdin is an error' '
500 test_must_fail git config --file - some.value foo
503 test_expect_success 'editing stdin is an error' '
504 test_must_fail git config --file - --edit
507 test_expect_success 'refer config from subdirectory' '
508 mkdir x &&
509 test_cmp_config -C x strasse --get --file ../other-config ein.bahn
512 test_expect_success 'refer config from subdirectory via --file' '
513 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
516 cat > expect << EOF
517 [ein]
518 bahn = strasse
519 [anwohner]
520 park = ausweis
523 test_expect_success '--set in alternative file' '
524 git config --file=other-config anwohner.park ausweis &&
525 test_cmp expect other-config
528 cat > .git/config << EOF
529 # Hallo
530 #Bello
531 [branch "eins"]
532 x = 1
533 [branch.eins]
534 y = 1
535 [branch "1 234 blabl/a"]
536 weird
539 test_expect_success 'rename section' '
540 git config --rename-section branch.eins branch.zwei
543 cat > expect << EOF
544 # Hallo
545 #Bello
546 [branch "zwei"]
547 x = 1
548 [branch "zwei"]
549 y = 1
550 [branch "1 234 blabl/a"]
551 weird
554 test_expect_success 'rename succeeded' '
555 test_cmp expect .git/config
558 test_expect_success 'rename non-existing section' '
559 test_must_fail git config --rename-section \
560 branch."world domination" branch.drei
563 test_expect_success 'rename succeeded' '
564 test_cmp expect .git/config
567 test_expect_success 'rename another section' '
568 git config --rename-section branch."1 234 blabl/a" branch.drei
571 cat > expect << EOF
572 # Hallo
573 #Bello
574 [branch "zwei"]
575 x = 1
576 [branch "zwei"]
577 y = 1
578 [branch "drei"]
579 weird
582 test_expect_success 'rename succeeded' '
583 test_cmp expect .git/config
586 cat >> .git/config << EOF
587 [branch "vier"] z = 1
590 test_expect_success 'rename a section with a var on the same line' '
591 git config --rename-section branch.vier branch.zwei
594 cat > expect << EOF
595 # Hallo
596 #Bello
597 [branch "zwei"]
598 x = 1
599 [branch "zwei"]
600 y = 1
601 [branch "drei"]
602 weird
603 [branch "zwei"]
604 z = 1
607 test_expect_success 'rename succeeded' '
608 test_cmp expect .git/config
611 test_expect_success 'renaming empty section name is rejected' '
612 test_must_fail git config --rename-section branch.zwei ""
615 test_expect_success 'renaming to bogus section is rejected' '
616 test_must_fail git config --rename-section branch.zwei "bogus name"
619 cat >> .git/config << EOF
620 [branch "zwei"] a = 1 [branch "vier"]
623 test_expect_success 'remove section' '
624 git config --remove-section branch.zwei
627 cat > expect << EOF
628 # Hallo
629 #Bello
630 [branch "drei"]
631 weird
634 test_expect_success 'section was removed properly' '
635 test_cmp expect .git/config
638 cat > expect << EOF
639 [gitcvs]
640 enabled = true
641 dbname = %Ggitcvs2.%a.%m.sqlite
642 [gitcvs "ext"]
643 dbname = %Ggitcvs1.%a.%m.sqlite
646 test_expect_success 'section ending' '
647 rm -f .git/config &&
648 git config gitcvs.enabled true &&
649 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
650 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
651 test_cmp expect .git/config
655 test_expect_success numbers '
656 git config kilo.gram 1k &&
657 git config mega.ton 1m &&
658 echo 1024 >expect &&
659 echo 1048576 >>expect &&
660 git config --int --get kilo.gram >actual &&
661 git config --int --get mega.ton >>actual &&
662 test_cmp expect actual
665 test_expect_success '--int is at least 64 bits' '
666 git config giga.watts 121g &&
667 echo >expect &&
668 test_cmp_config 129922760704 --int --get giga.watts
671 test_expect_success 'invalid unit' '
672 git config aninvalid.unit "1auto" &&
673 test_cmp_config 1auto aninvalid.unit &&
674 test_must_fail git config --int --get aninvalid.unit 2>actual &&
675 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
678 test_expect_success 'line number is reported correctly' '
679 printf "[bool]\n\tvar\n" >invalid &&
680 test_must_fail git config -f invalid --path bool.var 2>actual &&
681 test_i18ngrep "line 2" actual
684 test_expect_success 'invalid stdin config' '
685 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
686 test_i18ngrep "bad config line 1 in standard input" output
689 cat > expect << EOF
690 true
691 false
692 true
693 false
694 true
695 false
696 true
697 false
700 test_expect_success bool '
702 git config bool.true1 01 &&
703 git config bool.true2 -1 &&
704 git config bool.true3 YeS &&
705 git config bool.true4 true &&
706 git config bool.false1 000 &&
707 git config bool.false2 "" &&
708 git config bool.false3 nO &&
709 git config bool.false4 FALSE &&
710 rm -f result &&
711 for i in 1 2 3 4
713 git config --bool --get bool.true$i >>result
714 git config --bool --get bool.false$i >>result
715 done &&
716 test_cmp expect result'
718 test_expect_success 'invalid bool (--get)' '
720 git config bool.nobool foobar &&
721 test_must_fail git config --bool --get bool.nobool'
723 test_expect_success 'invalid bool (set)' '
725 test_must_fail git config --bool bool.nobool foobar'
727 cat > expect <<\EOF
728 [bool]
729 true1 = true
730 true2 = true
731 true3 = true
732 true4 = true
733 false1 = false
734 false2 = false
735 false3 = false
736 false4 = false
739 test_expect_success 'set --bool' '
741 rm -f .git/config &&
742 git config --bool bool.true1 01 &&
743 git config --bool bool.true2 -1 &&
744 git config --bool bool.true3 YeS &&
745 git config --bool bool.true4 true &&
746 git config --bool bool.false1 000 &&
747 git config --bool bool.false2 "" &&
748 git config --bool bool.false3 nO &&
749 git config --bool bool.false4 FALSE &&
750 test_cmp expect .git/config'
752 cat > expect <<\EOF
753 [int]
754 val1 = 1
755 val2 = -1
756 val3 = 5242880
759 test_expect_success 'set --int' '
761 rm -f .git/config &&
762 git config --int int.val1 01 &&
763 git config --int int.val2 -1 &&
764 git config --int int.val3 5m &&
765 test_cmp expect .git/config
768 test_expect_success 'get --bool-or-int' '
769 cat >.git/config <<-\EOF &&
770 [bool]
771 true1
772 true2 = true
773 false = false
774 [int]
775 int1 = 0
776 int2 = 1
777 int3 = -1
779 cat >expect <<-\EOF &&
780 true
781 true
782 false
788 git config --bool-or-int bool.true1 &&
789 git config --bool-or-int bool.true2 &&
790 git config --bool-or-int bool.false &&
791 git config --bool-or-int int.int1 &&
792 git config --bool-or-int int.int2 &&
793 git config --bool-or-int int.int3
794 } >actual &&
795 test_cmp expect actual
798 cat >expect <<\EOF
799 [bool]
800 true1 = true
801 false1 = false
802 true2 = true
803 false2 = false
804 [int]
805 int1 = 0
806 int2 = 1
807 int3 = -1
810 test_expect_success 'set --bool-or-int' '
811 rm -f .git/config &&
812 git config --bool-or-int bool.true1 true &&
813 git config --bool-or-int bool.false1 false &&
814 git config --bool-or-int bool.true2 yes &&
815 git config --bool-or-int bool.false2 no &&
816 git config --bool-or-int int.int1 0 &&
817 git config --bool-or-int int.int2 1 &&
818 git config --bool-or-int int.int3 -1 &&
819 test_cmp expect .git/config
822 cat >expect <<\EOF
823 [path]
824 home = ~/
825 normal = /dev/null
826 trailingtilde = foo~
829 test_expect_success !MINGW 'set --path' '
830 rm -f .git/config &&
831 git config --path path.home "~/" &&
832 git config --path path.normal "/dev/null" &&
833 git config --path path.trailingtilde "foo~" &&
834 test_cmp expect .git/config'
836 if test_have_prereq !MINGW && test "${HOME+set}"
837 then
838 test_set_prereq HOMEVAR
841 cat >expect <<EOF
842 $HOME/
843 /dev/null
844 foo~
847 test_expect_success HOMEVAR 'get --path' '
848 git config --get --path path.home > result &&
849 git config --get --path path.normal >> result &&
850 git config --get --path path.trailingtilde >> result &&
851 test_cmp expect result
854 cat >expect <<\EOF
855 /dev/null
856 foo~
859 test_expect_success !MINGW 'get --path copes with unset $HOME' '
861 sane_unset HOME &&
862 test_must_fail git config --get --path path.home \
863 >result 2>msg &&
864 git config --get --path path.normal >>result &&
865 git config --get --path path.trailingtilde >>result
866 ) &&
867 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
868 test_cmp expect result
871 test_expect_success 'get --path barfs on boolean variable' '
872 echo "[path]bool" >.git/config &&
873 test_must_fail git config --get --path path.bool
876 test_expect_success 'get --expiry-date' '
877 rel="3.weeks.5.days.00:00" &&
878 rel_out="$rel ->" &&
879 cat >.git/config <<-\EOF &&
880 [date]
881 valid1 = "3.weeks.5.days 00:00"
882 valid2 = "Fri Jun 4 15:46:55 2010"
883 valid3 = "2017/11/11 11:11:11PM"
884 valid4 = "2017/11/10 09:08:07 PM"
885 valid5 = "never"
886 invalid1 = "abc"
888 cat >expect <<-EOF &&
889 $(test-tool date timestamp $rel)
890 1275666415
891 1510441871
892 1510348087
895 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
897 echo "$rel_out $(git config --expiry-date date.valid1)"
898 git config --expiry-date date.valid2 &&
899 git config --expiry-date date.valid3 &&
900 git config --expiry-date date.valid4 &&
901 git config --expiry-date date.valid5
902 } >actual &&
903 test_cmp expect actual &&
904 test_must_fail git config --expiry-date date.invalid1
907 test_expect_success 'get --type=color' '
908 rm .git/config &&
909 git config foo.color "red" &&
910 git config --get --type=color foo.color >actual.raw &&
911 test_decode_color <actual.raw >actual &&
912 echo "<RED>" >expect &&
913 test_cmp expect actual
916 cat >expect << EOF
917 [foo]
918 color = red
921 test_expect_success 'set --type=color' '
922 rm .git/config &&
923 git config --type=color foo.color "red" &&
924 test_cmp expect .git/config
927 test_expect_success 'get --type=color barfs on non-color' '
928 echo "[foo]bar=not-a-color" >.git/config &&
929 test_must_fail git config --get --type=color foo.bar
932 test_expect_success 'set --type=color barfs on non-color' '
933 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
934 test_i18ngrep "cannot parse color" error
937 cat > expect << EOF
938 [quote]
939 leading = " test"
940 ending = "test "
941 semicolon = "test;test"
942 hash = "test#test"
944 test_expect_success 'quoting' '
945 rm -f .git/config &&
946 git config quote.leading " test" &&
947 git config quote.ending "test " &&
948 git config quote.semicolon "test;test" &&
949 git config quote.hash "test#test" &&
950 test_cmp expect .git/config
953 test_expect_success 'key with newline' '
954 test_must_fail git config "key.with
955 newline" 123'
957 test_expect_success 'value with newline' 'git config key.sub value.with\\\
958 newline'
960 cat > .git/config <<\EOF
961 [section]
962 ; comment \
963 continued = cont\
964 inued
965 noncont = not continued ; \
966 quotecont = "cont;\
967 inued"
970 cat > expect <<\EOF
971 section.continued=continued
972 section.noncont=not continued
973 section.quotecont=cont;inued
976 test_expect_success 'value continued on next line' '
977 git config --list > result &&
978 test_cmp expect result
981 cat > .git/config <<\EOF
982 [section "sub=section"]
983 val1 = foo=bar
984 val2 = foo\nbar
985 val3 = \n\n
986 val4 =
987 val5
990 cat > expect <<\EOF
991 section.sub=section.val1
992 foo=barQsection.sub=section.val2
994 barQsection.sub=section.val3
997 Qsection.sub=section.val4
998 Qsection.sub=section.val5Q
1000 test_expect_success '--null --list' '
1001 git config --null --list >result.raw &&
1002 nul_to_q <result.raw >result &&
1003 echo >>result &&
1004 test_cmp expect result
1007 test_expect_success '--null --get-regexp' '
1008 git config --null --get-regexp "val[0-9]" >result.raw &&
1009 nul_to_q <result.raw >result &&
1010 echo >>result &&
1011 test_cmp expect result
1014 test_expect_success 'inner whitespace kept verbatim' '
1015 git config section.val "foo bar" &&
1016 test_cmp_config "foo bar" section.val
1019 test_expect_success SYMLINKS 'symlinked configuration' '
1020 ln -s notyet myconfig &&
1021 git config --file=myconfig test.frotz nitfol &&
1022 test -h myconfig &&
1023 test -f notyet &&
1024 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1025 git config --file=myconfig test.xyzzy rezrov &&
1026 test -h myconfig &&
1027 test -f notyet &&
1028 cat >expect <<-\EOF &&
1029 nitfol
1030 rezrov
1033 git config --file=notyet test.frotz &&
1034 git config --file=notyet test.xyzzy
1035 } >actual &&
1036 test_cmp expect actual
1039 test_expect_success 'nonexistent configuration' '
1040 test_must_fail git config --file=doesnotexist --list &&
1041 test_must_fail git config --file=doesnotexist test.xyzzy
1044 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1045 ln -s doesnotexist linktonada &&
1046 ln -s linktonada linktolinktonada &&
1047 test_must_fail git config --file=linktonada --list &&
1048 test_must_fail git config --file=linktolinktonada --list
1051 test_expect_success 'check split_cmdline return' "
1052 git config alias.split-cmdline-fix 'echo \"' &&
1053 test_must_fail git split-cmdline-fix &&
1054 echo foo > foo &&
1055 git add foo &&
1056 git commit -m 'initial commit' &&
1057 git config branch.master.mergeoptions 'echo \"' &&
1058 test_must_fail git merge master
1061 test_expect_success 'git -c "key=value" support' '
1062 cat >expect <<-\EOF &&
1063 value
1064 value
1065 true
1068 git -c core.name=value config core.name &&
1069 git -c foo.CamelCase=value config foo.camelcase &&
1070 git -c foo.flag config --bool foo.flag
1071 } >actual &&
1072 test_cmp expect actual &&
1073 test_must_fail git -c name=value config core.name
1076 # We just need a type-specifier here that cares about the
1077 # distinction internally between a NULL boolean and a real
1078 # string (because most of git's internal parsers do care).
1079 # Using "--path" works, but we do not otherwise care about
1080 # its semantics.
1081 test_expect_success 'git -c can represent empty string' '
1082 echo >expect &&
1083 git -c foo.empty= config --path foo.empty >actual &&
1084 test_cmp expect actual
1087 test_expect_success 'key sanity-checking' '
1088 test_must_fail git config foo=bar &&
1089 test_must_fail git config foo=.bar &&
1090 test_must_fail git config foo.ba=r &&
1091 test_must_fail git config foo.1bar &&
1092 test_must_fail git config foo."ba
1093 z".bar &&
1094 test_must_fail git config . false &&
1095 test_must_fail git config .foo false &&
1096 test_must_fail git config foo. false &&
1097 test_must_fail git config .foo. false &&
1098 git config foo.bar true &&
1099 git config foo."ba =z".bar false
1102 test_expect_success 'git -c works with aliases of builtins' '
1103 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1104 echo bar >expect &&
1105 git checkconfig >actual &&
1106 test_cmp expect actual
1109 test_expect_success 'aliases can be CamelCased' '
1110 test_config alias.CamelCased "rev-parse HEAD" &&
1111 git CamelCased >out &&
1112 git rev-parse HEAD >expect &&
1113 test_cmp expect out
1116 test_expect_success 'git -c does not split values on equals' '
1117 echo "value with = in it" >expect &&
1118 git -c core.foo="value with = in it" config core.foo >actual &&
1119 test_cmp expect actual
1122 test_expect_success 'git -c dies on bogus config' '
1123 test_must_fail git -c core.bare=foo rev-parse
1126 test_expect_success 'git -c complains about empty key' '
1127 test_must_fail git -c "=foo" rev-parse
1130 test_expect_success 'git -c complains about empty key and value' '
1131 test_must_fail git -c "" rev-parse
1134 test_expect_success 'multiple git -c appends config' '
1135 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1136 cat >expect <<-\EOF &&
1137 x.one 1
1138 x.two 2
1140 git -c x.one=1 x >actual &&
1141 test_cmp expect actual
1144 test_expect_success 'last one wins: two level vars' '
1146 # sec.var and sec.VAR are the same variable, as the first
1147 # and the last level of a configuration variable name is
1148 # case insensitive.
1150 echo VAL >expect &&
1152 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1153 test_cmp expect actual &&
1154 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1155 test_cmp expect actual &&
1157 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1158 test_cmp expect actual &&
1159 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1160 test_cmp expect actual
1163 test_expect_success 'last one wins: three level vars' '
1165 # v.a.r and v.A.r are not the same variable, as the middle
1166 # level of a three-level configuration variable name is
1167 # case sensitive.
1169 echo val >expect &&
1170 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1171 test_cmp expect actual &&
1172 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1173 test_cmp expect actual &&
1175 # v.a.r and V.a.R are the same variable, as the first
1176 # and the last level of a configuration variable name is
1177 # case insensitive.
1179 echo VAL >expect &&
1180 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1181 test_cmp expect actual &&
1182 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1183 test_cmp expect actual &&
1184 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1185 test_cmp expect actual &&
1186 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1187 test_cmp expect actual
1190 test_expect_success 'old-fashioned settings are case insensitive' '
1191 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1193 cat >testConfig_actual <<-EOF &&
1194 [V.A]
1195 r = value1
1197 q_to_tab >testConfig_expect <<-EOF &&
1198 [V.A]
1199 Qr = value2
1201 git config -f testConfig_actual "v.a.r" value2 &&
1202 test_cmp testConfig_expect testConfig_actual &&
1204 cat >testConfig_actual <<-EOF &&
1205 [V.A]
1206 r = value1
1208 q_to_tab >testConfig_expect <<-EOF &&
1209 [V.A]
1210 QR = value2
1212 git config -f testConfig_actual "V.a.R" value2 &&
1213 test_cmp testConfig_expect testConfig_actual &&
1215 cat >testConfig_actual <<-EOF &&
1216 [V.A]
1217 r = value1
1219 q_to_tab >testConfig_expect <<-EOF &&
1220 [V.A]
1221 r = value1
1222 Qr = value2
1224 git config -f testConfig_actual "V.A.r" value2 &&
1225 test_cmp testConfig_expect testConfig_actual &&
1227 cat >testConfig_actual <<-EOF &&
1228 [V.A]
1229 r = value1
1231 q_to_tab >testConfig_expect <<-EOF &&
1232 [V.A]
1233 r = value1
1234 Qr = value2
1236 git config -f testConfig_actual "v.A.r" value2 &&
1237 test_cmp testConfig_expect testConfig_actual
1240 test_expect_success 'setting different case sensitive subsections ' '
1241 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1243 cat >testConfig_actual <<-EOF &&
1244 [V "A"]
1245 R = v1
1246 [K "E"]
1247 Y = v1
1248 [a "b"]
1249 c = v1
1250 [d "e"]
1251 f = v1
1253 q_to_tab >testConfig_expect <<-EOF &&
1254 [V "A"]
1255 Qr = v2
1256 [K "E"]
1257 Qy = v2
1258 [a "b"]
1259 Qc = v2
1260 [d "e"]
1261 f = v1
1262 [d "E"]
1263 Qf = v2
1265 # exact match
1266 git config -f testConfig_actual a.b.c v2 &&
1267 # match section and subsection, key is cased differently.
1268 git config -f testConfig_actual K.E.y v2 &&
1269 # section and key are matched case insensitive, but subsection needs
1270 # to match; When writing out new values only the key is adjusted
1271 git config -f testConfig_actual v.A.r v2 &&
1272 # subsection is not matched:
1273 git config -f testConfig_actual d.E.f v2 &&
1274 test_cmp testConfig_expect testConfig_actual
1277 for VAR in a .a a. a.0b a."b c". a."b c".0d
1279 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1280 test_must_fail git -c "$VAR=VAL" config -l
1282 done
1284 for VAR in a.b a."b c".d
1286 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1287 echo VAL >expect &&
1288 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1289 test_cmp expect actual
1291 done
1293 test_expect_success 'git -c is not confused by empty environment' '
1294 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1297 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1298 cat >expect <<-\EOF &&
1299 env.one one
1300 env.two two
1302 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1303 git config --get-regexp "env.*" >actual &&
1304 test_cmp expect actual &&
1306 cat >expect <<-EOF &&
1307 env.one one${SQ}
1308 env.two two
1310 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1311 git config --get-regexp "env.*" >actual &&
1312 test_cmp expect actual &&
1314 test_must_fail env \
1315 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1316 git config --get-regexp "env.*"
1319 test_expect_success 'git config --edit works' '
1320 git config -f tmp test.value no &&
1321 echo test.value=yes >expect &&
1322 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1323 git config -f tmp --list >actual &&
1324 test_cmp expect actual
1327 test_expect_success 'git config --edit respects core.editor' '
1328 git config -f tmp test.value no &&
1329 echo test.value=yes >expect &&
1330 test_config core.editor "echo [test]value=yes >" &&
1331 git config -f tmp --edit &&
1332 git config -f tmp --list >actual &&
1333 test_cmp expect actual
1336 # malformed configuration files
1337 test_expect_success 'barf on syntax error' '
1338 cat >.git/config <<-\EOF &&
1339 # broken section line
1340 [section]
1341 key garbage
1343 test_must_fail git config --get section.key >actual 2>error &&
1344 test_i18ngrep " line 3 " error
1347 test_expect_success 'barf on incomplete section header' '
1348 cat >.git/config <<-\EOF &&
1349 # broken section line
1350 [section
1351 key = value
1353 test_must_fail git config --get section.key >actual 2>error &&
1354 test_i18ngrep " line 2 " error
1357 test_expect_success 'barf on incomplete string' '
1358 cat >.git/config <<-\EOF &&
1359 # broken section line
1360 [section]
1361 key = "value string
1363 test_must_fail git config --get section.key >actual 2>error &&
1364 test_i18ngrep " line 3 " error
1367 test_expect_success 'urlmatch' '
1368 cat >.git/config <<-\EOF &&
1369 [http]
1370 sslVerify
1371 [http "https://weak.example.com"]
1372 sslVerify = false
1373 cookieFile = /tmp/cookie.txt
1376 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1377 test_must_be_empty actual &&
1379 echo true >expect &&
1380 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1381 test_cmp expect actual &&
1383 echo false >expect &&
1384 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1385 test_cmp expect actual &&
1388 echo http.cookiefile /tmp/cookie.txt &&
1389 echo http.sslverify false
1390 } >expect &&
1391 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1392 test_cmp expect actual
1395 test_expect_success 'urlmatch favors more specific URLs' '
1396 cat >.git/config <<-\EOF &&
1397 [http "https://example.com/"]
1398 cookieFile = /tmp/root.txt
1399 [http "https://example.com/subdirectory"]
1400 cookieFile = /tmp/subdirectory.txt
1401 [http "https://user@example.com/"]
1402 cookieFile = /tmp/user.txt
1403 [http "https://averylonguser@example.com/"]
1404 cookieFile = /tmp/averylonguser.txt
1405 [http "https://preceding.example.com"]
1406 cookieFile = /tmp/preceding.txt
1407 [http "https://*.example.com"]
1408 cookieFile = /tmp/wildcard.txt
1409 [http "https://*.example.com/wildcardwithsubdomain"]
1410 cookieFile = /tmp/wildcardwithsubdomain.txt
1411 [http "https://*.example.*"]
1412 cookieFile = /tmp/multiwildcard.txt
1413 [http "https://trailing.example.com"]
1414 cookieFile = /tmp/trailing.txt
1415 [http "https://user@*.example.com/"]
1416 cookieFile = /tmp/wildcardwithuser.txt
1417 [http "https://sub.example.com/"]
1418 cookieFile = /tmp/sub.txt
1421 echo http.cookiefile /tmp/root.txt >expect &&
1422 git config --get-urlmatch HTTP https://example.com >actual &&
1423 test_cmp expect actual &&
1425 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1426 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1427 test_cmp expect actual &&
1429 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1430 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1431 test_cmp expect actual &&
1433 echo http.cookiefile /tmp/user.txt >expect &&
1434 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1435 test_cmp expect actual &&
1437 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1438 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1439 test_cmp expect actual &&
1441 echo http.cookiefile /tmp/preceding.txt >expect &&
1442 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1443 test_cmp expect actual &&
1445 echo http.cookiefile /tmp/wildcard.txt >expect &&
1446 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1447 test_cmp expect actual &&
1449 echo http.cookiefile /tmp/sub.txt >expect &&
1450 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1451 test_cmp expect actual &&
1453 echo http.cookiefile /tmp/trailing.txt >expect &&
1454 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1455 test_cmp expect actual &&
1457 echo http.cookiefile /tmp/sub.txt >expect &&
1458 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1459 test_cmp expect actual &&
1461 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1462 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1463 test_cmp expect actual
1466 test_expect_success 'urlmatch with wildcard' '
1467 cat >.git/config <<-\EOF &&
1468 [http]
1469 sslVerify
1470 [http "https://*.example.com"]
1471 sslVerify = false
1472 cookieFile = /tmp/cookie.txt
1475 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1476 test_must_be_empty actual &&
1478 echo true >expect &&
1479 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1480 test_cmp expect actual &&
1482 echo true >expect &&
1483 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1484 test_cmp expect actual &&
1486 echo true >expect &&
1487 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1488 test_cmp expect actual &&
1490 echo false >expect &&
1491 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1492 test_cmp expect actual &&
1495 echo http.cookiefile /tmp/cookie.txt &&
1496 echo http.sslverify false
1497 } >expect &&
1498 git config --get-urlmatch HTTP https://good.example.com >actual &&
1499 test_cmp expect actual &&
1501 echo http.sslverify >expect &&
1502 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1503 test_cmp expect actual
1506 # good section hygiene
1507 test_expect_success '--unset last key removes section (except if commented)' '
1508 cat >.git/config <<-\EOF &&
1509 # some generic comment on the configuration file itself
1510 # a comment specific to this "section" section.
1511 [section]
1512 # some intervening lines
1513 # that should also be dropped
1515 key = value
1516 # please be careful when you update the above variable
1519 cat >expect <<-\EOF &&
1520 # some generic comment on the configuration file itself
1521 # a comment specific to this "section" section.
1522 [section]
1523 # some intervening lines
1524 # that should also be dropped
1526 # please be careful when you update the above variable
1529 git config --unset section.key &&
1530 test_cmp expect .git/config &&
1532 cat >.git/config <<-\EOF &&
1533 [section]
1534 key = value
1535 [next-section]
1538 cat >expect <<-\EOF &&
1539 [next-section]
1542 git config --unset section.key &&
1543 test_cmp expect .git/config &&
1545 q_to_tab >.git/config <<-\EOF &&
1546 [one]
1547 Qkey = "multiline \
1548 QQ# with comment"
1549 [two]
1550 key = true
1552 git config --unset two.key &&
1553 ! grep two .git/config &&
1555 q_to_tab >.git/config <<-\EOF &&
1556 [one]
1557 Qkey = "multiline \
1558 QQ# with comment"
1559 [one]
1560 key = true
1562 git config --unset-all one.key &&
1563 test_line_count = 0 .git/config &&
1565 q_to_tab >.git/config <<-\EOF &&
1566 [one]
1567 Qkey = true
1568 Q# a comment not at the start
1569 [two]
1570 Qkey = true
1572 git config --unset two.key &&
1573 grep two .git/config &&
1575 q_to_tab >.git/config <<-\EOF &&
1576 [one]
1577 Qkey = not [two "subsection"]
1578 [two "subsection"]
1579 [two "subsection"]
1580 Qkey = true
1581 [TWO "subsection"]
1582 [one]
1584 git config --unset two.subsection.key &&
1585 test "not [two subsection]" = "$(git config one.key)" &&
1586 test_line_count = 3 .git/config
1589 test_expect_success '--unset-all removes section if empty & uncommented' '
1590 cat >.git/config <<-\EOF &&
1591 [section]
1592 key = value1
1593 key = value2
1596 git config --unset-all section.key &&
1597 test_line_count = 0 .git/config
1600 test_expect_success 'adding a key into an empty section reuses header' '
1601 cat >.git/config <<-\EOF &&
1602 [section]
1605 q_to_tab >expect <<-\EOF &&
1606 [section]
1607 Qkey = value
1610 git config section.key value &&
1611 test_cmp expect .git/config
1614 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1615 chmod 0600 .git/config &&
1616 git config imap.pass Hunter2 &&
1617 perl -e \
1618 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1619 git config --rename-section imap pop &&
1620 perl -e \
1621 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1624 ! test_have_prereq MINGW ||
1625 HOME="$(pwd)" # convert to Windows path
1627 test_expect_success 'set up --show-origin tests' '
1628 INCLUDE_DIR="$HOME/include" &&
1629 mkdir -p "$INCLUDE_DIR" &&
1630 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1631 [user]
1632 absolute = include
1634 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1635 [user]
1636 relative = include
1638 cat >"$HOME"/.gitconfig <<-EOF &&
1639 [user]
1640 global = true
1641 override = global
1642 [include]
1643 path = "$INCLUDE_DIR/absolute.include"
1645 cat >.git/config <<-\EOF
1646 [user]
1647 local = true
1648 override = local
1649 [include]
1650 path = ../include/relative.include
1654 test_expect_success '--show-origin with --list' '
1655 cat >expect <<-EOF &&
1656 file:$HOME/.gitconfig user.global=true
1657 file:$HOME/.gitconfig user.override=global
1658 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1659 file:$INCLUDE_DIR/absolute.include user.absolute=include
1660 file:.git/config user.local=true
1661 file:.git/config user.override=local
1662 file:.git/config include.path=../include/relative.include
1663 file:.git/../include/relative.include user.relative=include
1664 command line: user.cmdline=true
1666 git -c user.cmdline=true config --list --show-origin >output &&
1667 test_cmp expect output
1670 test_expect_success '--show-origin with --list --null' '
1671 cat >expect <<-EOF &&
1672 file:$HOME/.gitconfigQuser.global
1673 trueQfile:$HOME/.gitconfigQuser.override
1674 globalQfile:$HOME/.gitconfigQinclude.path
1675 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1676 includeQfile:.git/configQuser.local
1677 trueQfile:.git/configQuser.override
1678 localQfile:.git/configQinclude.path
1679 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1680 includeQcommand line:Quser.cmdline
1681 trueQ
1683 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1684 nul_to_q <output.raw >output &&
1685 # The here-doc above adds a newline that the --null output would not
1686 # include. Add it here to make the two comparable.
1687 echo >>output &&
1688 test_cmp expect output
1691 test_expect_success '--show-origin with single file' '
1692 cat >expect <<-\EOF &&
1693 file:.git/config user.local=true
1694 file:.git/config user.override=local
1695 file:.git/config include.path=../include/relative.include
1697 git config --local --list --show-origin >output &&
1698 test_cmp expect output
1701 test_expect_success '--show-origin with --get-regexp' '
1702 cat >expect <<-EOF &&
1703 file:$HOME/.gitconfig user.global true
1704 file:.git/config user.local true
1706 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1707 test_cmp expect output
1710 test_expect_success '--show-origin getting a single key' '
1711 cat >expect <<-\EOF &&
1712 file:.git/config local
1714 git config --show-origin user.override >output &&
1715 test_cmp expect output
1718 test_expect_success 'set up custom config file' '
1719 CUSTOM_CONFIG_FILE="custom.conf" &&
1720 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1721 [user]
1722 custom = true
1726 test_expect_success !MINGW 'set up custom config file with special name characters' '
1727 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
1728 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
1731 test_expect_success !MINGW '--show-origin escape special file name characters' '
1732 cat >expect <<-\EOF &&
1733 file:"file\" (dq) and spaces.conf" user.custom=true
1735 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
1736 test_cmp expect output
1739 test_expect_success '--show-origin stdin' '
1740 cat >expect <<-\EOF &&
1741 standard input: user.custom=true
1743 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1744 test_cmp expect output
1747 test_expect_success '--show-origin stdin with file include' '
1748 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1749 [user]
1750 stdin = include
1752 cat >expect <<-EOF &&
1753 file:$INCLUDE_DIR/stdin.include include
1755 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
1756 git config --show-origin --includes --file - user.stdin >output &&
1758 test_cmp expect output
1761 test_expect_success '--show-origin blob' '
1762 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1763 cat >expect <<-EOF &&
1764 blob:$blob user.custom=true
1766 git config --blob=$blob --show-origin --list >output &&
1767 test_cmp expect output
1770 test_expect_success '--show-origin blob ref' '
1771 cat >expect <<-\EOF &&
1772 blob:master:custom.conf user.custom=true
1774 git add "$CUSTOM_CONFIG_FILE" &&
1775 git commit -m "new config file" &&
1776 git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1777 test_cmp expect output
1780 test_expect_success '--show-scope with --list' '
1781 cat >expect <<-EOF &&
1782 global user.global=true
1783 global user.override=global
1784 global include.path=$INCLUDE_DIR/absolute.include
1785 global user.absolute=include
1786 local user.local=true
1787 local user.override=local
1788 local include.path=../include/relative.include
1789 local user.relative=include
1790 command user.cmdline=true
1792 git -c user.cmdline=true config --list --show-scope >output &&
1793 test_cmp expect output
1796 test_expect_success !MINGW '--show-scope with --blob' '
1797 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1798 cat >expect <<-EOF &&
1799 command user.custom=true
1801 git config --blob=$blob --show-scope --list >output &&
1802 test_cmp expect output
1805 test_expect_success '--show-scope with --local' '
1806 cat >expect <<-\EOF &&
1807 local user.local=true
1808 local user.override=local
1809 local include.path=../include/relative.include
1811 git config --local --list --show-scope >output &&
1812 test_cmp expect output
1815 test_expect_success '--show-scope getting a single value' '
1816 cat >expect <<-\EOF &&
1817 local true
1819 git config --show-scope --get user.local >output &&
1820 test_cmp expect output
1823 test_expect_success '--show-scope with --show-origin' '
1824 cat >expect <<-EOF &&
1825 global file:$HOME/.gitconfig user.global=true
1826 global file:$HOME/.gitconfig user.override=global
1827 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1828 global file:$INCLUDE_DIR/absolute.include user.absolute=include
1829 local file:.git/config user.local=true
1830 local file:.git/config user.override=local
1831 local file:.git/config include.path=../include/relative.include
1832 local file:.git/../include/relative.include user.relative=include
1833 command command line: user.cmdline=true
1835 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
1836 test_cmp expect output
1839 test_expect_success '--local requires a repo' '
1840 # we expect 128 to ensure that we do not simply
1841 # fail to find anything and return code "1"
1842 test_expect_code 128 nongit git config --local foo.bar
1845 cat >.git/config <<-\EOF &&
1846 [core]
1847 foo = true
1848 number = 10
1849 big = 1M
1852 test_expect_success 'identical modern --type specifiers are allowed' '
1853 test_cmp_config 1048576 --type=int --type=int core.big
1856 test_expect_success 'identical legacy --type specifiers are allowed' '
1857 test_cmp_config 1048576 --int --int core.big
1860 test_expect_success 'identical mixed --type specifiers are allowed' '
1861 test_cmp_config 1048576 --int --type=int core.big
1864 test_expect_success 'non-identical modern --type specifiers are not allowed' '
1865 test_must_fail git config --type=int --type=bool core.big 2>error &&
1866 test_i18ngrep "only one type at a time" error
1869 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
1870 test_must_fail git config --int --bool core.big 2>error &&
1871 test_i18ngrep "only one type at a time" error
1874 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
1875 test_must_fail git config --type=int --bool core.big 2>error &&
1876 test_i18ngrep "only one type at a time" error
1879 test_expect_success '--type allows valid type specifiers' '
1880 test_cmp_config true --type=bool core.foo
1883 test_expect_success '--no-type unsets type specifiers' '
1884 test_cmp_config 10 --type=bool --no-type core.number
1887 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
1888 test_cmp_config 1048576 --type=bool --no-type --type=int core.big
1891 test_expect_success '--type rejects unknown specifiers' '
1892 test_must_fail git config --type=nonsense core.foo 2>error &&
1893 test_i18ngrep "unrecognized --type argument" error
1896 test_expect_success '--replace-all does not invent newlines' '
1897 q_to_tab >.git/config <<-\EOF &&
1898 [abc]key
1899 QkeepSection
1900 [xyz]
1901 Qkey = 1
1902 [abc]
1903 Qkey = a
1905 q_to_tab >expect <<-\EOF &&
1906 [abc]
1907 QkeepSection
1908 [xyz]
1909 Qkey = 1
1910 [abc]
1911 Qkey = b
1913 git config --replace-all abc.key b &&
1914 test_cmp expect .git/config
1917 test_done