test: remove httpd tests that ask for user
[git] / t / t1300-repo-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 . ./test-lib.sh
9
10 test_expect_success 'clear default config' '
11         rm -f .git/config
12 '
13
14 cat > expect << EOF
15 [core]
16         penguin = little blue
17 EOF
18 test_expect_success 'initial' '
19         git config core.penguin "little blue" &&
20         test_cmp expect .git/config
21 '
22
23 cat > expect << EOF
24 [core]
25         penguin = little blue
26         Movie = BadPhysics
27 EOF
28 test_expect_success 'mixed case' '
29         git config Core.Movie BadPhysics &&
30         test_cmp expect .git/config
31 '
32
33 cat > expect << EOF
34 [core]
35         penguin = little blue
36         Movie = BadPhysics
37 [Cores]
38         WhatEver = Second
39 EOF
40 test_expect_success 'similar section' '
41         git config Cores.WhatEver Second &&
42         test_cmp expect .git/config
43 '
44
45 cat > expect << EOF
46 [core]
47         penguin = little blue
48         Movie = BadPhysics
49         UPPERCASE = true
50 [Cores]
51         WhatEver = Second
52 EOF
53 test_expect_success 'uppercase section' '
54         git config CORE.UPPERCASE true &&
55         test_cmp expect .git/config
56 '
57
58 test_expect_success 'replace with non-match' '
59         git config core.penguin kingpin !blue
60 '
61
62 test_expect_success 'replace with non-match (actually matching)' '
63         git config core.penguin "very blue" !kingpin
64 '
65
66 cat > expect << EOF
67 [core]
68         penguin = very blue
69         Movie = BadPhysics
70         UPPERCASE = true
71         penguin = kingpin
72 [Cores]
73         WhatEver = Second
74 EOF
75
76 test_expect_success 'non-match result' 'test_cmp expect .git/config'
77
78 test_expect_success 'find mixed-case key by canonical name' '
79         echo Second >expect &&
80         git config cores.whatever >actual &&
81         test_cmp expect actual
82 '
83
84 test_expect_success 'find mixed-case key by non-canonical name' '
85         echo Second >expect &&
86         git config CoReS.WhAtEvEr >actual &&
87         test_cmp expect actual
88 '
89
90 test_expect_success 'subsections are not canonicalized by git-config' '
91         cat >>.git/config <<-\EOF &&
92         [section.SubSection]
93         key = one
94         [section "SubSection"]
95         key = two
96         EOF
97         echo one >expect &&
98         git config section.subsection.key >actual &&
99         test_cmp expect actual &&
100         echo two >expect &&
101         git config section.SubSection.key >actual &&
102         test_cmp expect actual
103 '
104
105 cat > .git/config <<\EOF
106 [alpha]
107 bar = foo
108 [beta]
109 baz = multiple \
110 lines
111 EOF
112
113 test_expect_success 'unset with cont. lines' '
114         git config --unset beta.baz
115 '
116
117 cat > expect <<\EOF
118 [alpha]
119 bar = foo
120 [beta]
121 EOF
122
123 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
124
125 cat > .git/config << EOF
126 [beta] ; silly comment # another comment
127 noIndent= sillyValue ; 'nother silly comment
128
129 # empty line
130                 ; comment
131                 haha   ="beta" # last silly comment
132 haha = hello
133         haha = bello
134 [nextSection] noNewline = ouch
135 EOF
136
137 cp .git/config .git/config2
138
139 test_expect_success 'multiple unset' '
140         git config --unset-all beta.haha
141 '
142
143 cat > expect << EOF
144 [beta] ; silly comment # another comment
145 noIndent= sillyValue ; 'nother silly comment
146
147 # empty line
148                 ; comment
149 [nextSection] noNewline = ouch
150 EOF
151
152 test_expect_success 'multiple unset is correct' '
153         test_cmp expect .git/config
154 '
155
156 cp .git/config2 .git/config
157
158 test_expect_success '--replace-all missing value' '
159         test_must_fail git config --replace-all beta.haha &&
160         test_cmp .git/config2 .git/config
161 '
162
163 rm .git/config2
164
165 test_expect_success '--replace-all' '
166         git config --replace-all beta.haha gamma
167 '
168
169 cat > expect << EOF
170 [beta] ; silly comment # another comment
171 noIndent= sillyValue ; 'nother silly comment
172
173 # empty line
174                 ; comment
175         haha = gamma
176 [nextSection] noNewline = ouch
177 EOF
178
179 test_expect_success 'all replaced' '
180         test_cmp expect .git/config
181 '
182
183 cat > expect << EOF
184 [beta] ; silly comment # another comment
185 noIndent= sillyValue ; 'nother silly comment
186
187 # empty line
188                 ; comment
189         haha = alpha
190 [nextSection] noNewline = ouch
191 EOF
192 test_expect_success 'really mean test' '
193         git config beta.haha alpha &&
194         test_cmp expect .git/config
195 '
196
197 cat > expect << EOF
198 [beta] ; silly comment # another comment
199 noIndent= sillyValue ; 'nother silly comment
200
201 # empty line
202                 ; comment
203         haha = alpha
204 [nextSection]
205         nonewline = wow
206 EOF
207 test_expect_success 'really really mean test' '
208         git config nextsection.nonewline wow &&
209         test_cmp expect .git/config
210 '
211
212 test_expect_success 'get value' '
213         echo alpha >expect &&
214         git config beta.haha >actual &&
215         test_cmp expect actual
216 '
217
218 cat > expect << EOF
219 [beta] ; silly comment # another comment
220 noIndent= sillyValue ; 'nother silly comment
221
222 # empty line
223                 ; comment
224 [nextSection]
225         nonewline = wow
226 EOF
227 test_expect_success 'unset' '
228         git config --unset beta.haha &&
229         test_cmp expect .git/config
230 '
231
232 cat > expect << EOF
233 [beta] ; silly comment # another comment
234 noIndent= sillyValue ; 'nother silly comment
235
236 # empty line
237                 ; comment
238 [nextSection]
239         nonewline = wow
240         NoNewLine = wow2 for me
241 EOF
242 test_expect_success 'multivar' '
243         git config nextsection.NoNewLine "wow2 for me" "for me$" &&
244         test_cmp expect .git/config
245 '
246
247 test_expect_success 'non-match' '
248         git config --get nextsection.nonewline !for
249 '
250
251 test_expect_success 'non-match value' '
252         echo wow >expect &&
253         git config --get nextsection.nonewline !for >actual &&
254         test_cmp expect actual
255 '
256
257 test_expect_success 'multi-valued get returns final one' '
258         echo "wow2 for me" >expect &&
259         git config --get nextsection.nonewline >actual &&
260         test_cmp expect actual
261 '
262
263 test_expect_success 'multi-valued get-all returns all' '
264         cat >expect <<-\EOF &&
265         wow
266         wow2 for me
267         EOF
268         git config --get-all nextsection.nonewline >actual &&
269         test_cmp expect actual
270 '
271
272 cat > expect << EOF
273 [beta] ; silly comment # another comment
274 noIndent= sillyValue ; 'nother silly comment
275
276 # empty line
277                 ; comment
278 [nextSection]
279         nonewline = wow3
280         NoNewLine = wow2 for me
281 EOF
282 test_expect_success 'multivar replace' '
283         git config nextsection.nonewline "wow3" "wow$" &&
284         test_cmp expect .git/config
285 '
286
287 test_expect_success 'ambiguous unset' '
288         test_must_fail git config --unset nextsection.nonewline
289 '
290
291 test_expect_success 'invalid unset' '
292         test_must_fail git config --unset somesection.nonewline
293 '
294
295 cat > expect << EOF
296 [beta] ; silly comment # another comment
297 noIndent= sillyValue ; 'nother silly comment
298
299 # empty line
300                 ; comment
301 [nextSection]
302         NoNewLine = wow2 for me
303 EOF
304
305 test_expect_success 'multivar unset' '
306         git config --unset nextsection.nonewline "wow3$" &&
307         test_cmp expect .git/config
308 '
309
310 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
311
312 test_expect_success 'correct key' 'git config 123456.a123 987'
313
314 test_expect_success 'hierarchical section' '
315         git config Version.1.2.3eX.Alpha beta
316 '
317
318 cat > expect << EOF
319 [beta] ; silly comment # another comment
320 noIndent= sillyValue ; 'nother silly comment
321
322 # empty line
323                 ; comment
324 [nextSection]
325         NoNewLine = wow2 for me
326 [123456]
327         a123 = 987
328 [Version "1.2.3eX"]
329         Alpha = beta
330 EOF
331
332 test_expect_success 'hierarchical section value' '
333         test_cmp expect .git/config
334 '
335
336 cat > expect << EOF
337 alias.ci=commit
338 alias.co=checkout
339 alias.rb=rebase
340 alias.st=status
341 alias.br=branch
342 alias.pi=cherry-pick
343 alias.mt=mergetool
344 beta.noindent=sillyValue
345 nextsection.nonewline=wow2 for me
346 123456.a123=987
347 version.1.2.3eX.alpha=beta
348 EOF
349
350 test_expect_success 'working --list' '
351         git config --list > output &&
352         test_cmp expect output
353 '
354 cat > expect << EOF
355 alias.ci=commit
356 alias.co=checkout
357 alias.rb=rebase
358 alias.st=status
359 alias.br=branch
360 alias.pi=cherry-pick
361 alias.mt=mergetool
362 EOF
363
364 test_expect_success '--list without repo produces empty output' '
365         git --git-dir=nonexistent config --list >output &&
366         test_cmp expect output
367 '
368
369 cat > expect << EOF
370 alias.ci
371 alias.co
372 alias.rb
373 alias.st
374 alias.br
375 alias.pi
376 alias.mt
377 beta.noindent
378 nextsection.nonewline
379 123456.a123
380 version.1.2.3eX.alpha
381 EOF
382
383 test_expect_success '--name-only --list' '
384         git config --name-only --list >output &&
385         test_cmp expect output
386 '
387
388 cat > expect << EOF
389 beta.noindent sillyValue
390 nextsection.nonewline wow2 for me
391 EOF
392
393 test_expect_success '--get-regexp' '
394         git config --get-regexp in >output &&
395         test_cmp expect output
396 '
397
398 cat > expect << EOF
399 beta.noindent
400 nextsection.nonewline
401 EOF
402
403 test_expect_success '--name-only --get-regexp' '
404         git config --name-only --get-regexp in >output &&
405         test_cmp expect output
406 '
407
408 cat > expect << EOF
409 wow2 for me
410 wow4 for you
411 EOF
412
413 test_expect_success '--add' '
414         git config --add nextsection.nonewline "wow4 for you" &&
415         git config --get-all nextsection.nonewline > output &&
416         test_cmp expect output
417 '
418
419 cat > .git/config << EOF
420 [novalue]
421         variable
422 [emptyvalue]
423         variable =
424 EOF
425
426 test_expect_success 'get variable with no value' '
427         git config --get novalue.variable ^$
428 '
429
430 test_expect_success 'get variable with empty value' '
431         git config --get emptyvalue.variable ^$
432 '
433
434 echo novalue.variable > expect
435
436 test_expect_success 'get-regexp variable with no value' '
437         git config --get-regexp novalue > output &&
438         test_cmp expect output
439 '
440
441 echo 'novalue.variable true' > expect
442
443 test_expect_success 'get-regexp --bool variable with no value' '
444         git config --bool --get-regexp novalue > output &&
445         test_cmp expect output
446 '
447
448 echo 'emptyvalue.variable ' > expect
449
450 test_expect_success 'get-regexp variable with empty value' '
451         git config --get-regexp emptyvalue > output &&
452         test_cmp expect output
453 '
454
455 echo true > expect
456
457 test_expect_success 'get bool variable with no value' '
458         git config --bool novalue.variable > output &&
459         test_cmp expect output
460 '
461
462 echo false > expect
463
464 test_expect_success 'get bool variable with empty value' '
465         git config --bool emptyvalue.variable > output &&
466         test_cmp expect output
467 '
468
469 test_expect_success 'no arguments, but no crash' '
470         test_must_fail git config >output 2>&1 &&
471         test_i18ngrep usage output
472 '
473
474 cat > .git/config << EOF
475 [a.b]
476         c = d
477 EOF
478
479 cat > expect << EOF
480 [a.b]
481         c = d
482 [a]
483         x = y
484 EOF
485
486 test_expect_success 'new section is partial match of another' '
487         git config a.x y &&
488         test_cmp expect .git/config
489 '
490
491 cat > expect << EOF
492 [a.b]
493         c = d
494 [a]
495         x = y
496         b = c
497 [b]
498         x = y
499 EOF
500
501 test_expect_success 'new variable inserts into proper section' '
502         git config b.x y &&
503         git config a.b c &&
504         test_cmp expect .git/config
505 '
506
507 test_expect_success 'alternative --file (non-existing file should fail)' '
508         test_must_fail git config --file non-existing-config -l
509 '
510
511 cat > other-config << EOF
512 [ein]
513         bahn = strasse
514 EOF
515
516 cat > expect << EOF
517 ein.bahn=strasse
518 EOF
519
520 test_expect_success 'alternative GIT_CONFIG' '
521         GIT_CONFIG=other-config git config --list >output &&
522         test_cmp expect output
523 '
524
525 test_expect_success 'alternative GIT_CONFIG (--file)' '
526         git config --file other-config --list >output &&
527         test_cmp expect output
528 '
529
530 test_expect_success 'alternative GIT_CONFIG (--file=-)' '
531         git config --file - --list <other-config >output &&
532         test_cmp expect output
533 '
534
535 test_expect_success 'setting a value in stdin is an error' '
536         test_must_fail git config --file - some.value foo
537 '
538
539 test_expect_success 'editing stdin is an error' '
540         test_must_fail git config --file - --edit
541 '
542
543 test_expect_success 'refer config from subdirectory' '
544         mkdir x &&
545         (
546                 cd x &&
547                 echo strasse >expect &&
548                 git config --get --file ../other-config ein.bahn >actual &&
549                 test_cmp expect actual
550         )
551
552 '
553
554 test_expect_success 'refer config from subdirectory via --file' '
555         (
556                 cd x &&
557                 git config --file=../other-config --get ein.bahn >actual &&
558                 test_cmp expect actual
559         )
560 '
561
562 cat > expect << EOF
563 [ein]
564         bahn = strasse
565 [anwohner]
566         park = ausweis
567 EOF
568
569 test_expect_success '--set in alternative file' '
570         git config --file=other-config anwohner.park ausweis &&
571         test_cmp expect other-config
572 '
573
574 cat > .git/config << EOF
575 # Hallo
576         #Bello
577 [branch "eins"]
578         x = 1
579 [branch.eins]
580         y = 1
581         [branch "1 234 blabl/a"]
582 weird
583 EOF
584
585 test_expect_success 'rename section' '
586         git config --rename-section branch.eins branch.zwei
587 '
588
589 cat > expect << EOF
590 # Hallo
591         #Bello
592 [branch "zwei"]
593         x = 1
594 [branch "zwei"]
595         y = 1
596         [branch "1 234 blabl/a"]
597 weird
598 EOF
599
600 test_expect_success 'rename succeeded' '
601         test_cmp expect .git/config
602 '
603
604 test_expect_success 'rename non-existing section' '
605         test_must_fail git config --rename-section \
606                 branch."world domination" branch.drei
607 '
608
609 test_expect_success 'rename succeeded' '
610         test_cmp expect .git/config
611 '
612
613 test_expect_success 'rename another section' '
614         git config --rename-section branch."1 234 blabl/a" branch.drei
615 '
616
617 cat > expect << EOF
618 # Hallo
619         #Bello
620 [branch "zwei"]
621         x = 1
622 [branch "zwei"]
623         y = 1
624 [branch "drei"]
625 weird
626 EOF
627
628 test_expect_success 'rename succeeded' '
629         test_cmp expect .git/config
630 '
631
632 cat >> .git/config << EOF
633 [branch "vier"] z = 1
634 EOF
635
636 test_expect_success 'rename a section with a var on the same line' '
637         git config --rename-section branch.vier branch.zwei
638 '
639
640 cat > expect << EOF
641 # Hallo
642         #Bello
643 [branch "zwei"]
644         x = 1
645 [branch "zwei"]
646         y = 1
647 [branch "drei"]
648 weird
649 [branch "zwei"]
650         z = 1
651 EOF
652
653 test_expect_success 'rename succeeded' '
654         test_cmp expect .git/config
655 '
656
657 test_expect_success 'renaming empty section name is rejected' '
658         test_must_fail git config --rename-section branch.zwei ""
659 '
660
661 test_expect_success 'renaming to bogus section is rejected' '
662         test_must_fail git config --rename-section branch.zwei "bogus name"
663 '
664
665 cat >> .git/config << EOF
666   [branch "zwei"] a = 1 [branch "vier"]
667 EOF
668
669 test_expect_success 'remove section' '
670         git config --remove-section branch.zwei
671 '
672
673 cat > expect << EOF
674 # Hallo
675         #Bello
676 [branch "drei"]
677 weird
678 EOF
679
680 test_expect_success 'section was removed properly' '
681         test_cmp expect .git/config
682 '
683
684 cat > expect << EOF
685 [gitcvs]
686         enabled = true
687         dbname = %Ggitcvs2.%a.%m.sqlite
688 [gitcvs "ext"]
689         dbname = %Ggitcvs1.%a.%m.sqlite
690 EOF
691
692 test_expect_success 'section ending' '
693         rm -f .git/config &&
694         git config gitcvs.enabled true &&
695         git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
696         git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
697         test_cmp expect .git/config
698
699 '
700
701 test_expect_success numbers '
702         git config kilo.gram 1k &&
703         git config mega.ton 1m &&
704         echo 1024 >expect &&
705         echo 1048576 >>expect &&
706         git config --int --get kilo.gram >actual &&
707         git config --int --get mega.ton >>actual &&
708         test_cmp expect actual
709 '
710
711 test_expect_success '--int is at least 64 bits' '
712         git config giga.watts 121g &&
713         echo 129922760704 >expect &&
714         git config --int --get giga.watts >actual &&
715         test_cmp expect actual
716 '
717
718 test_expect_success 'invalid unit' '
719         git config aninvalid.unit "1auto" &&
720         echo 1auto >expect &&
721         git config aninvalid.unit >actual &&
722         test_cmp expect actual &&
723         test_must_fail git config --int --get aninvalid.unit 2>actual &&
724         test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
725 '
726
727 test_expect_success 'invalid stdin config' '
728         echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
729         test_i18ngrep "bad config line 1 in standard input" output
730 '
731
732 cat > expect << EOF
733 true
734 false
735 true
736 false
737 true
738 false
739 true
740 false
741 EOF
742
743 test_expect_success bool '
744
745         git config bool.true1 01 &&
746         git config bool.true2 -1 &&
747         git config bool.true3 YeS &&
748         git config bool.true4 true &&
749         git config bool.false1 000 &&
750         git config bool.false2 "" &&
751         git config bool.false3 nO &&
752         git config bool.false4 FALSE &&
753         rm -f result &&
754         for i in 1 2 3 4
755         do
756             git config --bool --get bool.true$i >>result
757             git config --bool --get bool.false$i >>result
758         done &&
759         test_cmp expect result'
760
761 test_expect_success 'invalid bool (--get)' '
762
763         git config bool.nobool foobar &&
764         test_must_fail git config --bool --get bool.nobool'
765
766 test_expect_success 'invalid bool (set)' '
767
768         test_must_fail git config --bool bool.nobool foobar'
769
770 cat > expect <<\EOF
771 [bool]
772         true1 = true
773         true2 = true
774         true3 = true
775         true4 = true
776         false1 = false
777         false2 = false
778         false3 = false
779         false4 = false
780 EOF
781
782 test_expect_success 'set --bool' '
783
784         rm -f .git/config &&
785         git config --bool bool.true1 01 &&
786         git config --bool bool.true2 -1 &&
787         git config --bool bool.true3 YeS &&
788         git config --bool bool.true4 true &&
789         git config --bool bool.false1 000 &&
790         git config --bool bool.false2 "" &&
791         git config --bool bool.false3 nO &&
792         git config --bool bool.false4 FALSE &&
793         test_cmp expect .git/config'
794
795 cat > expect <<\EOF
796 [int]
797         val1 = 1
798         val2 = -1
799         val3 = 5242880
800 EOF
801
802 test_expect_success 'set --int' '
803
804         rm -f .git/config &&
805         git config --int int.val1 01 &&
806         git config --int int.val2 -1 &&
807         git config --int int.val3 5m &&
808         test_cmp expect .git/config
809 '
810
811 test_expect_success 'get --bool-or-int' '
812         cat >.git/config <<-\EOF &&
813         [bool]
814         true1
815         true2 = true
816         false = false
817         [int]
818         int1 = 0
819         int2 = 1
820         int3 = -1
821         EOF
822         cat >expect <<-\EOF &&
823         true
824         true
825         false
826         0
827         1
828         -1
829         EOF
830         {
831                 git config --bool-or-int bool.true1 &&
832                 git config --bool-or-int bool.true2 &&
833                 git config --bool-or-int bool.false &&
834                 git config --bool-or-int int.int1 &&
835                 git config --bool-or-int int.int2 &&
836                 git config --bool-or-int int.int3
837         } >actual &&
838         test_cmp expect actual
839 '
840
841 cat >expect <<\EOF
842 [bool]
843         true1 = true
844         false1 = false
845         true2 = true
846         false2 = false
847 [int]
848         int1 = 0
849         int2 = 1
850         int3 = -1
851 EOF
852
853 test_expect_success 'set --bool-or-int' '
854         rm -f .git/config &&
855         git config --bool-or-int bool.true1 true &&
856         git config --bool-or-int bool.false1 false &&
857         git config --bool-or-int bool.true2 yes &&
858         git config --bool-or-int bool.false2 no &&
859         git config --bool-or-int int.int1 0 &&
860         git config --bool-or-int int.int2 1 &&
861         git config --bool-or-int int.int3 -1 &&
862         test_cmp expect .git/config
863 '
864
865 cat >expect <<\EOF
866 [path]
867         home = ~/
868         normal = /dev/null
869         trailingtilde = foo~
870 EOF
871
872 test_expect_success !MINGW 'set --path' '
873         rm -f .git/config &&
874         git config --path path.home "~/" &&
875         git config --path path.normal "/dev/null" &&
876         git config --path path.trailingtilde "foo~" &&
877         test_cmp expect .git/config'
878
879 if test_have_prereq !MINGW && test "${HOME+set}"
880 then
881         test_set_prereq HOMEVAR
882 fi
883
884 cat >expect <<EOF
885 $HOME/
886 /dev/null
887 foo~
888 EOF
889
890 test_expect_success HOMEVAR 'get --path' '
891         git config --get --path path.home > result &&
892         git config --get --path path.normal >> result &&
893         git config --get --path path.trailingtilde >> result &&
894         test_cmp expect result
895 '
896
897 cat >expect <<\EOF
898 /dev/null
899 foo~
900 EOF
901
902 test_expect_success !MINGW 'get --path copes with unset $HOME' '
903         (
904                 unset HOME;
905                 test_must_fail git config --get --path path.home \
906                         >result 2>msg &&
907                 git config --get --path path.normal >>result &&
908                 git config --get --path path.trailingtilde >>result
909         ) &&
910         grep "[Ff]ailed to expand.*~/" msg &&
911         test_cmp expect result
912 '
913
914 test_expect_success 'get --path barfs on boolean variable' '
915         echo "[path]bool" >.git/config &&
916         test_must_fail git config --get --path path.bool
917 '
918
919 cat > expect << EOF
920 [quote]
921         leading = " test"
922         ending = "test "
923         semicolon = "test;test"
924         hash = "test#test"
925 EOF
926 test_expect_success 'quoting' '
927         rm -f .git/config &&
928         git config quote.leading " test" &&
929         git config quote.ending "test " &&
930         git config quote.semicolon "test;test" &&
931         git config quote.hash "test#test" &&
932         test_cmp expect .git/config
933 '
934
935 test_expect_success 'key with newline' '
936         test_must_fail git config "key.with
937 newline" 123'
938
939 test_expect_success 'value with newline' 'git config key.sub value.with\\\
940 newline'
941
942 cat > .git/config <<\EOF
943 [section]
944         ; comment \
945         continued = cont\
946 inued
947         noncont   = not continued ; \
948         quotecont = "cont;\
949 inued"
950 EOF
951
952 cat > expect <<\EOF
953 alias.ci=commit
954 alias.co=checkout
955 alias.rb=rebase
956 alias.st=status
957 alias.br=branch
958 alias.pi=cherry-pick
959 alias.mt=mergetool
960 section.continued=continued
961 section.noncont=not continued
962 section.quotecont=cont;inued
963 EOF
964
965 test_expect_success 'value continued on next line' '
966         git config --list > result &&
967         test_cmp result expect
968 '
969
970 cat > .git/config <<\EOF
971 [section "sub=section"]
972         val1 = foo=bar
973         val2 = foo\nbar
974         val3 = \n\n
975         val4 =
976         val5
977 EOF
978
979 cat > expect <<\EOF
980 alias.ci
981 commitQalias.co
982 checkoutQalias.rb
983 rebaseQalias.st
984 statusQalias.br
985 branchQalias.pi
986 cherry-pickQalias.mt
987 mergetoolQsection.sub=section.val1
988 foo=barQsection.sub=section.val2
989 foo
990 barQsection.sub=section.val3
991
992
993 Qsection.sub=section.val4
994 Qsection.sub=section.val5Q
995 EOF
996 test_expect_success '--null --list' '
997         git config --null --list >result.raw &&
998         nul_to_q <result.raw >result &&
999         echo >>result &&
1000         test_cmp expect result
1001 '
1002
1003 cat > expect <<\EOF
1004 section.sub=section.val1
1005 foo=barQsection.sub=section.val2
1006 foo
1007 barQsection.sub=section.val3
1008
1009
1010 Qsection.sub=section.val4
1011 Qsection.sub=section.val5Q
1012 EOF
1013 test_expect_success '--null --get-regexp' '
1014         git config --null --get-regexp "val[0-9]" >result.raw &&
1015         nul_to_q <result.raw >result &&
1016         echo >>result &&
1017         test_cmp expect result
1018 '
1019
1020 test_expect_success 'inner whitespace kept verbatim' '
1021         git config section.val "foo       bar" &&
1022         echo "foo         bar" >expect &&
1023         git config section.val >actual &&
1024         test_cmp expect actual
1025 '
1026
1027 test_expect_success SYMLINKS 'symlinked configuration' '
1028         ln -s notyet myconfig &&
1029         git config --file=myconfig test.frotz nitfol &&
1030         test -h myconfig &&
1031         test -f notyet &&
1032         test "z$(git config --file=notyet test.frotz)" = znitfol &&
1033         git config --file=myconfig test.xyzzy rezrov &&
1034         test -h myconfig &&
1035         test -f notyet &&
1036         cat >expect <<-\EOF &&
1037         nitfol
1038         rezrov
1039         EOF
1040         {
1041                 git config --file=notyet test.frotz &&
1042                 git config --file=notyet test.xyzzy
1043         } >actual &&
1044         test_cmp expect actual
1045 '
1046
1047 test_expect_success 'nonexistent configuration' '
1048         test_must_fail git config --file=doesnotexist --list &&
1049         test_must_fail git config --file=doesnotexist test.xyzzy
1050 '
1051
1052 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1053         ln -s doesnotexist linktonada &&
1054         ln -s linktonada linktolinktonada &&
1055         test_must_fail git config --file=linktonada --list &&
1056         test_must_fail git config --file=linktolinktonada --list
1057 '
1058
1059 test_expect_success 'check split_cmdline return' "
1060         git config alias.split-cmdline-fix 'echo \"' &&
1061         test_must_fail git split-cmdline-fix &&
1062         echo foo > foo &&
1063         git add foo &&
1064         git commit -m 'initial commit' &&
1065         git config branch.master.mergeoptions 'echo \"' &&
1066         test_must_fail git merge master
1067 "
1068
1069 test_expect_success 'git -c "key=value" support' '
1070         cat >expect <<-\EOF &&
1071         value
1072         value
1073         true
1074         EOF
1075         {
1076                 git -c core.name=value config core.name &&
1077                 git -c foo.CamelCase=value config foo.camelcase &&
1078                 git -c foo.flag config --bool foo.flag
1079         } >actual &&
1080         test_cmp expect actual &&
1081         test_must_fail git -c name=value config core.name
1082 '
1083
1084 # We just need a type-specifier here that cares about the
1085 # distinction internally between a NULL boolean and a real
1086 # string (because most of git's internal parsers do care).
1087 # Using "--path" works, but we do not otherwise care about
1088 # its semantics.
1089 test_expect_success 'git -c can represent empty string' '
1090         echo >expect &&
1091         git -c foo.empty= config --path foo.empty >actual &&
1092         test_cmp expect actual
1093 '
1094
1095 test_expect_success 'key sanity-checking' '
1096         test_must_fail git config foo=bar &&
1097         test_must_fail git config foo=.bar &&
1098         test_must_fail git config foo.ba=r &&
1099         test_must_fail git config foo.1bar &&
1100         test_must_fail git config foo."ba
1101                                 z".bar &&
1102         test_must_fail git config . false &&
1103         test_must_fail git config .foo false &&
1104         test_must_fail git config foo. false &&
1105         test_must_fail git config .foo. false &&
1106         git config foo.bar true &&
1107         git config foo."ba =z".bar false
1108 '
1109
1110 test_expect_success 'git -c works with aliases of builtins' '
1111         git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1112         echo bar >expect &&
1113         git checkconfig >actual &&
1114         test_cmp expect actual
1115 '
1116
1117 test_expect_success 'git -c does not split values on equals' '
1118         echo "value with = in it" >expect &&
1119         git -c core.foo="value with = in it" config core.foo >actual &&
1120         test_cmp expect actual
1121 '
1122
1123 test_expect_success 'git -c dies on bogus config' '
1124         test_must_fail git -c core.bare=foo rev-parse
1125 '
1126
1127 test_expect_success 'git -c complains about empty key' '
1128         test_must_fail git -c "=foo" rev-parse
1129 '
1130
1131 test_expect_success 'git -c complains about empty key and value' '
1132         test_must_fail git -c "" rev-parse
1133 '
1134
1135 test_expect_success 'git config --edit works' '
1136         git config -f tmp test.value no &&
1137         echo test.value=yes >expect &&
1138         GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1139         git config -f tmp --list >actual &&
1140         test_cmp expect actual
1141 '
1142
1143 test_expect_success 'git config --edit respects core.editor' '
1144         git config -f tmp test.value no &&
1145         echo test.value=yes >expect &&
1146         test_config core.editor "echo [test]value=yes >" &&
1147         git config -f tmp --edit &&
1148         git config -f tmp --list >actual &&
1149         test_cmp expect actual
1150 '
1151
1152 # malformed configuration files
1153 test_expect_success 'barf on syntax error' '
1154         cat >.git/config <<-\EOF &&
1155         # broken section line
1156         [section]
1157         key garbage
1158         EOF
1159         test_must_fail git config --get section.key >actual 2>error &&
1160         grep " line 3 " error
1161 '
1162
1163 test_expect_success 'barf on incomplete section header' '
1164         cat >.git/config <<-\EOF &&
1165         # broken section line
1166         [section
1167         key = value
1168         EOF
1169         test_must_fail git config --get section.key >actual 2>error &&
1170         grep " line 2 " error
1171 '
1172
1173 test_expect_success 'barf on incomplete string' '
1174         cat >.git/config <<-\EOF &&
1175         # broken section line
1176         [section]
1177         key = "value string
1178         EOF
1179         test_must_fail git config --get section.key >actual 2>error &&
1180         grep " line 3 " error
1181 '
1182
1183 test_expect_success 'urlmatch' '
1184         cat >.git/config <<-\EOF &&
1185         [http]
1186                 sslVerify
1187         [http "https://weak.example.com"]
1188                 sslVerify = false
1189                 cookieFile = /tmp/cookie.txt
1190         EOF
1191
1192         echo true >expect &&
1193         git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1194         test_cmp expect actual &&
1195
1196         echo false >expect &&
1197         git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1198         test_cmp expect actual &&
1199
1200         {
1201                 echo http.cookiefile /tmp/cookie.txt &&
1202                 echo http.sslverify false
1203         } >expect &&
1204         git config --get-urlmatch HTTP https://weak.example.com >actual &&
1205         test_cmp expect actual
1206 '
1207
1208 # good section hygiene
1209 test_expect_failure 'unsetting the last key in a section removes header' '
1210         cat >.git/config <<-\EOF &&
1211         # some generic comment on the configuration file itself
1212         # a comment specific to this "section" section.
1213         [section]
1214         # some intervening lines
1215         # that should also be dropped
1216
1217         key = value
1218         # please be careful when you update the above variable
1219         EOF
1220
1221         cat >expect <<-\EOF &&
1222         # some generic comment on the configuration file itself
1223         EOF
1224
1225         git config --unset section.key &&
1226         test_cmp expect .git/config
1227 '
1228
1229 test_expect_failure 'adding a key into an empty section reuses header' '
1230         cat >.git/config <<-\EOF &&
1231         [section]
1232         EOF
1233
1234         q_to_tab >expect <<-\EOF &&
1235         [section]
1236         Qkey = value
1237         EOF
1238
1239         git config section.key value &&
1240         test_cmp expect .git/config
1241 '
1242
1243 test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1244         chmod 0600 .git/config &&
1245         git config imap.pass Hunter2 &&
1246         perl -e \
1247           "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1248         git config --rename-section imap pop &&
1249         perl -e \
1250           "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1251 '
1252
1253 ! test_have_prereq MINGW ||
1254 HOME="$(pwd)" # convert to Windows path
1255
1256 test_expect_success 'set up --show-origin tests' '
1257         INCLUDE_DIR="$HOME/include" &&
1258         mkdir -p "$INCLUDE_DIR" &&
1259         cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1260                 [user]
1261                         absolute = include
1262         EOF
1263         cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1264                 [user]
1265                         relative = include
1266         EOF
1267         cat >"$HOME"/.gitconfig <<-EOF &&
1268                 [user]
1269                         global = true
1270                         override = global
1271                 [include]
1272                         path = "$INCLUDE_DIR/absolute.include"
1273         EOF
1274         cat >.git/config <<-\EOF
1275                 [user]
1276                         local = true
1277                         override = local
1278                 [include]
1279                         path = ../include/relative.include
1280         EOF
1281 '
1282
1283 test_expect_success '--show-origin with --list' '
1284         cat >expect <<-EOF &&
1285                 command line:   alias.ci=commit
1286                 command line:   alias.co=checkout
1287                 command line:   alias.rb=rebase
1288                 command line:   alias.st=status
1289                 command line:   alias.br=branch
1290                 command line:   alias.pi=cherry-pick
1291                 command line:   alias.mt=mergetool
1292                 file:$HOME/.gitconfig   user.global=true
1293                 file:$HOME/.gitconfig   user.override=global
1294                 file:$HOME/.gitconfig   include.path=$INCLUDE_DIR/absolute.include
1295                 file:$INCLUDE_DIR/absolute.include      user.absolute=include
1296                 file:.git/config        user.local=true
1297                 file:.git/config        user.override=local
1298                 file:.git/config        include.path=../include/relative.include
1299                 file:.git/../include/relative.include   user.relative=include
1300                 command line:   user.cmdline=true
1301         EOF
1302         git -c user.cmdline=true config --list --show-origin >output &&
1303         test_cmp expect output
1304 '
1305
1306 test_expect_success '--show-origin with --list --null' '
1307         cat >expect <<-EOF &&
1308                 command line:Qalias.ci
1309                 commitQcommand line:Qalias.co
1310                 checkoutQcommand line:Qalias.rb
1311                 rebaseQcommand line:Qalias.st
1312                 statusQcommand line:Qalias.br
1313                 branchQcommand line:Qalias.pi
1314                 cherry-pickQcommand line:Qalias.mt
1315                 mergetoolQfile:$HOME/.gitconfigQuser.global
1316                 trueQfile:$HOME/.gitconfigQuser.override
1317                 globalQfile:$HOME/.gitconfigQinclude.path
1318                 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1319                 includeQfile:.git/configQuser.local
1320                 trueQfile:.git/configQuser.override
1321                 localQfile:.git/configQinclude.path
1322                 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1323                 includeQcommand line:Quser.cmdline
1324                 trueQ
1325         EOF
1326         git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1327         nul_to_q <output.raw >output &&
1328         # The here-doc above adds a newline that the --null output would not
1329         # include. Add it here to make the two comparable.
1330         echo >>output &&
1331         test_cmp expect output
1332 '
1333
1334 test_expect_success '--show-origin with single file' '
1335         cat >expect <<-\EOF &&
1336                 file:.git/config        user.local=true
1337                 file:.git/config        user.override=local
1338                 file:.git/config        include.path=../include/relative.include
1339         EOF
1340         git config --local --list --show-origin >output &&
1341         test_cmp expect output
1342 '
1343
1344 test_expect_success '--show-origin with --get-regexp' '
1345         cat >expect <<-EOF &&
1346                 file:$HOME/.gitconfig   user.global true
1347                 file:.git/config        user.local true
1348         EOF
1349         git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1350         test_cmp expect output
1351 '
1352
1353 test_expect_success '--show-origin getting a single key' '
1354         cat >expect <<-\EOF &&
1355                 file:.git/config        local
1356         EOF
1357         git config --show-origin user.override >output &&
1358         test_cmp expect output
1359 '
1360
1361 test_expect_success 'set up custom config file' '
1362         CUSTOM_CONFIG_FILE="file\" (dq) and spaces.conf" &&
1363         cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1364                 [user]
1365                         custom = true
1366         EOF
1367 '
1368
1369 test_expect_success !MINGW '--show-origin escape special file name characters' '
1370         cat >expect <<-\EOF &&
1371                 file:"file\" (dq) and spaces.conf"      user.custom=true
1372         EOF
1373         git config --file "$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1374         test_cmp expect output
1375 '
1376
1377 test_expect_success '--show-origin stdin' '
1378         cat >expect <<-\EOF &&
1379                 standard input: user.custom=true
1380         EOF
1381         git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1382         test_cmp expect output
1383 '
1384
1385 test_expect_success '--show-origin stdin with file include' '
1386         cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1387                 [user]
1388                         stdin = include
1389         EOF
1390         cat >expect <<-EOF &&
1391                 file:$INCLUDE_DIR/stdin.include include
1392         EOF
1393         echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" \
1394                 | git config --show-origin --includes --file - user.stdin >output &&
1395         test_cmp expect output
1396 '
1397
1398 test_expect_success !MINGW '--show-origin blob' '
1399         cat >expect <<-\EOF &&
1400                 blob:a9d9f9e555b5c6f07cbe09d3f06fe3df11e09c08   user.custom=true
1401         EOF
1402         blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1403         git config --blob=$blob --show-origin --list >output &&
1404         test_cmp expect output
1405 '
1406
1407 test_expect_success !MINGW '--show-origin blob ref' '
1408         cat >expect <<-\EOF &&
1409                 blob:"master:file\" (dq) and spaces.conf"       user.custom=true
1410         EOF
1411         git add "$CUSTOM_CONFIG_FILE" &&
1412         git commit -m "new config file" &&
1413         git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1414         test_cmp expect output
1415 '
1416
1417 test_done