]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1300-config.sh
branch.c: simplify advice-and-die sequence
[thirdparty/git.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 'invalid unit boolean' '
679 git config commit.gpgsign "1true" &&
680 test_cmp_config 1true commit.gpgsign &&
681 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
682 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
683 '
684
685 test_expect_success 'line number is reported correctly' '
686 printf "[bool]\n\tvar\n" >invalid &&
687 test_must_fail git config -f invalid --path bool.var 2>actual &&
688 test_i18ngrep "line 2" actual
689 '
690
691 test_expect_success 'invalid stdin config' '
692 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
693 test_i18ngrep "bad config line 1 in standard input" output
694 '
695
696 cat > expect << EOF
697 true
698 false
699 true
700 false
701 true
702 false
703 true
704 false
705 EOF
706
707 test_expect_success bool '
708
709 git config bool.true1 01 &&
710 git config bool.true2 -1 &&
711 git config bool.true3 YeS &&
712 git config bool.true4 true &&
713 git config bool.false1 000 &&
714 git config bool.false2 "" &&
715 git config bool.false3 nO &&
716 git config bool.false4 FALSE &&
717 rm -f result &&
718 for i in 1 2 3 4
719 do
720 git config --bool --get bool.true$i >>result
721 git config --bool --get bool.false$i >>result
722 done &&
723 test_cmp expect result'
724
725 test_expect_success 'invalid bool (--get)' '
726
727 git config bool.nobool foobar &&
728 test_must_fail git config --bool --get bool.nobool'
729
730 test_expect_success 'invalid bool (set)' '
731
732 test_must_fail git config --bool bool.nobool foobar'
733
734 cat > expect <<\EOF
735 [bool]
736 true1 = true
737 true2 = true
738 true3 = true
739 true4 = true
740 false1 = false
741 false2 = false
742 false3 = false
743 false4 = false
744 EOF
745
746 test_expect_success 'set --bool' '
747
748 rm -f .git/config &&
749 git config --bool bool.true1 01 &&
750 git config --bool bool.true2 -1 &&
751 git config --bool bool.true3 YeS &&
752 git config --bool bool.true4 true &&
753 git config --bool bool.false1 000 &&
754 git config --bool bool.false2 "" &&
755 git config --bool bool.false3 nO &&
756 git config --bool bool.false4 FALSE &&
757 test_cmp expect .git/config'
758
759 cat > expect <<\EOF
760 [int]
761 val1 = 1
762 val2 = -1
763 val3 = 5242880
764 EOF
765
766 test_expect_success 'set --int' '
767
768 rm -f .git/config &&
769 git config --int int.val1 01 &&
770 git config --int int.val2 -1 &&
771 git config --int int.val3 5m &&
772 test_cmp expect .git/config
773 '
774
775 test_expect_success 'get --bool-or-int' '
776 cat >.git/config <<-\EOF &&
777 [bool]
778 true1
779 true2 = true
780 false = false
781 [int]
782 int1 = 0
783 int2 = 1
784 int3 = -1
785 EOF
786 cat >expect <<-\EOF &&
787 true
788 true
789 false
790 0
791 1
792 -1
793 EOF
794 {
795 git config --bool-or-int bool.true1 &&
796 git config --bool-or-int bool.true2 &&
797 git config --bool-or-int bool.false &&
798 git config --bool-or-int int.int1 &&
799 git config --bool-or-int int.int2 &&
800 git config --bool-or-int int.int3
801 } >actual &&
802 test_cmp expect actual
803 '
804
805 cat >expect <<\EOF
806 [bool]
807 true1 = true
808 false1 = false
809 true2 = true
810 false2 = false
811 [int]
812 int1 = 0
813 int2 = 1
814 int3 = -1
815 EOF
816
817 test_expect_success 'set --bool-or-int' '
818 rm -f .git/config &&
819 git config --bool-or-int bool.true1 true &&
820 git config --bool-or-int bool.false1 false &&
821 git config --bool-or-int bool.true2 yes &&
822 git config --bool-or-int bool.false2 no &&
823 git config --bool-or-int int.int1 0 &&
824 git config --bool-or-int int.int2 1 &&
825 git config --bool-or-int int.int3 -1 &&
826 test_cmp expect .git/config
827 '
828
829 cat >expect <<\EOF
830 [path]
831 home = ~/
832 normal = /dev/null
833 trailingtilde = foo~
834 EOF
835
836 test_expect_success !MINGW 'set --path' '
837 rm -f .git/config &&
838 git config --path path.home "~/" &&
839 git config --path path.normal "/dev/null" &&
840 git config --path path.trailingtilde "foo~" &&
841 test_cmp expect .git/config'
842
843 if test_have_prereq !MINGW && test "${HOME+set}"
844 then
845 test_set_prereq HOMEVAR
846 fi
847
848 cat >expect <<EOF
849 $HOME/
850 /dev/null
851 foo~
852 EOF
853
854 test_expect_success HOMEVAR 'get --path' '
855 git config --get --path path.home > result &&
856 git config --get --path path.normal >> result &&
857 git config --get --path path.trailingtilde >> result &&
858 test_cmp expect result
859 '
860
861 cat >expect <<\EOF
862 /dev/null
863 foo~
864 EOF
865
866 test_expect_success !MINGW 'get --path copes with unset $HOME' '
867 (
868 sane_unset HOME &&
869 test_must_fail git config --get --path path.home \
870 >result 2>msg &&
871 git config --get --path path.normal >>result &&
872 git config --get --path path.trailingtilde >>result
873 ) &&
874 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
875 test_cmp expect result
876 '
877
878 test_expect_success 'get --path barfs on boolean variable' '
879 echo "[path]bool" >.git/config &&
880 test_must_fail git config --get --path path.bool
881 '
882
883 test_expect_success 'get --expiry-date' '
884 rel="3.weeks.5.days.00:00" &&
885 rel_out="$rel ->" &&
886 cat >.git/config <<-\EOF &&
887 [date]
888 valid1 = "3.weeks.5.days 00:00"
889 valid2 = "Fri Jun 4 15:46:55 2010"
890 valid3 = "2017/11/11 11:11:11PM"
891 valid4 = "2017/11/10 09:08:07 PM"
892 valid5 = "never"
893 invalid1 = "abc"
894 EOF
895 cat >expect <<-EOF &&
896 $(test-tool date timestamp $rel)
897 1275666415
898 1510441871
899 1510348087
900 0
901 EOF
902 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
903 {
904 echo "$rel_out $(git config --expiry-date date.valid1)"
905 git config --expiry-date date.valid2 &&
906 git config --expiry-date date.valid3 &&
907 git config --expiry-date date.valid4 &&
908 git config --expiry-date date.valid5
909 } >actual &&
910 test_cmp expect actual &&
911 test_must_fail git config --expiry-date date.invalid1
912 '
913
914 test_expect_success 'get --type=color' '
915 rm .git/config &&
916 git config foo.color "red" &&
917 git config --get --type=color foo.color >actual.raw &&
918 test_decode_color <actual.raw >actual &&
919 echo "<RED>" >expect &&
920 test_cmp expect actual
921 '
922
923 cat >expect << EOF
924 [foo]
925 color = red
926 EOF
927
928 test_expect_success 'set --type=color' '
929 rm .git/config &&
930 git config --type=color foo.color "red" &&
931 test_cmp expect .git/config
932 '
933
934 test_expect_success 'get --type=color barfs on non-color' '
935 echo "[foo]bar=not-a-color" >.git/config &&
936 test_must_fail git config --get --type=color foo.bar
937 '
938
939 test_expect_success 'set --type=color barfs on non-color' '
940 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
941 test_i18ngrep "cannot parse color" error
942 '
943
944 cat > expect << EOF
945 [quote]
946 leading = " test"
947 ending = "test "
948 semicolon = "test;test"
949 hash = "test#test"
950 EOF
951 test_expect_success 'quoting' '
952 rm -f .git/config &&
953 git config quote.leading " test" &&
954 git config quote.ending "test " &&
955 git config quote.semicolon "test;test" &&
956 git config quote.hash "test#test" &&
957 test_cmp expect .git/config
958 '
959
960 test_expect_success 'key with newline' '
961 test_must_fail git config "key.with
962 newline" 123'
963
964 test_expect_success 'value with newline' 'git config key.sub value.with\\\
965 newline'
966
967 cat > .git/config <<\EOF
968 [section]
969 ; comment \
970 continued = cont\
971 inued
972 noncont = not continued ; \
973 quotecont = "cont;\
974 inued"
975 EOF
976
977 cat > expect <<\EOF
978 section.continued=continued
979 section.noncont=not continued
980 section.quotecont=cont;inued
981 EOF
982
983 test_expect_success 'value continued on next line' '
984 git config --list > result &&
985 test_cmp expect result
986 '
987
988 cat > .git/config <<\EOF
989 [section "sub=section"]
990 val1 = foo=bar
991 val2 = foo\nbar
992 val3 = \n\n
993 val4 =
994 val5
995 EOF
996
997 cat > expect <<\EOF
998 section.sub=section.val1
999 foo=barQsection.sub=section.val2
1000 foo
1001 barQsection.sub=section.val3
1002
1003
1004 Qsection.sub=section.val4
1005 Qsection.sub=section.val5Q
1006 EOF
1007 test_expect_success '--null --list' '
1008 git config --null --list >result.raw &&
1009 nul_to_q <result.raw >result &&
1010 echo >>result &&
1011 test_cmp expect result
1012 '
1013
1014 test_expect_success '--null --get-regexp' '
1015 git config --null --get-regexp "val[0-9]" >result.raw &&
1016 nul_to_q <result.raw >result &&
1017 echo >>result &&
1018 test_cmp expect result
1019 '
1020
1021 test_expect_success 'inner whitespace kept verbatim' '
1022 git config section.val "foo bar" &&
1023 test_cmp_config "foo bar" section.val
1024 '
1025
1026 test_expect_success SYMLINKS 'symlinked configuration' '
1027 ln -s notyet myconfig &&
1028 git config --file=myconfig test.frotz nitfol &&
1029 test -h myconfig &&
1030 test -f notyet &&
1031 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1032 git config --file=myconfig test.xyzzy rezrov &&
1033 test -h myconfig &&
1034 test -f notyet &&
1035 cat >expect <<-\EOF &&
1036 nitfol
1037 rezrov
1038 EOF
1039 {
1040 git config --file=notyet test.frotz &&
1041 git config --file=notyet test.xyzzy
1042 } >actual &&
1043 test_cmp expect actual
1044 '
1045
1046 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1047 ln -s doesnotexist linktonada &&
1048 ln -s linktonada linktolinktonada &&
1049 test_must_fail git config --file=linktonada --list &&
1050 test_must_fail git config --file=linktolinktonada --list
1051 '
1052
1053 test_expect_success 'check split_cmdline return' "
1054 git config alias.split-cmdline-fix 'echo \"' &&
1055 test_must_fail git split-cmdline-fix &&
1056 echo foo > foo &&
1057 git add foo &&
1058 git commit -m 'initial commit' &&
1059 git config branch.main.mergeoptions 'echo \"' &&
1060 test_must_fail git merge main
1061 "
1062
1063 test_expect_success 'git -c "key=value" support' '
1064 cat >expect <<-\EOF &&
1065 value
1066 value
1067 true
1068 EOF
1069 {
1070 git -c section.name=value config section.name &&
1071 git -c foo.CamelCase=value config foo.camelcase &&
1072 git -c foo.flag config --bool foo.flag
1073 } >actual &&
1074 test_cmp expect actual &&
1075 test_must_fail git -c name=value config section.name
1076 '
1077
1078 # We just need a type-specifier here that cares about the
1079 # distinction internally between a NULL boolean and a real
1080 # string (because most of git's internal parsers do care).
1081 # Using "--path" works, but we do not otherwise care about
1082 # its semantics.
1083 test_expect_success 'git -c can represent empty string' '
1084 echo >expect &&
1085 git -c foo.empty= config --path foo.empty >actual &&
1086 test_cmp expect actual
1087 '
1088
1089 test_expect_success 'key sanity-checking' '
1090 test_must_fail git config foo=bar &&
1091 test_must_fail git config foo=.bar &&
1092 test_must_fail git config foo.ba=r &&
1093 test_must_fail git config foo.1bar &&
1094 test_must_fail git config foo."ba
1095 z".bar &&
1096 test_must_fail git config . false &&
1097 test_must_fail git config .foo false &&
1098 test_must_fail git config foo. false &&
1099 test_must_fail git config .foo. false &&
1100 git config foo.bar true &&
1101 git config foo."ba =z".bar false
1102 '
1103
1104 test_expect_success 'git -c works with aliases of builtins' '
1105 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1106 echo bar >expect &&
1107 git checkconfig >actual &&
1108 test_cmp expect actual
1109 '
1110
1111 test_expect_success 'aliases can be CamelCased' '
1112 test_config alias.CamelCased "rev-parse HEAD" &&
1113 git CamelCased >out &&
1114 git rev-parse HEAD >expect &&
1115 test_cmp expect out
1116 '
1117
1118 test_expect_success 'git -c does not split values on equals' '
1119 echo "value with = in it" >expect &&
1120 git -c section.foo="value with = in it" config section.foo >actual &&
1121 test_cmp expect actual
1122 '
1123
1124 test_expect_success 'git -c dies on bogus config' '
1125 test_must_fail git -c core.bare=foo rev-parse
1126 '
1127
1128 test_expect_success 'git -c complains about empty key' '
1129 test_must_fail git -c "=foo" rev-parse
1130 '
1131
1132 test_expect_success 'git -c complains about empty key and value' '
1133 test_must_fail git -c "" rev-parse
1134 '
1135
1136 test_expect_success 'multiple git -c appends config' '
1137 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1138 cat >expect <<-\EOF &&
1139 x.one 1
1140 x.two 2
1141 EOF
1142 git -c x.one=1 x >actual &&
1143 test_cmp expect actual
1144 '
1145
1146 test_expect_success 'last one wins: two level vars' '
1147
1148 # sec.var and sec.VAR are the same variable, as the first
1149 # and the last level of a configuration variable name is
1150 # case insensitive.
1151
1152 echo VAL >expect &&
1153
1154 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1155 test_cmp expect actual &&
1156 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1157 test_cmp expect actual &&
1158
1159 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1160 test_cmp expect actual &&
1161 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1162 test_cmp expect actual
1163 '
1164
1165 test_expect_success 'last one wins: three level vars' '
1166
1167 # v.a.r and v.A.r are not the same variable, as the middle
1168 # level of a three-level configuration variable name is
1169 # case sensitive.
1170
1171 echo val >expect &&
1172 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1173 test_cmp expect actual &&
1174 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1175 test_cmp expect actual &&
1176
1177 # v.a.r and V.a.R are the same variable, as the first
1178 # and the last level of a configuration variable name is
1179 # case insensitive.
1180
1181 echo VAL >expect &&
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 &&
1188 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1189 test_cmp expect actual
1190 '
1191
1192 test_expect_success 'old-fashioned settings are case insensitive' '
1193 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1194
1195 cat >testConfig_actual <<-EOF &&
1196 [V.A]
1197 r = value1
1198 EOF
1199 q_to_tab >testConfig_expect <<-EOF &&
1200 [V.A]
1201 Qr = value2
1202 EOF
1203 git config -f testConfig_actual "v.a.r" value2 &&
1204 test_cmp testConfig_expect testConfig_actual &&
1205
1206 cat >testConfig_actual <<-EOF &&
1207 [V.A]
1208 r = value1
1209 EOF
1210 q_to_tab >testConfig_expect <<-EOF &&
1211 [V.A]
1212 QR = value2
1213 EOF
1214 git config -f testConfig_actual "V.a.R" value2 &&
1215 test_cmp testConfig_expect testConfig_actual &&
1216
1217 cat >testConfig_actual <<-EOF &&
1218 [V.A]
1219 r = value1
1220 EOF
1221 q_to_tab >testConfig_expect <<-EOF &&
1222 [V.A]
1223 r = value1
1224 Qr = value2
1225 EOF
1226 git config -f testConfig_actual "V.A.r" value2 &&
1227 test_cmp testConfig_expect testConfig_actual &&
1228
1229 cat >testConfig_actual <<-EOF &&
1230 [V.A]
1231 r = value1
1232 EOF
1233 q_to_tab >testConfig_expect <<-EOF &&
1234 [V.A]
1235 r = value1
1236 Qr = value2
1237 EOF
1238 git config -f testConfig_actual "v.A.r" value2 &&
1239 test_cmp testConfig_expect testConfig_actual
1240 '
1241
1242 test_expect_success 'setting different case sensitive subsections ' '
1243 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1244
1245 cat >testConfig_actual <<-EOF &&
1246 [V "A"]
1247 R = v1
1248 [K "E"]
1249 Y = v1
1250 [a "b"]
1251 c = v1
1252 [d "e"]
1253 f = v1
1254 EOF
1255 q_to_tab >testConfig_expect <<-EOF &&
1256 [V "A"]
1257 Qr = v2
1258 [K "E"]
1259 Qy = v2
1260 [a "b"]
1261 Qc = v2
1262 [d "e"]
1263 f = v1
1264 [d "E"]
1265 Qf = v2
1266 EOF
1267 # exact match
1268 git config -f testConfig_actual a.b.c v2 &&
1269 # match section and subsection, key is cased differently.
1270 git config -f testConfig_actual K.E.y v2 &&
1271 # section and key are matched case insensitive, but subsection needs
1272 # to match; When writing out new values only the key is adjusted
1273 git config -f testConfig_actual v.A.r v2 &&
1274 # subsection is not matched:
1275 git config -f testConfig_actual d.E.f v2 &&
1276 test_cmp testConfig_expect testConfig_actual
1277 '
1278
1279 for VAR in a .a a. a.0b a."b c". a."b c".0d
1280 do
1281 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1282 test_must_fail git -c "$VAR=VAL" config -l
1283 '
1284 done
1285
1286 for VAR in a.b a."b c".d
1287 do
1288 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1289 echo VAL >expect &&
1290 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1291 test_cmp expect actual
1292 '
1293 done
1294
1295 test_expect_success 'git -c is not confused by empty environment' '
1296 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1297 '
1298
1299 test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1300 v="${SQ}key.one=foo${SQ}" &&
1301 v="$v ${SQ}key.two=bar${SQ}" &&
1302 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1303 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1304 cat >expect <<-EOF &&
1305 key.one foo
1306 key.two bar
1307 key.ambiguous section.whatever=value
1308 EOF
1309 test_cmp expect actual
1310 '
1311
1312 test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1313 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1314 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1315 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1316 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1317 cat >expect <<-EOF &&
1318 key.one foo
1319 key.two bar
1320 key.ambiguous=section.whatever value
1321 EOF
1322 test_cmp expect actual
1323 '
1324
1325 test_expect_success 'old and new-style entries can mix' '
1326 v="${SQ}key.oldone=oldfoo${SQ}" &&
1327 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1328 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1329 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1330 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1331 cat >expect <<-EOF &&
1332 key.oldone oldfoo
1333 key.newone newfoo
1334 key.oldtwo oldbar
1335 key.newtwo newbar
1336 EOF
1337 test_cmp expect actual
1338 '
1339
1340 test_expect_success 'old and new bools with ambiguous subsection' '
1341 v="${SQ}key.with=equals.oldbool${SQ}" &&
1342 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1343 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1344 cat >expect <<-EOF &&
1345 key.with equals.oldbool
1346 key.with=equals.newbool
1347 EOF
1348 test_cmp expect actual
1349 '
1350
1351 test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1352 cat >expect <<-\EOF &&
1353 env.one one
1354 env.two two
1355 EOF
1356 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1357 git config --get-regexp "env.*" >actual &&
1358 test_cmp expect actual &&
1359
1360 cat >expect <<-EOF &&
1361 env.one one${SQ}
1362 env.two two
1363 EOF
1364 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1365 git config --get-regexp "env.*" >actual &&
1366 test_cmp expect actual &&
1367
1368 test_must_fail env \
1369 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1370 git config --get-regexp "env.*"
1371 '
1372
1373 test_expect_success 'git --config-env=key=envvar support' '
1374 cat >expect <<-\EOF &&
1375 value
1376 value
1377 value
1378 value
1379 false
1380 false
1381 EOF
1382 {
1383 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1384 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1385 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1386 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1387 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1388 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1389 } >actual &&
1390 test_cmp expect actual
1391 '
1392
1393 test_expect_success 'git --config-env with missing value' '
1394 test_must_fail env ENVVAR=value git --config-env 2>error &&
1395 grep "no config key given for --config-env" error &&
1396 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1397 grep "invalid config format: config" error
1398 '
1399
1400 test_expect_success 'git --config-env fails with invalid parameters' '
1401 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1402 test_i18ngrep "invalid config format: foo.flag" error &&
1403 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1404 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1405 sane_unset NONEXISTENT &&
1406 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1407 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1408 '
1409
1410 test_expect_success 'git -c and --config-env work together' '
1411 cat >expect <<-\EOF &&
1412 bar.cmd cmd-value
1413 bar.env env-value
1414 EOF
1415 ENVVAR=env-value git \
1416 -c bar.cmd=cmd-value \
1417 --config-env=bar.env=ENVVAR \
1418 config --get-regexp "^bar.*" >actual &&
1419 test_cmp expect actual
1420 '
1421
1422 test_expect_success 'git -c and --config-env override each other' '
1423 cat >expect <<-\EOF &&
1424 env
1425 cmd
1426 EOF
1427 {
1428 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1429 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1430 } >actual &&
1431 test_cmp expect actual
1432 '
1433
1434 test_expect_success '--config-env handles keys with equals' '
1435 echo value=with=equals >expect &&
1436 ENVVAR=value=with=equals git \
1437 --config-env=section.subsection=with=equals.key=ENVVAR \
1438 config section.subsection=with=equals.key >actual &&
1439 test_cmp expect actual
1440 '
1441
1442 test_expect_success 'git config handles environment config pairs' '
1443 GIT_CONFIG_COUNT=2 \
1444 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1445 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1446 git config --get-regexp "pair.*" >actual &&
1447 cat >expect <<-EOF &&
1448 pair.one foo
1449 pair.two bar
1450 EOF
1451 test_cmp expect actual
1452 '
1453
1454 test_expect_success 'git config ignores pairs without count' '
1455 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1456 git config pair.one 2>error &&
1457 test_must_be_empty error
1458 '
1459
1460 test_expect_success 'git config ignores pairs with zero count' '
1461 test_must_fail env \
1462 GIT_CONFIG_COUNT=0 \
1463 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1464 git config pair.one
1465 '
1466
1467 test_expect_success 'git config ignores pairs exceeding count' '
1468 GIT_CONFIG_COUNT=1 \
1469 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1470 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1471 git config --get-regexp "pair.*" >actual &&
1472 cat >expect <<-EOF &&
1473 pair.one value
1474 EOF
1475 test_cmp expect actual
1476 '
1477
1478 test_expect_success 'git config ignores pairs with zero count' '
1479 test_must_fail env \
1480 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1481 git config pair.one >error &&
1482 test_must_be_empty error
1483 '
1484
1485 test_expect_success 'git config ignores pairs with empty count' '
1486 test_must_fail env \
1487 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1488 git config pair.one >error &&
1489 test_must_be_empty error
1490 '
1491
1492 test_expect_success 'git config fails with invalid count' '
1493 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1494 test_i18ngrep "bogus count" error &&
1495 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1496 test_i18ngrep "too many entries" error
1497 '
1498
1499 test_expect_success 'git config fails with missing config key' '
1500 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1501 git config --list 2>error &&
1502 test_i18ngrep "missing config key" error
1503 '
1504
1505 test_expect_success 'git config fails with missing config value' '
1506 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1507 git config --list 2>error &&
1508 test_i18ngrep "missing config value" error
1509 '
1510
1511 test_expect_success 'git config fails with invalid config pair key' '
1512 test_must_fail env GIT_CONFIG_COUNT=1 \
1513 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1514 git config --list &&
1515 test_must_fail env GIT_CONFIG_COUNT=1 \
1516 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1517 git config --list
1518 '
1519
1520 test_expect_success 'environment overrides config file' '
1521 test_when_finished "rm -f .git/config" &&
1522 cat >.git/config <<-EOF &&
1523 [pair]
1524 one = value
1525 EOF
1526 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1527 git config pair.one >actual &&
1528 cat >expect <<-EOF &&
1529 override
1530 EOF
1531 test_cmp expect actual
1532 '
1533
1534 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1535 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1536 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1537 git config pair.one >actual &&
1538 cat >expect <<-EOF &&
1539 override
1540 EOF
1541 test_cmp expect actual
1542 '
1543
1544 test_expect_success 'command line overrides environment config' '
1545 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1546 git -c pair.one=override config pair.one >actual &&
1547 cat >expect <<-EOF &&
1548 override
1549 EOF
1550 test_cmp expect actual
1551 '
1552
1553 test_expect_success 'git config --edit works' '
1554 git config -f tmp test.value no &&
1555 echo test.value=yes >expect &&
1556 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1557 git config -f tmp --list >actual &&
1558 test_cmp expect actual
1559 '
1560
1561 test_expect_success 'git config --edit respects core.editor' '
1562 git config -f tmp test.value no &&
1563 echo test.value=yes >expect &&
1564 test_config core.editor "echo [test]value=yes >" &&
1565 git config -f tmp --edit &&
1566 git config -f tmp --list >actual &&
1567 test_cmp expect actual
1568 '
1569
1570 # malformed configuration files
1571 test_expect_success 'barf on syntax error' '
1572 cat >.git/config <<-\EOF &&
1573 # broken section line
1574 [section]
1575 key garbage
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 'barf on incomplete section header' '
1582 cat >.git/config <<-\EOF &&
1583 # broken section line
1584 [section
1585 key = value
1586 EOF
1587 test_must_fail git config --get section.key >actual 2>error &&
1588 test_i18ngrep " line 2 " error
1589 '
1590
1591 test_expect_success 'barf on incomplete string' '
1592 cat >.git/config <<-\EOF &&
1593 # broken section line
1594 [section]
1595 key = "value string
1596 EOF
1597 test_must_fail git config --get section.key >actual 2>error &&
1598 test_i18ngrep " line 3 " error
1599 '
1600
1601 test_expect_success 'urlmatch' '
1602 cat >.git/config <<-\EOF &&
1603 [http]
1604 sslVerify
1605 [http "https://weak.example.com"]
1606 sslVerify = false
1607 cookieFile = /tmp/cookie.txt
1608 EOF
1609
1610 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1611 test_must_be_empty actual &&
1612
1613 echo true >expect &&
1614 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1615 test_cmp expect actual &&
1616
1617 echo false >expect &&
1618 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1619 test_cmp expect actual &&
1620
1621 {
1622 echo http.cookiefile /tmp/cookie.txt &&
1623 echo http.sslverify false
1624 } >expect &&
1625 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1626 test_cmp expect actual
1627 '
1628
1629 test_expect_success 'urlmatch favors more specific URLs' '
1630 cat >.git/config <<-\EOF &&
1631 [http "https://example.com/"]
1632 cookieFile = /tmp/root.txt
1633 [http "https://example.com/subdirectory"]
1634 cookieFile = /tmp/subdirectory.txt
1635 [http "https://user@example.com/"]
1636 cookieFile = /tmp/user.txt
1637 [http "https://averylonguser@example.com/"]
1638 cookieFile = /tmp/averylonguser.txt
1639 [http "https://preceding.example.com"]
1640 cookieFile = /tmp/preceding.txt
1641 [http "https://*.example.com"]
1642 cookieFile = /tmp/wildcard.txt
1643 [http "https://*.example.com/wildcardwithsubdomain"]
1644 cookieFile = /tmp/wildcardwithsubdomain.txt
1645 [http "https://*.example.*"]
1646 cookieFile = /tmp/multiwildcard.txt
1647 [http "https://trailing.example.com"]
1648 cookieFile = /tmp/trailing.txt
1649 [http "https://user@*.example.com/"]
1650 cookieFile = /tmp/wildcardwithuser.txt
1651 [http "https://sub.example.com/"]
1652 cookieFile = /tmp/sub.txt
1653 EOF
1654
1655 echo http.cookiefile /tmp/root.txt >expect &&
1656 git config --get-urlmatch HTTP https://example.com >actual &&
1657 test_cmp expect actual &&
1658
1659 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1660 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1661 test_cmp expect actual &&
1662
1663 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1664 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1665 test_cmp expect actual &&
1666
1667 echo http.cookiefile /tmp/user.txt >expect &&
1668 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1669 test_cmp expect actual &&
1670
1671 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1672 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1673 test_cmp expect actual &&
1674
1675 echo http.cookiefile /tmp/preceding.txt >expect &&
1676 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1677 test_cmp expect actual &&
1678
1679 echo http.cookiefile /tmp/wildcard.txt >expect &&
1680 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1681 test_cmp expect actual &&
1682
1683 echo http.cookiefile /tmp/sub.txt >expect &&
1684 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1685 test_cmp expect actual &&
1686
1687 echo http.cookiefile /tmp/trailing.txt >expect &&
1688 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1689 test_cmp expect actual &&
1690
1691 echo http.cookiefile /tmp/sub.txt >expect &&
1692 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1693 test_cmp expect actual &&
1694
1695 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1696 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1697 test_cmp expect actual
1698 '
1699
1700 test_expect_success 'urlmatch with wildcard' '
1701 cat >.git/config <<-\EOF &&
1702 [http]
1703 sslVerify
1704 [http "https://*.example.com"]
1705 sslVerify = false
1706 cookieFile = /tmp/cookie.txt
1707 EOF
1708
1709 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1710 test_must_be_empty actual &&
1711
1712 echo true >expect &&
1713 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1714 test_cmp expect actual &&
1715
1716 echo true >expect &&
1717 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1718 test_cmp expect actual &&
1719
1720 echo true >expect &&
1721 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1722 test_cmp expect actual &&
1723
1724 echo false >expect &&
1725 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1726 test_cmp expect actual &&
1727
1728 {
1729 echo http.cookiefile /tmp/cookie.txt &&
1730 echo http.sslverify false
1731 } >expect &&
1732 git config --get-urlmatch HTTP https://good.example.com >actual &&
1733 test_cmp expect actual &&
1734
1735 echo http.sslverify >expect &&
1736 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
1737 test_cmp expect actual
1738 '
1739
1740 # good section hygiene
1741 test_expect_success '--unset last key removes section (except if commented)' '
1742 cat >.git/config <<-\EOF &&
1743 # some generic comment on the configuration file itself
1744 # a comment specific to this "section" section.
1745 [section]
1746 # some intervening lines
1747 # that should also be dropped
1748
1749 key = value
1750 # please be careful when you update the above variable
1751 EOF
1752
1753 cat >expect <<-\EOF &&
1754 # some generic comment on the configuration file itself
1755 # a comment specific to this "section" section.
1756 [section]
1757 # some intervening lines
1758 # that should also be dropped
1759
1760 # please be careful when you update the above variable
1761 EOF
1762
1763 git config --unset section.key &&
1764 test_cmp expect .git/config &&
1765
1766 cat >.git/config <<-\EOF &&
1767 [section]
1768 key = value
1769 [next-section]
1770 EOF
1771
1772 cat >expect <<-\EOF &&
1773 [next-section]
1774 EOF
1775
1776 git config --unset section.key &&
1777 test_cmp expect .git/config &&
1778
1779 q_to_tab >.git/config <<-\EOF &&
1780 [one]
1781 Qkey = "multiline \
1782 QQ# with comment"
1783 [two]
1784 key = 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 = "multiline \
1792 QQ# with comment"
1793 [one]
1794 key = true
1795 EOF
1796 git config --unset-all one.key &&
1797 test_line_count = 0 .git/config &&
1798
1799 q_to_tab >.git/config <<-\EOF &&
1800 [one]
1801 Qkey = true
1802 Q# a comment not at the start
1803 [two]
1804 Qkey = true
1805 EOF
1806 git config --unset two.key &&
1807 grep two .git/config &&
1808
1809 q_to_tab >.git/config <<-\EOF &&
1810 [one]
1811 Qkey = not [two "subsection"]
1812 [two "subsection"]
1813 [two "subsection"]
1814 Qkey = true
1815 [TWO "subsection"]
1816 [one]
1817 EOF
1818 git config --unset two.subsection.key &&
1819 test "not [two subsection]" = "$(git config one.key)" &&
1820 test_line_count = 3 .git/config
1821 '
1822
1823 test_expect_success '--unset-all removes section if empty & uncommented' '
1824 cat >.git/config <<-\EOF &&
1825 [section]
1826 key = value1
1827 key = value2
1828 EOF
1829
1830 git config --unset-all section.key &&
1831 test_line_count = 0 .git/config
1832 '
1833
1834 test_expect_success 'adding a key into an empty section reuses header' '
1835 cat >.git/config <<-\EOF &&
1836 [section]
1837 EOF
1838
1839 q_to_tab >expect <<-\EOF &&
1840 [section]
1841 Qkey = value
1842 EOF
1843
1844 git config section.key value &&
1845 test_cmp expect .git/config
1846 '
1847
1848 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1849 chmod 0600 .git/config &&
1850 git config imap.pass Hunter2 &&
1851 perl -e \
1852 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1853 git config --rename-section imap pop &&
1854 perl -e \
1855 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1856 '
1857
1858 ! test_have_prereq MINGW ||
1859 HOME="$(pwd)" # convert to Windows path
1860
1861 test_expect_success 'set up --show-origin tests' '
1862 INCLUDE_DIR="$HOME/include" &&
1863 mkdir -p "$INCLUDE_DIR" &&
1864 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1865 [user]
1866 absolute = include
1867 EOF
1868 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1869 [user]
1870 relative = include
1871 EOF
1872 cat >"$HOME"/.gitconfig <<-EOF &&
1873 [user]
1874 global = true
1875 override = global
1876 [include]
1877 path = "$INCLUDE_DIR/absolute.include"
1878 EOF
1879 cat >.git/config <<-\EOF
1880 [user]
1881 local = true
1882 override = local
1883 [include]
1884 path = ../include/relative.include
1885 EOF
1886 '
1887
1888 test_expect_success '--show-origin with --list' '
1889 cat >expect <<-EOF &&
1890 file:$HOME/.gitconfig user.global=true
1891 file:$HOME/.gitconfig user.override=global
1892 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1893 file:$INCLUDE_DIR/absolute.include user.absolute=include
1894 file:.git/config user.local=true
1895 file:.git/config user.override=local
1896 file:.git/config include.path=../include/relative.include
1897 file:.git/../include/relative.include user.relative=include
1898 command line: user.environ=true
1899 command line: user.cmdline=true
1900 EOF
1901 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
1902 git -c user.cmdline=true config --list --show-origin >output &&
1903 test_cmp expect output
1904 '
1905
1906 test_expect_success '--show-origin with --list --null' '
1907 cat >expect <<-EOF &&
1908 file:$HOME/.gitconfigQuser.global
1909 trueQfile:$HOME/.gitconfigQuser.override
1910 globalQfile:$HOME/.gitconfigQinclude.path
1911 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1912 includeQfile:.git/configQuser.local
1913 trueQfile:.git/configQuser.override
1914 localQfile:.git/configQinclude.path
1915 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1916 includeQcommand line:Quser.cmdline
1917 trueQ
1918 EOF
1919 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1920 nul_to_q <output.raw >output &&
1921 # The here-doc above adds a newline that the --null output would not
1922 # include. Add it here to make the two comparable.
1923 echo >>output &&
1924 test_cmp expect output
1925 '
1926
1927 test_expect_success '--show-origin with single file' '
1928 cat >expect <<-\EOF &&
1929 file:.git/config user.local=true
1930 file:.git/config user.override=local
1931 file:.git/config include.path=../include/relative.include
1932 EOF
1933 git config --local --list --show-origin >output &&
1934 test_cmp expect output
1935 '
1936
1937 test_expect_success '--show-origin with --get-regexp' '
1938 cat >expect <<-EOF &&
1939 file:$HOME/.gitconfig user.global true
1940 file:.git/config user.local true
1941 EOF
1942 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1943 test_cmp expect output
1944 '
1945
1946 test_expect_success '--show-origin getting a single key' '
1947 cat >expect <<-\EOF &&
1948 file:.git/config local
1949 EOF
1950 git config --show-origin user.override >output &&
1951 test_cmp expect output
1952 '
1953
1954 test_expect_success 'set up custom config file' '
1955 CUSTOM_CONFIG_FILE="custom.conf" &&
1956 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1957 [user]
1958 custom = true
1959 EOF
1960 '
1961
1962 test_expect_success !MINGW 'set up custom config file with special name characters' '
1963 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
1964 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
1965 '
1966
1967 test_expect_success !MINGW '--show-origin escape special file name characters' '
1968 cat >expect <<-\EOF &&
1969 file:"file\" (dq) and spaces.conf" user.custom=true
1970 EOF
1971 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
1972 test_cmp expect output
1973 '
1974
1975 test_expect_success '--show-origin stdin' '
1976 cat >expect <<-\EOF &&
1977 standard input: user.custom=true
1978 EOF
1979 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1980 test_cmp expect output
1981 '
1982
1983 test_expect_success '--show-origin stdin with file include' '
1984 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1985 [user]
1986 stdin = include
1987 EOF
1988 cat >expect <<-EOF &&
1989 file:$INCLUDE_DIR/stdin.include include
1990 EOF
1991 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
1992 git config --show-origin --includes --file - user.stdin >output &&
1993
1994 test_cmp expect output
1995 '
1996
1997 test_expect_success '--show-origin blob' '
1998 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1999 cat >expect <<-EOF &&
2000 blob:$blob user.custom=true
2001 EOF
2002 git config --blob=$blob --show-origin --list >output &&
2003 test_cmp expect output
2004 '
2005
2006 test_expect_success '--show-origin blob ref' '
2007 cat >expect <<-\EOF &&
2008 blob:main:custom.conf user.custom=true
2009 EOF
2010 git add "$CUSTOM_CONFIG_FILE" &&
2011 git commit -m "new config file" &&
2012 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2013 test_cmp expect output
2014 '
2015
2016 test_expect_success '--show-scope with --list' '
2017 cat >expect <<-EOF &&
2018 global user.global=true
2019 global user.override=global
2020 global include.path=$INCLUDE_DIR/absolute.include
2021 global user.absolute=include
2022 local user.local=true
2023 local user.override=local
2024 local include.path=../include/relative.include
2025 local user.relative=include
2026 command user.cmdline=true
2027 EOF
2028 git -c user.cmdline=true config --list --show-scope >output &&
2029 test_cmp expect output
2030 '
2031
2032 test_expect_success !MINGW '--show-scope with --blob' '
2033 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2034 cat >expect <<-EOF &&
2035 command user.custom=true
2036 EOF
2037 git config --blob=$blob --show-scope --list >output &&
2038 test_cmp expect output
2039 '
2040
2041 test_expect_success '--show-scope with --local' '
2042 cat >expect <<-\EOF &&
2043 local user.local=true
2044 local user.override=local
2045 local include.path=../include/relative.include
2046 EOF
2047 git config --local --list --show-scope >output &&
2048 test_cmp expect output
2049 '
2050
2051 test_expect_success '--show-scope getting a single value' '
2052 cat >expect <<-\EOF &&
2053 local true
2054 EOF
2055 git config --show-scope --get user.local >output &&
2056 test_cmp expect output
2057 '
2058
2059 test_expect_success '--show-scope with --show-origin' '
2060 cat >expect <<-EOF &&
2061 global file:$HOME/.gitconfig user.global=true
2062 global file:$HOME/.gitconfig user.override=global
2063 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2064 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2065 local file:.git/config user.local=true
2066 local file:.git/config user.override=local
2067 local file:.git/config include.path=../include/relative.include
2068 local file:.git/../include/relative.include user.relative=include
2069 command command line: user.cmdline=true
2070 EOF
2071 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2072 test_cmp expect output
2073 '
2074
2075 test_expect_success 'override global and system config' '
2076 test_when_finished rm -f "$HOME"/.config/git &&
2077
2078 cat >"$HOME"/.gitconfig <<-EOF &&
2079 [home]
2080 config = true
2081 EOF
2082 mkdir -p "$HOME"/.config/git &&
2083 cat >"$HOME"/.config/git/config <<-EOF &&
2084 [xdg]
2085 config = true
2086 EOF
2087 cat >.git/config <<-EOF &&
2088 [local]
2089 config = true
2090 EOF
2091 cat >custom-global-config <<-EOF &&
2092 [global]
2093 config = true
2094 EOF
2095 cat >custom-system-config <<-EOF &&
2096 [system]
2097 config = true
2098 EOF
2099
2100 cat >expect <<-EOF &&
2101 global xdg.config=true
2102 global home.config=true
2103 local local.config=true
2104 EOF
2105 git config --show-scope --list >output &&
2106 test_cmp expect output &&
2107
2108 cat >expect <<-EOF &&
2109 system system.config=true
2110 global global.config=true
2111 local local.config=true
2112 EOF
2113 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
2114 git config --show-scope --list >output &&
2115 test_cmp expect output &&
2116
2117 cat >expect <<-EOF &&
2118 local local.config=true
2119 EOF
2120 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2121 git config --show-scope --list >output &&
2122 test_cmp expect output
2123 '
2124
2125 test_expect_success 'override global and system config with missing file' '
2126 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2127 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2128 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2129 '
2130
2131 test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2132 # `git config --system` has different semantics compared to other
2133 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2134 # variable has an effect via a different proxy.
2135 cat >alias-config <<-EOF &&
2136 [alias]
2137 hello-world = !echo "hello world"
2138 EOF
2139 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2140 git hello-world &&
2141 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2142 git hello-world >actual &&
2143 echo "hello world" >expect &&
2144 test_cmp expect actual
2145 '
2146
2147 test_expect_success 'write to overridden global and system config' '
2148 cat >expect <<EOF &&
2149 [config]
2150 key = value
2151 EOF
2152
2153 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2154 test_cmp expect write-to-global &&
2155
2156 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2157 test_cmp expect write-to-system
2158 '
2159
2160 for opt in --local --worktree
2161 do
2162 test_expect_success "$opt requires a repo" '
2163 # we expect 128 to ensure that we do not simply
2164 # fail to find anything and return code "1"
2165 test_expect_code 128 nongit git config $opt foo.bar
2166 '
2167 done
2168
2169 cat >.git/config <<-\EOF &&
2170 [section]
2171 foo = true
2172 number = 10
2173 big = 1M
2174 EOF
2175
2176 test_expect_success 'identical modern --type specifiers are allowed' '
2177 test_cmp_config 1048576 --type=int --type=int section.big
2178 '
2179
2180 test_expect_success 'identical legacy --type specifiers are allowed' '
2181 test_cmp_config 1048576 --int --int section.big
2182 '
2183
2184 test_expect_success 'identical mixed --type specifiers are allowed' '
2185 test_cmp_config 1048576 --int --type=int section.big
2186 '
2187
2188 test_expect_success 'non-identical modern --type specifiers are not allowed' '
2189 test_must_fail git config --type=int --type=bool section.big 2>error &&
2190 test_i18ngrep "only one type at a time" error
2191 '
2192
2193 test_expect_success 'non-identical legacy --type specifiers are not allowed' '
2194 test_must_fail git config --int --bool section.big 2>error &&
2195 test_i18ngrep "only one type at a time" error
2196 '
2197
2198 test_expect_success 'non-identical mixed --type specifiers are not allowed' '
2199 test_must_fail git config --type=int --bool section.big 2>error &&
2200 test_i18ngrep "only one type at a time" error
2201 '
2202
2203 test_expect_success '--type allows valid type specifiers' '
2204 test_cmp_config true --type=bool section.foo
2205 '
2206
2207 test_expect_success '--no-type unsets type specifiers' '
2208 test_cmp_config 10 --type=bool --no-type section.number
2209 '
2210
2211 test_expect_success 'unset type specifiers may be reset to conflicting ones' '
2212 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
2213 '
2214
2215 test_expect_success '--type rejects unknown specifiers' '
2216 test_must_fail git config --type=nonsense section.foo 2>error &&
2217 test_i18ngrep "unrecognized --type argument" error
2218 '
2219
2220 test_expect_success '--replace-all does not invent newlines' '
2221 q_to_tab >.git/config <<-\EOF &&
2222 [abc]key
2223 QkeepSection
2224 [xyz]
2225 Qkey = 1
2226 [abc]
2227 Qkey = a
2228 EOF
2229 q_to_tab >expect <<-\EOF &&
2230 [abc]
2231 QkeepSection
2232 [xyz]
2233 Qkey = 1
2234 [abc]
2235 Qkey = b
2236 EOF
2237 git config --replace-all abc.key b &&
2238 test_cmp expect .git/config
2239 '
2240
2241 test_expect_success 'set all config with value-pattern' '
2242 test_when_finished rm -f config initial &&
2243 git config --file=initial abc.key one &&
2244
2245 # no match => add new entry
2246 cp initial config &&
2247 git config --file=config abc.key two a+ &&
2248 git config --file=config --list >actual &&
2249 cat >expect <<-\EOF &&
2250 abc.key=one
2251 abc.key=two
2252 EOF
2253 test_cmp expect actual &&
2254
2255 # multiple matches => failure
2256 test_must_fail git config --file=config abc.key three o+ 2>err &&
2257 test_i18ngrep "has multiple values" err &&
2258
2259 # multiple values, no match => add
2260 git config --file=config abc.key three a+ &&
2261 git config --file=config --list >actual &&
2262 cat >expect <<-\EOF &&
2263 abc.key=one
2264 abc.key=two
2265 abc.key=three
2266 EOF
2267 test_cmp expect actual &&
2268
2269 # single match => replace
2270 git config --file=config abc.key four h+ &&
2271 git config --file=config --list >actual &&
2272 cat >expect <<-\EOF &&
2273 abc.key=one
2274 abc.key=two
2275 abc.key=four
2276 EOF
2277 test_cmp expect actual
2278 '
2279
2280 test_expect_success '--replace-all and value-pattern' '
2281 test_when_finished rm -f config &&
2282 git config --file=config --add abc.key one &&
2283 git config --file=config --add abc.key two &&
2284 git config --file=config --add abc.key three &&
2285 git config --file=config --replace-all abc.key four "o+" &&
2286 git config --file=config --list >actual &&
2287 cat >expect <<-\EOF &&
2288 abc.key=four
2289 abc.key=three
2290 EOF
2291 test_cmp expect actual
2292 '
2293
2294 test_expect_success 'refuse --fixed-value for incompatible actions' '
2295 test_when_finished rm -f config &&
2296 git config --file=config dev.null bogus &&
2297
2298 # These modes do not allow --fixed-value at all
2299 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2300 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2301 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2302 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2303 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2304 test_must_fail git config --file=config --fixed-value --list &&
2305 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2306 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2307
2308 # These modes complain when --fixed-value has no value-pattern
2309 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2310 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2311 test_must_fail git config --file=config --fixed-value --get dev.null &&
2312 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2313 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2314 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2315 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2316 '
2317
2318 test_expect_success '--fixed-value uses exact string matching' '
2319 test_when_finished rm -f config initial &&
2320 META="a+b*c?d[e]f.g" &&
2321 git config --file=initial fixed.test "$META" &&
2322
2323 cp initial config &&
2324 git config --file=config fixed.test bogus "$META" &&
2325 git config --file=config --list >actual &&
2326 cat >expect <<-EOF &&
2327 fixed.test=$META
2328 fixed.test=bogus
2329 EOF
2330 test_cmp expect actual &&
2331
2332 cp initial config &&
2333 git config --file=config --fixed-value fixed.test bogus "$META" &&
2334 git config --file=config --list >actual &&
2335 cat >expect <<-\EOF &&
2336 fixed.test=bogus
2337 EOF
2338 test_cmp expect actual &&
2339
2340 cp initial config &&
2341 test_must_fail git config --file=config --unset fixed.test "$META" &&
2342 git config --file=config --fixed-value --unset fixed.test "$META" &&
2343 test_must_fail git config --file=config fixed.test &&
2344
2345 cp initial config &&
2346 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2347 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2348 test_must_fail git config --file=config fixed.test &&
2349
2350 cp initial config &&
2351 git config --file=config --replace-all fixed.test bogus "$META" &&
2352 git config --file=config --list >actual &&
2353 cat >expect <<-EOF &&
2354 fixed.test=$META
2355 fixed.test=bogus
2356 EOF
2357 test_cmp expect actual &&
2358
2359 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2360 git config --file=config --list >actual &&
2361 cat >expect <<-EOF &&
2362 fixed.test=bogus
2363 fixed.test=bogus
2364 EOF
2365 test_cmp expect actual
2366 '
2367
2368 test_expect_success '--get and --get-all with --fixed-value' '
2369 test_when_finished rm -f config &&
2370 META="a+b*c?d[e]f.g" &&
2371 git config --file=config fixed.test bogus &&
2372 git config --file=config --add fixed.test "$META" &&
2373
2374 git config --file=config --get fixed.test bogus &&
2375 test_must_fail git config --file=config --get fixed.test "$META" &&
2376 git config --file=config --get --fixed-value fixed.test "$META" &&
2377 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2378
2379 git config --file=config --get-all fixed.test bogus &&
2380 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2381 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2382 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2383
2384 git config --file=config --get-regexp fixed+ bogus &&
2385 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2386 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2387 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2388 '
2389
2390 test_done