git.txt: fix monospace rendering
[git] / t / t1300-config.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Johannes Schindelin
4 #
5
6 test_description='Test git config in different settings'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./test-lib.sh
12
13 test_expect_success 'clear default config' '
14         rm -f .git/config
15 '
16
17 cat > expect << EOF
18 [section]
19         penguin = little blue
20 EOF
21 test_expect_success 'initial' '
22         git config section.penguin "little blue" &&
23         test_cmp expect .git/config
24 '
25
26 cat > expect << EOF
27 [section]
28         penguin = little blue
29         Movie = BadPhysics
30 EOF
31 test_expect_success 'mixed case' '
32         git config Section.Movie BadPhysics &&
33         test_cmp expect .git/config
34 '
35
36 cat > expect << EOF
37 [section]
38         penguin = little blue
39         Movie = BadPhysics
40 [Sections]
41         WhatEver = Second
42 EOF
43 test_expect_success 'similar section' '
44         git config Sections.WhatEver Second &&
45         test_cmp expect .git/config
46 '
47
48 cat > expect << EOF
49 [section]
50         penguin = little blue
51         Movie = BadPhysics
52         UPPERCASE = true
53 [Sections]
54         WhatEver = Second
55 EOF
56 test_expect_success 'uppercase section' '
57         git config SECTION.UPPERCASE true &&
58         test_cmp expect .git/config
59 '
60
61 test_expect_success 'replace with non-match' '
62         git config section.penguin kingpin !blue
63 '
64
65 test_expect_success 'replace with non-match (actually matching)' '
66         git config section.penguin "very blue" !kingpin
67 '
68
69 cat > expect << EOF
70 [section]
71         penguin = very blue
72         Movie = BadPhysics
73         UPPERCASE = true
74         penguin = kingpin
75 [Sections]
76         WhatEver = Second
77 EOF
78
79 test_expect_success 'non-match result' 'test_cmp expect .git/config'
80
81 test_expect_success 'find mixed-case key by canonical name' '
82         test_cmp_config Second sections.whatever
83 '
84
85 test_expect_success 'find mixed-case key by non-canonical name' '
86         test_cmp_config Second SeCtIoNs.WhAtEvEr
87 '
88
89 test_expect_success 'subsections are not canonicalized by git-config' '
90         cat >>.git/config <<-\EOF &&
91         [section.SubSection]
92         key = one
93         [section "SubSection"]
94         key = two
95         EOF
96         test_cmp_config one section.subsection.key &&
97         test_cmp_config two section.SubSection.key
98 '
99
100 cat > .git/config <<\EOF
101 [alpha]
102 bar = foo
103 [beta]
104 baz = multiple \
105 lines
106 foo = bar
107 EOF
108
109 test_expect_success 'unset with cont. lines' '
110         git config --unset beta.baz
111 '
112
113 cat > expect <<\EOF
114 [alpha]
115 bar = foo
116 [beta]
117 foo = bar
118 EOF
119
120 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
121
122 cat > .git/config << EOF
123 [beta] ; silly comment # another comment
124 noIndent= sillyValue ; 'nother silly comment
125
126 # empty line
127                 ; comment
128                 haha   ="beta" # last silly comment
129 haha = hello
130         haha = bello
131 [nextSection] noNewline = ouch
132 EOF
133
134 cp .git/config .git/config2
135
136 test_expect_success 'multiple unset' '
137         git config --unset-all beta.haha
138 '
139
140 cat > expect << EOF
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
143
144 # empty line
145                 ; comment
146 [nextSection] noNewline = ouch
147 EOF
148
149 test_expect_success 'multiple unset is correct' '
150         test_cmp expect .git/config
151 '
152
153 cp .git/config2 .git/config
154
155 test_expect_success '--replace-all missing value' '
156         test_must_fail git config --replace-all beta.haha &&
157         test_cmp .git/config2 .git/config
158 '
159
160 rm .git/config2
161
162 test_expect_success '--replace-all' '
163         git config --replace-all beta.haha gamma
164 '
165
166 cat > expect << EOF
167 [beta] ; silly comment # another comment
168 noIndent= sillyValue ; 'nother silly comment
169
170 # empty line
171                 ; comment
172         haha = gamma
173 [nextSection] noNewline = ouch
174 EOF
175
176 test_expect_success 'all replaced' '
177         test_cmp expect .git/config
178 '
179
180 cat > expect << EOF
181 [beta] ; silly comment # another comment
182 noIndent= sillyValue ; 'nother silly comment
183
184 # empty line
185                 ; comment
186         haha = alpha
187 [nextSection] noNewline = ouch
188 EOF
189 test_expect_success 'really mean test' '
190         git config beta.haha alpha &&
191         test_cmp expect .git/config
192 '
193
194 cat > expect << EOF
195 [beta] ; silly comment # another comment
196 noIndent= sillyValue ; 'nother silly comment
197
198 # empty line
199                 ; comment
200         haha = alpha
201 [nextSection]
202         nonewline = wow
203 EOF
204 test_expect_success 'really really mean test' '
205         git config nextsection.nonewline wow &&
206         test_cmp expect .git/config
207 '
208
209 test_expect_success 'get value' '
210         test_cmp_config alpha beta.haha
211 '
212
213 cat > expect << EOF
214 [beta] ; silly comment # another comment
215 noIndent= sillyValue ; 'nother silly comment
216
217 # empty line
218                 ; comment
219 [nextSection]
220         nonewline = wow
221 EOF
222 test_expect_success 'unset' '
223         git config --unset beta.haha &&
224         test_cmp expect .git/config
225 '
226
227 cat > expect << EOF
228 [beta] ; silly comment # another comment
229 noIndent= sillyValue ; 'nother silly comment
230
231 # empty line
232                 ; comment
233 [nextSection]
234         nonewline = wow
235         NoNewLine = wow2 for me
236 EOF
237 test_expect_success 'multivar' '
238         git config nextsection.NoNewLine "wow2 for me" "for me$" &&
239         test_cmp expect .git/config
240 '
241
242 test_expect_success 'non-match' '
243         git config --get nextsection.nonewline !for
244 '
245
246 test_expect_success 'non-match value' '
247         test_cmp_config wow --get nextsection.nonewline !for
248 '
249
250 test_expect_success 'multi-valued get returns final one' '
251         test_cmp_config "wow2 for me" --get nextsection.nonewline
252 '
253
254 test_expect_success 'multi-valued get-all returns all' '
255         cat >expect <<-\EOF &&
256         wow
257         wow2 for me
258         EOF
259         git config --get-all nextsection.nonewline >actual &&
260         test_cmp expect actual
261 '
262
263 cat > expect << EOF
264 [beta] ; silly comment # another comment
265 noIndent= sillyValue ; 'nother silly comment
266
267 # empty line
268                 ; comment
269 [nextSection]
270         nonewline = wow3
271         NoNewLine = wow2 for me
272 EOF
273 test_expect_success 'multivar replace' '
274         git config nextsection.nonewline "wow3" "wow$" &&
275         test_cmp expect .git/config
276 '
277
278 test_expect_success 'ambiguous unset' '
279         test_must_fail git config --unset nextsection.nonewline
280 '
281
282 test_expect_success 'invalid unset' '
283         test_must_fail git config --unset somesection.nonewline
284 '
285
286 cat > expect << EOF
287 [beta] ; silly comment # another comment
288 noIndent= sillyValue ; 'nother silly comment
289
290 # empty line
291                 ; comment
292 [nextSection]
293         NoNewLine = wow2 for me
294 EOF
295
296 test_expect_success 'multivar unset' '
297         git config --unset nextsection.nonewline "wow3$" &&
298         test_cmp expect .git/config
299 '
300
301 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
302
303 test_expect_success 'correct key' 'git config 123456.a123 987'
304
305 test_expect_success 'hierarchical section' '
306         git config Version.1.2.3eX.Alpha beta
307 '
308
309 cat > expect << EOF
310 [beta] ; silly comment # another comment
311 noIndent= sillyValue ; 'nother silly comment
312
313 # empty line
314                 ; comment
315 [nextSection]
316         NoNewLine = wow2 for me
317 [123456]
318         a123 = 987
319 [Version "1.2.3eX"]
320         Alpha = beta
321 EOF
322
323 test_expect_success 'hierarchical section value' '
324         test_cmp expect .git/config
325 '
326
327 cat > expect << EOF
328 beta.noindent=sillyValue
329 nextsection.nonewline=wow2 for me
330 123456.a123=987
331 version.1.2.3eX.alpha=beta
332 EOF
333
334 test_expect_success 'working --list' '
335         git config --list > output &&
336         test_cmp expect output
337 '
338 test_expect_success '--list without repo produces empty output' '
339         git --git-dir=nonexistent config --list >output &&
340         test_must_be_empty output
341 '
342
343 cat > expect << EOF
344 beta.noindent
345 nextsection.nonewline
346 123456.a123
347 version.1.2.3eX.alpha
348 EOF
349
350 test_expect_success '--name-only --list' '
351         git config --name-only --list >output &&
352         test_cmp expect output
353 '
354
355 cat > expect << EOF
356 beta.noindent sillyValue
357 nextsection.nonewline wow2 for me
358 EOF
359
360 test_expect_success '--get-regexp' '
361         git config --get-regexp in >output &&
362         test_cmp expect output
363 '
364
365 cat > expect << EOF
366 beta.noindent
367 nextsection.nonewline
368 EOF
369
370 test_expect_success '--name-only --get-regexp' '
371         git config --name-only --get-regexp in >output &&
372         test_cmp expect output
373 '
374
375 cat > expect << EOF
376 wow2 for me
377 wow4 for you
378 EOF
379
380 test_expect_success '--add' '
381         git config --add nextsection.nonewline "wow4 for you" &&
382         git config --get-all nextsection.nonewline > output &&
383         test_cmp expect output
384 '
385
386 cat > .git/config << EOF
387 [novalue]
388         variable
389 [emptyvalue]
390         variable =
391 EOF
392
393 test_expect_success 'get variable with no value' '
394         git config --get novalue.variable ^$
395 '
396
397 test_expect_success 'get variable with empty value' '
398         git config --get emptyvalue.variable ^$
399 '
400
401 echo novalue.variable > expect
402
403 test_expect_success 'get-regexp variable with no value' '
404         git config --get-regexp novalue > output &&
405         test_cmp expect output
406 '
407
408 echo 'novalue.variable true' > expect
409
410 test_expect_success 'get-regexp --bool variable with no value' '
411         git config --bool --get-regexp novalue > output &&
412         test_cmp expect output
413 '
414
415 echo 'emptyvalue.variable ' > expect
416
417 test_expect_success 'get-regexp variable with empty value' '
418         git config --get-regexp emptyvalue > output &&
419         test_cmp expect output
420 '
421
422 echo true > expect
423
424 test_expect_success 'get bool variable with no value' '
425         git config --bool novalue.variable > output &&
426         test_cmp expect output
427 '
428
429 echo false > expect
430
431 test_expect_success 'get bool variable with empty value' '
432         git config --bool emptyvalue.variable > output &&
433         test_cmp expect output
434 '
435
436 test_expect_success 'no arguments, but no crash' '
437         test_must_fail git config >output 2>&1 &&
438         test_i18ngrep usage output
439 '
440
441 cat > .git/config << EOF
442 [a.b]
443         c = d
444 EOF
445
446 cat > expect << EOF
447 [a.b]
448         c = d
449 [a]
450         x = y
451 EOF
452
453 test_expect_success 'new section is partial match of another' '
454         git config a.x y &&
455         test_cmp expect .git/config
456 '
457
458 cat > expect << EOF
459 [a.b]
460         c = d
461 [a]
462         x = y
463         b = c
464 [b]
465         x = y
466 EOF
467
468 test_expect_success 'new variable inserts into proper section' '
469         git config b.x y &&
470         git config a.b c &&
471         test_cmp expect .git/config
472 '
473
474 test_expect_success 'alternative --file (non-existing file should fail)' '
475         test_must_fail git config --file non-existing-config -l &&
476         test_must_fail git config --file non-existing-config test.xyzzy
477 '
478
479 cat > other-config << EOF
480 [ein]
481         bahn = strasse
482 EOF
483
484 cat > expect << EOF
485 ein.bahn=strasse
486 EOF
487
488 test_expect_success 'alternative GIT_CONFIG' '
489         GIT_CONFIG=other-config git config --list >output &&
490         test_cmp expect output
491 '
492
493 test_expect_success 'alternative GIT_CONFIG (--file)' '
494         git config --file other-config --list >output &&
495         test_cmp expect output
496 '
497
498 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
499         git config --file - --list <other-config >output &&
500         test_cmp expect output
501 '
502
503 test_expect_success 'setting a value in stdin is an error' '
504         test_must_fail git config --file - some.value foo
505 '
506
507 test_expect_success 'editing stdin is an error' '
508         test_must_fail git config --file - --edit
509 '
510
511 test_expect_success 'refer config from subdirectory' '
512         mkdir x &&
513         test_cmp_config -C x strasse --file=../other-config --get ein.bahn
514 '
515
516 cat > expect << EOF
517 [ein]
518         bahn = strasse
519 [anwohner]
520         park = ausweis
521 EOF
522
523 test_expect_success '--set in alternative file' '
524         git config --file=other-config anwohner.park ausweis &&
525         test_cmp expect other-config
526 '
527
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
537 EOF
538
539 test_expect_success 'rename section' '
540         git config --rename-section branch.eins branch.zwei
541 '
542
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
552 EOF
553
554 test_expect_success 'rename succeeded' '
555         test_cmp expect .git/config
556 '
557
558 test_expect_success 'rename non-existing section' '
559         test_must_fail git config --rename-section \
560                 branch."world domination" branch.drei
561 '
562
563 test_expect_success 'rename succeeded' '
564         test_cmp expect .git/config
565 '
566
567 test_expect_success 'rename another section' '
568         git config --rename-section branch."1 234 blabl/a" branch.drei
569 '
570
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
580 EOF
581
582 test_expect_success 'rename succeeded' '
583         test_cmp expect .git/config
584 '
585
586 cat >> .git/config << EOF
587 [branch "vier"] z = 1
588 EOF
589
590 test_expect_success 'rename a section with a var on the same line' '
591         git config --rename-section branch.vier branch.zwei
592 '
593
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
605 EOF
606
607 test_expect_success 'rename succeeded' '
608         test_cmp expect .git/config
609 '
610
611 test_expect_success 'renaming empty section name is rejected' '
612         test_must_fail git config --rename-section branch.zwei ""
613 '
614
615 test_expect_success 'renaming to bogus section is rejected' '
616         test_must_fail git config --rename-section branch.zwei "bogus name"
617 '
618
619 cat >> .git/config << EOF
620   [branch "zwei"] a = 1 [branch "vier"]
621 EOF
622
623 test_expect_success 'remove section' '
624         git config --remove-section branch.zwei
625 '
626
627 cat > expect << EOF
628 # Hallo
629         #Bello
630 [branch "drei"]
631 weird
632 EOF
633
634 test_expect_success 'section was removed properly' '
635         test_cmp expect .git/config
636 '
637
638 cat > expect << EOF
639 [gitcvs]
640         enabled = true
641         dbname = %Ggitcvs2.%a.%m.sqlite
642 [gitcvs "ext"]
643         dbname = %Ggitcvs1.%a.%m.sqlite
644 EOF
645
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
652
653 '
654
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
663 '
664
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
669 '
670
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
676 '
677
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
682 '
683
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
687 '
688
689 cat > expect << EOF
690 true
691 false
692 true
693 false
694 true
695 false
696 true
697 false
698 EOF
699
700 test_expect_success bool '
701
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
712         do
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'
717
718 test_expect_success 'invalid bool (--get)' '
719
720         git config bool.nobool foobar &&
721         test_must_fail git config --bool --get bool.nobool'
722
723 test_expect_success 'invalid bool (set)' '
724
725         test_must_fail git config --bool bool.nobool foobar'
726
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
737 EOF
738
739 test_expect_success 'set --bool' '
740
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'
751
752 cat > expect <<\EOF
753 [int]
754         val1 = 1
755         val2 = -1
756         val3 = 5242880
757 EOF
758
759 test_expect_success 'set --int' '
760
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
766 '
767
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
778         EOF
779         cat >expect <<-\EOF &&
780         true
781         true
782         false
783         0
784         1
785         -1
786         EOF
787         {
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
796 '
797
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
808 EOF
809
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
820 '
821
822 cat >expect <<\EOF
823 [path]
824         home = ~/
825         normal = /dev/null
826         trailingtilde = foo~
827 EOF
828
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'
835
836 if test_have_prereq !MINGW && test "${HOME+set}"
837 then
838         test_set_prereq HOMEVAR
839 fi
840
841 cat >expect <<EOF
842 $HOME/
843 /dev/null
844 foo~
845 EOF
846
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
852 '
853
854 cat >expect <<\EOF
855 /dev/null
856 foo~
857 EOF
858
859 test_expect_success !MINGW 'get --path copes with unset $HOME' '
860         (
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
869 '
870
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
874 '
875
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"
887         EOF
888         cat >expect <<-EOF &&
889         $(test-tool date timestamp $rel)
890         1275666415
891         1510441871
892         1510348087
893         0
894         EOF
895         : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
896         {
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
905 '
906
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
914 '
915
916 cat >expect << EOF
917 [foo]
918         color = red
919 EOF
920
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
925 '
926
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
930 '
931
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
935 '
936
937 cat > expect << EOF
938 [quote]
939         leading = " test"
940         ending = "test "
941         semicolon = "test;test"
942         hash = "test#test"
943 EOF
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
951 '
952
953 test_expect_success 'key with newline' '
954         test_must_fail git config "key.with
955 newline" 123'
956
957 test_expect_success 'value with newline' 'git config key.sub value.with\\\
958 newline'
959
960 cat > .git/config <<\EOF
961 [section]
962         ; comment \
963         continued = cont\
964 inued
965         noncont   = not continued ; \
966         quotecont = "cont;\
967 inued"
968 EOF
969
970 cat > expect <<\EOF
971 section.continued=continued
972 section.noncont=not continued
973 section.quotecont=cont;inued
974 EOF
975
976 test_expect_success 'value continued on next line' '
977         git config --list > result &&
978         test_cmp expect result
979 '
980
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
988 EOF
989
990 cat > expect <<\EOF
991 section.sub=section.val1
992 foo=barQsection.sub=section.val2
993 foo
994 barQsection.sub=section.val3
995
996
997 Qsection.sub=section.val4
998 Qsection.sub=section.val5Q
999 EOF
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
1005 '
1006
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
1012 '
1013
1014 test_expect_success 'inner whitespace kept verbatim' '
1015         git config section.val "foo       bar" &&
1016         test_cmp_config "foo      bar" section.val
1017 '
1018
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
1031         EOF
1032         {
1033                 git config --file=notyet test.frotz &&
1034                 git config --file=notyet test.xyzzy
1035         } >actual &&
1036         test_cmp expect actual
1037 '
1038
1039 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1040         ln -s doesnotexist linktonada &&
1041         ln -s linktonada linktolinktonada &&
1042         test_must_fail git config --file=linktonada --list &&
1043         test_must_fail git config --file=linktolinktonada --list
1044 '
1045
1046 test_expect_success 'check split_cmdline return' "
1047         git config alias.split-cmdline-fix 'echo \"' &&
1048         test_must_fail git split-cmdline-fix &&
1049         echo foo > foo &&
1050         git add foo &&
1051         git commit -m 'initial commit' &&
1052         git config branch.main.mergeoptions 'echo \"' &&
1053         test_must_fail git merge main
1054 "
1055
1056 test_expect_success 'git -c "key=value" support' '
1057         cat >expect <<-\EOF &&
1058         value
1059         value
1060         true
1061         EOF
1062         {
1063                 git -c section.name=value config section.name &&
1064                 git -c foo.CamelCase=value config foo.camelcase &&
1065                 git -c foo.flag config --bool foo.flag
1066         } >actual &&
1067         test_cmp expect actual &&
1068         test_must_fail git -c name=value config section.name
1069 '
1070
1071 # We just need a type-specifier here that cares about the
1072 # distinction internally between a NULL boolean and a real
1073 # string (because most of git's internal parsers do care).
1074 # Using "--path" works, but we do not otherwise care about
1075 # its semantics.
1076 test_expect_success 'git -c can represent empty string' '
1077         echo >expect &&
1078         git -c foo.empty= config --path foo.empty >actual &&
1079         test_cmp expect actual
1080 '
1081
1082 test_expect_success 'key sanity-checking' '
1083         test_must_fail git config foo=bar &&
1084         test_must_fail git config foo=.bar &&
1085         test_must_fail git config foo.ba=r &&
1086         test_must_fail git config foo.1bar &&
1087         test_must_fail git config foo."ba
1088                                 z".bar &&
1089         test_must_fail git config . false &&
1090         test_must_fail git config .foo false &&
1091         test_must_fail git config foo. false &&
1092         test_must_fail git config .foo. false &&
1093         git config foo.bar true &&
1094         git config foo."ba =z".bar false
1095 '
1096
1097 test_expect_success 'git -c works with aliases of builtins' '
1098         git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1099         echo bar >expect &&
1100         git checkconfig >actual &&
1101         test_cmp expect actual
1102 '
1103
1104 test_expect_success 'aliases can be CamelCased' '
1105         test_config alias.CamelCased "rev-parse HEAD" &&
1106         git CamelCased >out &&
1107         git rev-parse HEAD >expect &&
1108         test_cmp expect out
1109 '
1110
1111 test_expect_success 'git -c does not split values on equals' '
1112         echo "value with = in it" >expect &&
1113         git -c section.foo="value with = in it" config section.foo >actual &&
1114         test_cmp expect actual
1115 '
1116
1117 test_expect_success 'git -c dies on bogus config' '
1118         test_must_fail git -c core.bare=foo rev-parse
1119 '
1120
1121 test_expect_success 'git -c complains about empty key' '
1122         test_must_fail git -c "=foo" rev-parse
1123 '
1124
1125 test_expect_success 'git -c complains about empty key and value' '
1126         test_must_fail git -c "" rev-parse
1127 '
1128
1129 test_expect_success 'multiple git -c appends config' '
1130         test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1131         cat >expect <<-\EOF &&
1132         x.one 1
1133         x.two 2
1134         EOF
1135         git -c x.one=1 x >actual &&
1136         test_cmp expect actual
1137 '
1138
1139 test_expect_success 'last one wins: two level vars' '
1140
1141         # sec.var and sec.VAR are the same variable, as the first
1142         # and the last level of a configuration variable name is
1143         # case insensitive.
1144
1145         echo VAL >expect &&
1146
1147         git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1148         test_cmp expect actual &&
1149         git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1150         test_cmp expect actual &&
1151
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
1156 '
1157
1158 test_expect_success 'last one wins: three level vars' '
1159
1160         # v.a.r and v.A.r are not the same variable, as the middle
1161         # level of a three-level configuration variable name is
1162         # case sensitive.
1163
1164         echo val >expect &&
1165         git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1166         test_cmp expect actual &&
1167         git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1168         test_cmp expect actual &&
1169
1170         # v.a.r and V.a.R are the same variable, as the first
1171         # and the last level of a configuration variable name is
1172         # case insensitive.
1173
1174         echo VAL >expect &&
1175         git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1176         test_cmp expect actual &&
1177         git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1178         test_cmp expect actual &&
1179         git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1180         test_cmp expect actual &&
1181         git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1182         test_cmp expect actual
1183 '
1184
1185 test_expect_success 'old-fashioned settings are case insensitive' '
1186         test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1187
1188         cat >testConfig_actual <<-EOF &&
1189         [V.A]
1190         r = value1
1191         EOF
1192         q_to_tab >testConfig_expect <<-EOF &&
1193         [V.A]
1194         Qr = value2
1195         EOF
1196         git config -f testConfig_actual "v.a.r" value2 &&
1197         test_cmp testConfig_expect testConfig_actual &&
1198
1199         cat >testConfig_actual <<-EOF &&
1200         [V.A]
1201         r = value1
1202         EOF
1203         q_to_tab >testConfig_expect <<-EOF &&
1204         [V.A]
1205         QR = value2
1206         EOF
1207         git config -f testConfig_actual "V.a.R" value2 &&
1208         test_cmp testConfig_expect testConfig_actual &&
1209
1210         cat >testConfig_actual <<-EOF &&
1211         [V.A]
1212         r = value1
1213         EOF
1214         q_to_tab >testConfig_expect <<-EOF &&
1215         [V.A]
1216         r = value1
1217         Qr = value2
1218         EOF
1219         git config -f testConfig_actual "V.A.r" value2 &&
1220         test_cmp testConfig_expect testConfig_actual &&
1221
1222         cat >testConfig_actual <<-EOF &&
1223         [V.A]
1224         r = value1
1225         EOF
1226         q_to_tab >testConfig_expect <<-EOF &&
1227         [V.A]
1228         r = value1
1229         Qr = value2
1230         EOF
1231         git config -f testConfig_actual "v.A.r" value2 &&
1232         test_cmp testConfig_expect testConfig_actual
1233 '
1234
1235 test_expect_success 'setting different case sensitive subsections ' '
1236         test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1237
1238         cat >testConfig_actual <<-EOF &&
1239         [V "A"]
1240         R = v1
1241         [K "E"]
1242         Y = v1
1243         [a "b"]
1244         c = v1
1245         [d "e"]
1246         f = v1
1247         EOF
1248         q_to_tab >testConfig_expect <<-EOF &&
1249         [V "A"]
1250         Qr = v2
1251         [K "E"]
1252         Qy = v2
1253         [a "b"]
1254         Qc = v2
1255         [d "e"]
1256         f = v1
1257         [d "E"]
1258         Qf = v2
1259         EOF
1260         # exact match
1261         git config -f testConfig_actual a.b.c v2 &&
1262         # match section and subsection, key is cased differently.
1263         git config -f testConfig_actual K.E.y v2 &&
1264         # section and key are matched case insensitive, but subsection needs
1265         # to match; When writing out new values only the key is adjusted
1266         git config -f testConfig_actual v.A.r v2 &&
1267         # subsection is not matched:
1268         git config -f testConfig_actual d.E.f v2 &&
1269         test_cmp testConfig_expect testConfig_actual
1270 '
1271
1272 for VAR in a .a a. a.0b a."b c". a."b c".0d
1273 do
1274         test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1275                 test_must_fail git -c "$VAR=VAL" config -l
1276         '
1277 done
1278
1279 for VAR in a.b a."b c".d
1280 do
1281         test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1282                 echo VAL >expect &&
1283                 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1284                 test_cmp expect actual
1285         '
1286 done
1287
1288 test_expect_success 'git -c is not confused by empty environment' '
1289         GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1290 '
1291
1292 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1293         v="${SQ}key.one=foo${SQ}" &&
1294         v="$v  ${SQ}key.two=bar${SQ}" &&
1295         v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1296         GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1297         cat >expect <<-EOF &&
1298         key.one foo
1299         key.two bar
1300         key.ambiguous section.whatever=value
1301         EOF
1302         test_cmp expect actual
1303 '
1304
1305 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1306         v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1307         v="$v  ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1308         v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1309         GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1310         cat >expect <<-EOF &&
1311         key.one foo
1312         key.two bar
1313         key.ambiguous=section.whatever value
1314         EOF
1315         test_cmp expect actual
1316 '
1317
1318 test_expect_success 'old and new-style entries can mix' '
1319         v="${SQ}key.oldone=oldfoo${SQ}" &&
1320         v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1321         v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1322         v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1323         GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1324         cat >expect <<-EOF &&
1325         key.oldone oldfoo
1326         key.newone newfoo
1327         key.oldtwo oldbar
1328         key.newtwo newbar
1329         EOF
1330         test_cmp expect actual
1331 '
1332
1333 test_expect_success 'old and new bools with ambiguous subsection' '
1334         v="${SQ}key.with=equals.oldbool${SQ}" &&
1335         v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1336         GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1337         cat >expect <<-EOF &&
1338         key.with equals.oldbool
1339         key.with=equals.newbool
1340         EOF
1341         test_cmp expect actual
1342 '
1343
1344 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1345         cat >expect <<-\EOF &&
1346         env.one one
1347         env.two two
1348         EOF
1349         GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1350                 git config --get-regexp "env.*" >actual &&
1351         test_cmp expect actual &&
1352
1353         cat >expect <<-EOF &&
1354         env.one one${SQ}
1355         env.two two
1356         EOF
1357         GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1358                 git config --get-regexp "env.*" >actual &&
1359         test_cmp expect actual &&
1360
1361         test_must_fail env \
1362                 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1363                 git config --get-regexp "env.*"
1364 '
1365
1366 test_expect_success 'git --config-env=key=envvar support' '
1367         cat >expect <<-\EOF &&
1368         value
1369         value
1370         false
1371         EOF
1372         {
1373                 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1374                 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1375                 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag
1376         } >actual &&
1377         test_cmp expect actual
1378 '
1379
1380 test_expect_success 'git --config-env fails with invalid parameters' '
1381         test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1382         test_i18ngrep "invalid config format: foo.flag" error &&
1383         test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1384         test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1385         sane_unset NONEXISTENT &&
1386         test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1387         test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1388 '
1389
1390 test_expect_success 'git -c and --config-env work together' '
1391         cat >expect <<-\EOF &&
1392         bar.cmd cmd-value
1393         bar.env env-value
1394         EOF
1395         ENVVAR=env-value git \
1396                 -c bar.cmd=cmd-value \
1397                 --config-env=bar.env=ENVVAR \
1398                 config --get-regexp "^bar.*" >actual &&
1399         test_cmp expect actual
1400 '
1401
1402 test_expect_success 'git -c and --config-env override each other' '
1403         cat >expect <<-\EOF &&
1404         env
1405         cmd
1406         EOF
1407         {
1408                 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1409                 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1410         } >actual &&
1411         test_cmp expect actual
1412 '
1413
1414 test_expect_success '--config-env handles keys with equals' '
1415         echo value=with=equals >expect &&
1416         ENVVAR=value=with=equals git \
1417                 --config-env=section.subsection=with=equals.key=ENVVAR \
1418                 config section.subsection=with=equals.key >actual &&
1419         test_cmp expect actual
1420 '
1421
1422 test_expect_success 'git config handles environment config pairs' '
1423         GIT_CONFIG_COUNT=2 \
1424                 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1425                 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1426                 git config --get-regexp "pair.*" >actual &&
1427         cat >expect <<-EOF &&
1428         pair.one foo
1429         pair.two bar
1430         EOF
1431         test_cmp expect actual
1432 '
1433
1434 test_expect_success 'git config ignores pairs without count' '
1435         test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1436                 git config pair.one 2>error &&
1437         test_must_be_empty error
1438 '
1439
1440 test_expect_success 'git config ignores pairs with zero count' '
1441         test_must_fail env \
1442                 GIT_CONFIG_COUNT=0 \
1443                 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1444                 git config pair.one
1445 '
1446
1447 test_expect_success 'git config ignores pairs exceeding count' '
1448         GIT_CONFIG_COUNT=1 \
1449                 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1450                 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1451                 git config --get-regexp "pair.*" >actual &&
1452         cat >expect <<-EOF &&
1453         pair.one value
1454         EOF
1455         test_cmp expect actual
1456 '
1457
1458 test_expect_success 'git config ignores pairs with zero count' '
1459         test_must_fail env \
1460                 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1461                 git config pair.one >error &&
1462         test_must_be_empty error
1463 '
1464
1465 test_expect_success 'git config ignores pairs with empty count' '
1466         test_must_fail env \
1467                 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1468                 git config pair.one >error &&
1469         test_must_be_empty error
1470 '
1471
1472 test_expect_success 'git config fails with invalid count' '
1473         test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1474         test_i18ngrep "bogus count" error &&
1475         test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1476         test_i18ngrep "too many entries" error
1477 '
1478
1479 test_expect_success 'git config fails with missing config key' '
1480         test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1481                 git config --list 2>error &&
1482         test_i18ngrep "missing config key" error
1483 '
1484
1485 test_expect_success 'git config fails with missing config value' '
1486         test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1487                 git config --list 2>error &&
1488         test_i18ngrep "missing config value" error
1489 '
1490
1491 test_expect_success 'git config fails with invalid config pair key' '
1492         test_must_fail env GIT_CONFIG_COUNT=1 \
1493                 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1494                 git config --list &&
1495         test_must_fail env GIT_CONFIG_COUNT=1 \
1496                 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1497                 git config --list
1498 '
1499
1500 test_expect_success 'environment overrides config file' '
1501         test_when_finished "rm -f .git/config" &&
1502         cat >.git/config <<-EOF &&
1503         [pair]
1504         one = value
1505         EOF
1506         GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1507                 git config pair.one >actual &&
1508         cat >expect <<-EOF &&
1509         override
1510         EOF
1511         test_cmp expect actual
1512 '
1513
1514 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1515         GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1516                 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1517                 git config pair.one >actual &&
1518         cat >expect <<-EOF &&
1519         override
1520         EOF
1521         test_cmp expect actual
1522 '
1523
1524 test_expect_success 'command line overrides environment config' '
1525         GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1526                 git -c pair.one=override config pair.one >actual &&
1527         cat >expect <<-EOF &&
1528         override
1529         EOF
1530         test_cmp expect actual
1531 '
1532
1533 test_expect_success 'git config --edit works' '
1534         git config -f tmp test.value no &&
1535         echo test.value=yes >expect &&
1536         GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1537         git config -f tmp --list >actual &&
1538         test_cmp expect actual
1539 '
1540
1541 test_expect_success 'git config --edit respects core.editor' '
1542         git config -f tmp test.value no &&
1543         echo test.value=yes >expect &&
1544         test_config core.editor "echo [test]value=yes >" &&
1545         git config -f tmp --edit &&
1546         git config -f tmp --list >actual &&
1547         test_cmp expect actual
1548 '
1549
1550 # malformed configuration files
1551 test_expect_success 'barf on syntax error' '
1552         cat >.git/config <<-\EOF &&
1553         # broken section line
1554         [section]
1555         key garbage
1556         EOF
1557         test_must_fail git config --get section.key >actual 2>error &&
1558         test_i18ngrep " line 3 " error
1559 '
1560
1561 test_expect_success 'barf on incomplete section header' '
1562         cat >.git/config <<-\EOF &&
1563         # broken section line
1564         [section
1565         key = value
1566         EOF
1567         test_must_fail git config --get section.key >actual 2>error &&
1568         test_i18ngrep " line 2 " error
1569 '
1570
1571 test_expect_success 'barf on incomplete string' '
1572         cat >.git/config <<-\EOF &&
1573         # broken section line
1574         [section]
1575         key = "value string
1576         EOF
1577         test_must_fail git config --get section.key >actual 2>error &&
1578         test_i18ngrep " line 3 " error
1579 '
1580
1581 test_expect_success 'urlmatch' '
1582         cat >.git/config <<-\EOF &&
1583         [http]
1584                 sslVerify
1585         [http "https://weak.example.com"]
1586                 sslVerify = false
1587                 cookieFile = /tmp/cookie.txt
1588         EOF
1589
1590         test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1591         test_must_be_empty actual &&
1592
1593         echo true >expect &&
1594         git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1595         test_cmp expect actual &&
1596
1597         echo false >expect &&
1598         git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1599         test_cmp expect actual &&
1600
1601         {
1602                 echo http.cookiefile /tmp/cookie.txt &&
1603                 echo http.sslverify false
1604         } >expect &&
1605         git config --get-urlmatch HTTP https://weak.example.com >actual &&
1606         test_cmp expect actual
1607 '
1608
1609 test_expect_success 'urlmatch favors more specific URLs' '
1610         cat >.git/config <<-\EOF &&
1611         [http "https://example.com/"]
1612                 cookieFile = /tmp/root.txt
1613         [http "https://example.com/subdirectory"]
1614                 cookieFile = /tmp/subdirectory.txt
1615         [http "https://user@example.com/"]
1616                 cookieFile = /tmp/user.txt
1617         [http "https://averylonguser@example.com/"]
1618                 cookieFile = /tmp/averylonguser.txt
1619         [http "https://preceding.example.com"]
1620                 cookieFile = /tmp/preceding.txt
1621         [http "https://*.example.com"]
1622                 cookieFile = /tmp/wildcard.txt
1623         [http "https://*.example.com/wildcardwithsubdomain"]
1624                 cookieFile = /tmp/wildcardwithsubdomain.txt
1625         [http "https://*.example.*"]
1626                 cookieFile = /tmp/multiwildcard.txt
1627         [http "https://trailing.example.com"]
1628                 cookieFile = /tmp/trailing.txt
1629         [http "https://user@*.example.com/"]
1630                 cookieFile = /tmp/wildcardwithuser.txt
1631         [http "https://sub.example.com/"]
1632                 cookieFile = /tmp/sub.txt
1633         EOF
1634
1635         echo http.cookiefile /tmp/root.txt >expect &&
1636         git config --get-urlmatch HTTP https://example.com >actual &&
1637         test_cmp expect actual &&
1638
1639         echo http.cookiefile /tmp/subdirectory.txt >expect &&
1640         git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1641         test_cmp expect actual &&
1642
1643         echo http.cookiefile /tmp/subdirectory.txt >expect &&
1644         git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1645         test_cmp expect actual &&
1646
1647         echo http.cookiefile /tmp/user.txt >expect &&
1648         git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1649         test_cmp expect actual &&
1650
1651         echo http.cookiefile /tmp/subdirectory.txt >expect &&
1652         git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1653         test_cmp expect actual &&
1654
1655         echo http.cookiefile /tmp/preceding.txt >expect &&
1656         git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1657         test_cmp expect actual &&
1658
1659         echo http.cookiefile /tmp/wildcard.txt >expect &&
1660         git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1661         test_cmp expect actual &&
1662
1663         echo http.cookiefile /tmp/sub.txt >expect &&
1664         git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1665         test_cmp expect actual &&
1666
1667         echo http.cookiefile /tmp/trailing.txt >expect &&
1668         git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1669         test_cmp expect actual &&
1670
1671         echo http.cookiefile /tmp/sub.txt >expect &&
1672         git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1673         test_cmp expect actual &&
1674
1675         echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1676         git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1677         test_cmp expect actual
1678 '
1679
1680 test_expect_success 'urlmatch with wildcard' '
1681         cat >.git/config <<-\EOF &&
1682         [http]
1683                 sslVerify
1684         [http "https://*.example.com"]
1685                 sslVerify = false
1686                 cookieFile = /tmp/cookie.txt
1687         EOF
1688
1689         test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1690         test_must_be_empty actual &&
1691
1692         echo true >expect &&
1693         git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1694         test_cmp expect actual &&
1695
1696         echo true >expect &&
1697         git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1698         test_cmp expect actual &&
1699
1700         echo true >expect &&
1701         git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1702         test_cmp expect actual &&
1703
1704         echo false >expect &&
1705         git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1706         test_cmp expect actual &&
1707
1708         {
1709                 echo http.cookiefile /tmp/cookie.txt &&
1710                 echo http.sslverify false
1711         } >expect &&
1712         git config --get-urlmatch HTTP https://good.example.com >actual &&
1713         test_cmp expect actual &&
1714
1715         echo http.sslverify >expect &&
1716         git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1717         test_cmp expect actual
1718 '
1719
1720 # good section hygiene
1721 test_expect_success '--unset last key removes section (except if commented)' '
1722         cat >.git/config <<-\EOF &&
1723         # some generic comment on the configuration file itself
1724         # a comment specific to this "section" section.
1725         [section]
1726         # some intervening lines
1727         # that should also be dropped
1728
1729         key = value
1730         # please be careful when you update the above variable
1731         EOF
1732
1733         cat >expect <<-\EOF &&
1734         # some generic comment on the configuration file itself
1735         # a comment specific to this "section" section.
1736         [section]
1737         # some intervening lines
1738         # that should also be dropped
1739
1740         # please be careful when you update the above variable
1741         EOF
1742
1743         git config --unset section.key &&
1744         test_cmp expect .git/config &&
1745
1746         cat >.git/config <<-\EOF &&
1747         [section]
1748         key = value
1749         [next-section]
1750         EOF
1751
1752         cat >expect <<-\EOF &&
1753         [next-section]
1754         EOF
1755
1756         git config --unset section.key &&
1757         test_cmp expect .git/config &&
1758
1759         q_to_tab >.git/config <<-\EOF &&
1760         [one]
1761         Qkey = "multiline \
1762         QQ# with comment"
1763         [two]
1764         key = true
1765         EOF
1766         git config --unset two.key &&
1767         ! grep two .git/config &&
1768
1769         q_to_tab >.git/config <<-\EOF &&
1770         [one]
1771         Qkey = "multiline \
1772         QQ# with comment"
1773         [one]
1774         key = true
1775         EOF
1776         git config --unset-all one.key &&
1777         test_line_count = 0 .git/config &&
1778
1779         q_to_tab >.git/config <<-\EOF &&
1780         [one]
1781         Qkey = true
1782         Q# a comment not at the start
1783         [two]
1784         Qkey = true
1785         EOF
1786         git config --unset two.key &&
1787         grep two .git/config &&
1788
1789         q_to_tab >.git/config <<-\EOF &&
1790         [one]
1791         Qkey = not [two "subsection"]
1792         [two "subsection"]
1793         [two "subsection"]
1794         Qkey = true
1795         [TWO "subsection"]
1796         [one]
1797         EOF
1798         git config --unset two.subsection.key &&
1799         test "not [two subsection]" = "$(git config one.key)" &&
1800         test_line_count = 3 .git/config
1801 '
1802
1803 test_expect_success '--unset-all removes section if empty & uncommented' '
1804         cat >.git/config <<-\EOF &&
1805         [section]
1806         key = value1
1807         key = value2
1808         EOF
1809
1810         git config --unset-all section.key &&
1811         test_line_count = 0 .git/config
1812 '
1813
1814 test_expect_success 'adding a key into an empty section reuses header' '
1815         cat >.git/config <<-\EOF &&
1816         [section]
1817         EOF
1818
1819         q_to_tab >expect <<-\EOF &&
1820         [section]
1821         Qkey = value
1822         EOF
1823
1824         git config section.key value &&
1825         test_cmp expect .git/config
1826 '
1827
1828 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1829         chmod 0600 .git/config &&
1830         git config imap.pass Hunter2 &&
1831         perl -e \
1832           "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1833         git config --rename-section imap pop &&
1834         perl -e \
1835           "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1836 '
1837
1838 ! test_have_prereq MINGW ||
1839 HOME="$(pwd)" # convert to Windows path
1840
1841 test_expect_success 'set up --show-origin tests' '
1842         INCLUDE_DIR="$HOME/include" &&
1843         mkdir -p "$INCLUDE_DIR" &&
1844         cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1845         [user]
1846                 absolute = include
1847         EOF
1848         cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1849         [user]
1850                 relative = include
1851         EOF
1852         cat >"$HOME"/.gitconfig <<-EOF &&
1853         [user]
1854                 global = true
1855                 override = global
1856         [include]
1857                 path = "$INCLUDE_DIR/absolute.include"
1858         EOF
1859         cat >.git/config <<-\EOF
1860         [user]
1861                 local = true
1862                 override = local
1863         [include]
1864                 path = ../include/relative.include
1865         EOF
1866 '
1867
1868 test_expect_success '--show-origin with --list' '
1869         cat >expect <<-EOF &&
1870         file:$HOME/.gitconfig   user.global=true
1871         file:$HOME/.gitconfig   user.override=global
1872         file:$HOME/.gitconfig   include.path=$INCLUDE_DIR/absolute.include
1873         file:$INCLUDE_DIR/absolute.include      user.absolute=include
1874         file:.git/config        user.local=true
1875         file:.git/config        user.override=local
1876         file:.git/config        include.path=../include/relative.include
1877         file:.git/../include/relative.include   user.relative=include
1878         command line:   user.environ=true
1879         command line:   user.cmdline=true
1880         EOF
1881         GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1882                 git -c user.cmdline=true config --list --show-origin >output &&
1883         test_cmp expect output
1884 '
1885
1886 test_expect_success '--show-origin with --list --null' '
1887         cat >expect <<-EOF &&
1888         file:$HOME/.gitconfigQuser.global
1889         trueQfile:$HOME/.gitconfigQuser.override
1890         globalQfile:$HOME/.gitconfigQinclude.path
1891         $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1892         includeQfile:.git/configQuser.local
1893         trueQfile:.git/configQuser.override
1894         localQfile:.git/configQinclude.path
1895         ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1896         includeQcommand line:Quser.cmdline
1897         trueQ
1898         EOF
1899         git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1900         nul_to_q <output.raw >output &&
1901         # The here-doc above adds a newline that the --null output would not
1902         # include. Add it here to make the two comparable.
1903         echo >>output &&
1904         test_cmp expect output
1905 '
1906
1907 test_expect_success '--show-origin with single file' '
1908         cat >expect <<-\EOF &&
1909         file:.git/config        user.local=true
1910         file:.git/config        user.override=local
1911         file:.git/config        include.path=../include/relative.include
1912         EOF
1913         git config --local --list --show-origin >output &&
1914         test_cmp expect output
1915 '
1916
1917 test_expect_success '--show-origin with --get-regexp' '
1918         cat >expect <<-EOF &&
1919         file:$HOME/.gitconfig   user.global true
1920         file:.git/config        user.local true
1921         EOF
1922         git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1923         test_cmp expect output
1924 '
1925
1926 test_expect_success '--show-origin getting a single key' '
1927         cat >expect <<-\EOF &&
1928         file:.git/config        local
1929         EOF
1930         git config --show-origin user.override >output &&
1931         test_cmp expect output
1932 '
1933
1934 test_expect_success 'set up custom config file' '
1935         CUSTOM_CONFIG_FILE="custom.conf" &&
1936         cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1937         [user]
1938                 custom = true
1939         EOF
1940 '
1941
1942 test_expect_success !MINGW 'set up custom config file with special name characters' '
1943         WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
1944         cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
1945 '
1946
1947 test_expect_success !MINGW '--show-origin escape special file name characters' '
1948         cat >expect <<-\EOF &&
1949         file:"file\" (dq) and spaces.conf"      user.custom=true
1950         EOF
1951         git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
1952         test_cmp expect output
1953 '
1954
1955 test_expect_success '--show-origin stdin' '
1956         cat >expect <<-\EOF &&
1957         standard input: user.custom=true
1958         EOF
1959         git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1960         test_cmp expect output
1961 '
1962
1963 test_expect_success '--show-origin stdin with file include' '
1964         cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1965         [user]
1966                 stdin = include
1967         EOF
1968         cat >expect <<-EOF &&
1969         file:$INCLUDE_DIR/stdin.include include
1970         EOF
1971         echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
1972         git config --show-origin --includes --file - user.stdin >output &&
1973
1974         test_cmp expect output
1975 '
1976
1977 test_expect_success '--show-origin blob' '
1978         blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1979         cat >expect <<-EOF &&
1980         blob:$blob      user.custom=true
1981         EOF
1982         git config --blob=$blob --show-origin --list >output &&
1983         test_cmp expect output
1984 '
1985
1986 test_expect_success '--show-origin blob ref' '
1987         cat >expect <<-\EOF &&
1988         blob:main:custom.conf   user.custom=true
1989         EOF
1990         git add "$CUSTOM_CONFIG_FILE" &&
1991         git commit -m "new config file" &&
1992         git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1993         test_cmp expect output
1994 '
1995
1996 test_expect_success '--show-scope with --list' '
1997         cat >expect <<-EOF &&
1998         global  user.global=true
1999         global  user.override=global
2000         global  include.path=$INCLUDE_DIR/absolute.include
2001         global  user.absolute=include
2002         local   user.local=true
2003         local   user.override=local
2004         local   include.path=../include/relative.include
2005         local   user.relative=include
2006         command user.cmdline=true
2007         EOF
2008         git -c user.cmdline=true config --list --show-scope >output &&
2009         test_cmp expect output
2010 '
2011
2012 test_expect_success !MINGW '--show-scope with --blob' '
2013         blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2014         cat >expect <<-EOF &&
2015         command user.custom=true
2016         EOF
2017         git config --blob=$blob --show-scope --list >output &&
2018         test_cmp expect output
2019 '
2020
2021 test_expect_success '--show-scope with --local' '
2022         cat >expect <<-\EOF &&
2023         local   user.local=true
2024         local   user.override=local
2025         local   include.path=../include/relative.include
2026         EOF
2027         git config --local --list --show-scope >output &&
2028         test_cmp expect output
2029 '
2030
2031 test_expect_success '--show-scope getting a single value' '
2032         cat >expect <<-\EOF &&
2033         local   true
2034         EOF
2035         git config --show-scope --get user.local >output &&
2036         test_cmp expect output
2037 '
2038
2039 test_expect_success '--show-scope with --show-origin' '
2040         cat >expect <<-EOF &&
2041         global  file:$HOME/.gitconfig   user.global=true
2042         global  file:$HOME/.gitconfig   user.override=global
2043         global  file:$HOME/.gitconfig   include.path=$INCLUDE_DIR/absolute.include
2044         global  file:$INCLUDE_DIR/absolute.include      user.absolute=include
2045         local   file:.git/config        user.local=true
2046         local   file:.git/config        user.override=local
2047         local   file:.git/config        include.path=../include/relative.include
2048         local   file:.git/../include/relative.include   user.relative=include
2049         command command line:   user.cmdline=true
2050         EOF
2051         git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2052         test_cmp expect output
2053 '
2054
2055 for opt in --local --worktree
2056 do
2057         test_expect_success "$opt requires a repo" '
2058                 # we expect 128 to ensure that we do not simply
2059                 # fail to find anything and return code "1"
2060                 test_expect_code 128 nongit git config $opt foo.bar
2061         '
2062 done
2063
2064 cat >.git/config <<-\EOF &&
2065 [section]
2066 foo = true
2067 number = 10
2068 big = 1M
2069 EOF
2070
2071 test_expect_success 'identical modern --type specifiers are allowed' '
2072         test_cmp_config 1048576 --type=int --type=int section.big
2073 '
2074
2075 test_expect_success 'identical legacy --type specifiers are allowed' '
2076         test_cmp_config 1048576 --int --int section.big
2077 '
2078
2079 test_expect_success 'identical mixed --type specifiers are allowed' '
2080         test_cmp_config 1048576 --int --type=int section.big
2081 '
2082
2083 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2084         test_must_fail git config --type=int --type=bool section.big 2>error &&
2085         test_i18ngrep "only one type at a time" error
2086 '
2087
2088 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2089         test_must_fail git config --int --bool section.big 2>error &&
2090         test_i18ngrep "only one type at a time" error
2091 '
2092
2093 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2094         test_must_fail git config --type=int --bool section.big 2>error &&
2095         test_i18ngrep "only one type at a time" error
2096 '
2097
2098 test_expect_success '--type allows valid type specifiers' '
2099         test_cmp_config true  --type=bool section.foo
2100 '
2101
2102 test_expect_success '--no-type unsets type specifiers' '
2103         test_cmp_config 10 --type=bool --no-type section.number
2104 '
2105
2106 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2107         test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2108 '
2109
2110 test_expect_success '--type rejects unknown specifiers' '
2111         test_must_fail git config --type=nonsense section.foo 2>error &&
2112         test_i18ngrep "unrecognized --type argument" error
2113 '
2114
2115 test_expect_success '--replace-all does not invent newlines' '
2116         q_to_tab >.git/config <<-\EOF &&
2117         [abc]key
2118         QkeepSection
2119         [xyz]
2120         Qkey = 1
2121         [abc]
2122         Qkey = a
2123         EOF
2124         q_to_tab >expect <<-\EOF &&
2125         [abc]
2126         QkeepSection
2127         [xyz]
2128         Qkey = 1
2129         [abc]
2130         Qkey = b
2131         EOF
2132         git config --replace-all abc.key b &&
2133         test_cmp expect .git/config
2134 '
2135
2136 test_expect_success 'set all config with value-pattern' '
2137         test_when_finished rm -f config initial &&
2138         git config --file=initial abc.key one &&
2139
2140         # no match => add new entry
2141         cp initial config &&
2142         git config --file=config abc.key two a+ &&
2143         git config --file=config --list >actual &&
2144         cat >expect <<-\EOF &&
2145         abc.key=one
2146         abc.key=two
2147         EOF
2148         test_cmp expect actual &&
2149
2150         # multiple matches => failure
2151         test_must_fail git config --file=config abc.key three o+ 2>err &&
2152         test_i18ngrep "has multiple values" err &&
2153
2154         # multiple values, no match => add
2155         git config --file=config abc.key three a+ &&
2156         git config --file=config --list >actual &&
2157         cat >expect <<-\EOF &&
2158         abc.key=one
2159         abc.key=two
2160         abc.key=three
2161         EOF
2162         test_cmp expect actual &&
2163
2164         # single match => replace
2165         git config --file=config abc.key four h+ &&
2166         git config --file=config --list >actual &&
2167         cat >expect <<-\EOF &&
2168         abc.key=one
2169         abc.key=two
2170         abc.key=four
2171         EOF
2172         test_cmp expect actual
2173 '
2174
2175 test_expect_success '--replace-all and value-pattern' '
2176         test_when_finished rm -f config &&
2177         git config --file=config --add abc.key one &&
2178         git config --file=config --add abc.key two &&
2179         git config --file=config --add abc.key three &&
2180         git config --file=config --replace-all abc.key four "o+" &&
2181         git config --file=config --list >actual &&
2182         cat >expect <<-\EOF &&
2183         abc.key=four
2184         abc.key=three
2185         EOF
2186         test_cmp expect actual
2187 '
2188
2189 test_expect_success 'refuse --fixed-value for incompatible actions' '
2190         test_when_finished rm -f config &&
2191         git config --file=config dev.null bogus &&
2192
2193         # These modes do not allow --fixed-value at all
2194         test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2195         test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2196         test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2197         test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2198         test_must_fail git config --file=config --fixed-value --remove-section dev &&
2199         test_must_fail git config --file=config --fixed-value --list &&
2200         test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2201         test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2202
2203         # These modes complain when --fixed-value has no value-pattern
2204         test_must_fail git config --file=config --fixed-value dev.null bogus &&
2205         test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2206         test_must_fail git config --file=config --fixed-value --get dev.null &&
2207         test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2208         test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2209         test_must_fail git config --file=config --fixed-value --unset dev.null &&
2210         test_must_fail git config --file=config --fixed-value --unset-all dev.null
2211 '
2212
2213 test_expect_success '--fixed-value uses exact string matching' '
2214         test_when_finished rm -f config initial &&
2215         META="a+b*c?d[e]f.g" &&
2216         git config --file=initial fixed.test "$META" &&
2217
2218         cp initial config &&
2219         git config --file=config fixed.test bogus "$META" &&
2220         git config --file=config --list >actual &&
2221         cat >expect <<-EOF &&
2222         fixed.test=$META
2223         fixed.test=bogus
2224         EOF
2225         test_cmp expect actual &&
2226
2227         cp initial config &&
2228         git config --file=config --fixed-value fixed.test bogus "$META" &&
2229         git config --file=config --list >actual &&
2230         cat >expect <<-\EOF &&
2231         fixed.test=bogus
2232         EOF
2233         test_cmp expect actual &&
2234
2235         cp initial config &&
2236         test_must_fail git config --file=config --unset fixed.test "$META" &&
2237         git config --file=config --fixed-value --unset fixed.test "$META" &&
2238         test_must_fail git config --file=config fixed.test &&
2239
2240         cp initial config &&
2241         test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2242         git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2243         test_must_fail git config --file=config fixed.test &&
2244
2245         cp initial config &&
2246         git config --file=config --replace-all fixed.test bogus "$META" &&
2247         git config --file=config --list >actual &&
2248         cat >expect <<-EOF &&
2249         fixed.test=$META
2250         fixed.test=bogus
2251         EOF
2252         test_cmp expect actual &&
2253
2254         git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2255         git config --file=config --list >actual &&
2256         cat >expect <<-EOF &&
2257         fixed.test=bogus
2258         fixed.test=bogus
2259         EOF
2260         test_cmp expect actual
2261 '
2262
2263 test_expect_success '--get and --get-all with --fixed-value' '
2264         test_when_finished rm -f config &&
2265         META="a+b*c?d[e]f.g" &&
2266         git config --file=config fixed.test bogus &&
2267         git config --file=config --add fixed.test "$META" &&
2268
2269         git config --file=config --get fixed.test bogus &&
2270         test_must_fail git config --file=config --get fixed.test "$META" &&
2271         git config --file=config --get --fixed-value fixed.test "$META" &&
2272         test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2273
2274         git config --file=config --get-all fixed.test bogus &&
2275         test_must_fail git config --file=config --get-all fixed.test "$META" &&
2276         git config --file=config --get-all --fixed-value fixed.test "$META" &&
2277         test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2278
2279         git config --file=config --get-regexp fixed+ bogus &&
2280         test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2281         git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2282         test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2283 '
2284
2285 test_done