Merge branch 'maint'
[git.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 test_expect_success 'replace with non-match (actually matching)' \
62         'git config core.penguin "very blue" !kingpin'
63
64 cat > expect << EOF
65 [core]
66         penguin = very blue
67         Movie = BadPhysics
68         UPPERCASE = true
69         penguin = kingpin
70 [Cores]
71         WhatEver = Second
72 EOF
73
74 test_expect_success 'non-match result' 'test_cmp expect .git/config'
75
76 test_expect_success 'find mixed-case key by canonical name' '
77         echo Second >expect &&
78         git config cores.whatever >actual &&
79         test_cmp expect actual
80 '
81
82 test_expect_success 'find mixed-case key by non-canonical name' '
83         echo Second >expect &&
84         git config CoReS.WhAtEvEr >actual &&
85         test_cmp expect actual
86 '
87
88 test_expect_success 'subsections are not canonicalized by git-config' '
89         cat >>.git/config <<-\EOF &&
90         [section.SubSection]
91         key = one
92         [section "SubSection"]
93         key = two
94         EOF
95         echo one >expect &&
96         git config section.subsection.key >actual &&
97         test_cmp expect actual &&
98         echo two >expect &&
99         git config section.SubSection.key >actual &&
100         test_cmp expect actual
101 '
102
103 cat > .git/config <<\EOF
104 [alpha]
105 bar = foo
106 [beta]
107 baz = multiple \
108 lines
109 EOF
110
111 test_expect_success 'unset with cont. lines' \
112         'git config --unset beta.baz'
113
114 cat > expect <<\EOF
115 [alpha]
116 bar = foo
117 [beta]
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 cat > expect << EOF
140 [beta] ; silly comment # another comment
141 noIndent= sillyValue ; 'nother silly comment
142
143 # empty line
144                 ; comment
145 [nextSection] noNewline = ouch
146 EOF
147
148 test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config'
149
150 cp .git/config2 .git/config
151
152 test_expect_success '--replace-all missing value' '
153         test_must_fail git config --replace-all beta.haha &&
154         test_cmp .git/config2 .git/config
155 '
156
157 rm .git/config2
158
159 test_expect_success '--replace-all' \
160         'git config --replace-all beta.haha gamma'
161
162 cat > expect << EOF
163 [beta] ; silly comment # another comment
164 noIndent= sillyValue ; 'nother silly comment
165
166 # empty line
167                 ; comment
168         haha = gamma
169 [nextSection] noNewline = ouch
170 EOF
171
172 test_expect_success 'all replaced' 'test_cmp expect .git/config'
173
174 cat > expect << EOF
175 [beta] ; silly comment # another comment
176 noIndent= sillyValue ; 'nother silly comment
177
178 # empty line
179                 ; comment
180         haha = alpha
181 [nextSection] noNewline = ouch
182 EOF
183 test_expect_success 'really mean test' '
184         git config beta.haha alpha &&
185         test_cmp expect .git/config
186 '
187
188 cat > expect << EOF
189 [beta] ; silly comment # another comment
190 noIndent= sillyValue ; 'nother silly comment
191
192 # empty line
193                 ; comment
194         haha = alpha
195 [nextSection]
196         nonewline = wow
197 EOF
198 test_expect_success 'really really mean test' '
199         git config nextsection.nonewline wow &&
200         test_cmp expect .git/config
201 '
202
203 test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
204
205 cat > expect << EOF
206 [beta] ; silly comment # another comment
207 noIndent= sillyValue ; 'nother silly comment
208
209 # empty line
210                 ; comment
211 [nextSection]
212         nonewline = wow
213 EOF
214 test_expect_success 'unset' '
215         git config --unset beta.haha &&
216         test_cmp expect .git/config
217 '
218
219 cat > expect << EOF
220 [beta] ; silly comment # another comment
221 noIndent= sillyValue ; 'nother silly comment
222
223 # empty line
224                 ; comment
225 [nextSection]
226         nonewline = wow
227         NoNewLine = wow2 for me
228 EOF
229 test_expect_success 'multivar' '
230         git config nextsection.NoNewLine "wow2 for me" "for me$" &&
231         test_cmp expect .git/config
232 '
233
234 test_expect_success 'non-match' \
235         'git config --get nextsection.nonewline !for'
236
237 test_expect_success 'non-match value' \
238         'test wow = $(git config --get nextsection.nonewline !for)'
239
240 test_expect_success 'ambiguous get' '
241         test_must_fail git config --get nextsection.nonewline
242 '
243
244 test_expect_success 'get multivar' \
245         'git config --get-all nextsection.nonewline'
246
247 cat > expect << EOF
248 [beta] ; silly comment # another comment
249 noIndent= sillyValue ; 'nother silly comment
250
251 # empty line
252                 ; comment
253 [nextSection]
254         nonewline = wow3
255         NoNewLine = wow2 for me
256 EOF
257 test_expect_success 'multivar replace' '
258         git config nextsection.nonewline "wow3" "wow$" &&
259         test_cmp expect .git/config
260 '
261
262 test_expect_success 'ambiguous value' '
263         test_must_fail git config nextsection.nonewline
264 '
265
266 test_expect_success 'ambiguous unset' '
267         test_must_fail git config --unset nextsection.nonewline
268 '
269
270 test_expect_success 'invalid unset' '
271         test_must_fail git config --unset somesection.nonewline
272 '
273
274 cat > expect << EOF
275 [beta] ; silly comment # another comment
276 noIndent= sillyValue ; 'nother silly comment
277
278 # empty line
279                 ; comment
280 [nextSection]
281         NoNewLine = wow2 for me
282 EOF
283
284 test_expect_success 'multivar unset' '
285         git config --unset nextsection.nonewline "wow3$" &&
286         test_cmp expect .git/config
287 '
288
289 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
290
291 test_expect_success 'correct key' 'git config 123456.a123 987'
292
293 test_expect_success 'hierarchical section' \
294         'git config Version.1.2.3eX.Alpha beta'
295
296 cat > expect << EOF
297 [beta] ; silly comment # another comment
298 noIndent= sillyValue ; 'nother silly comment
299
300 # empty line
301                 ; comment
302 [nextSection]
303         NoNewLine = wow2 for me
304 [123456]
305         a123 = 987
306 [Version "1.2.3eX"]
307         Alpha = beta
308 EOF
309
310 test_expect_success 'hierarchical section value' 'test_cmp expect .git/config'
311
312 cat > expect << EOF
313 beta.noindent=sillyValue
314 nextsection.nonewline=wow2 for me
315 123456.a123=987
316 version.1.2.3eX.alpha=beta
317 EOF
318
319 test_expect_success 'working --list' \
320         'git config --list > output && cmp output expect'
321
322 cat > expect << EOF
323 EOF
324
325 test_expect_success '--list without repo produces empty output' '
326         git --git-dir=nonexistent config --list >output &&
327         test_cmp expect output
328 '
329
330 cat > expect << EOF
331 beta.noindent sillyValue
332 nextsection.nonewline wow2 for me
333 EOF
334
335 test_expect_success '--get-regexp' \
336         'git config --get-regexp in > output && cmp output expect'
337
338 cat > expect << EOF
339 wow2 for me
340 wow4 for you
341 EOF
342
343 test_expect_success '--add' '
344         git config --add nextsection.nonewline "wow4 for you" &&
345         git config --get-all nextsection.nonewline > output &&
346         test_cmp expect output
347 '
348
349 cat > .git/config << EOF
350 [novalue]
351         variable
352 [emptyvalue]
353         variable =
354 EOF
355
356 test_expect_success 'get variable with no value' \
357         'git config --get novalue.variable ^$'
358
359 test_expect_success 'get variable with empty value' \
360         'git config --get emptyvalue.variable ^$'
361
362 echo novalue.variable > expect
363
364 test_expect_success 'get-regexp variable with no value' \
365         'git config --get-regexp novalue > output &&
366          cmp output expect'
367
368 echo 'novalue.variable true' > expect
369
370 test_expect_success 'get-regexp --bool variable with no value' \
371         'git config --bool --get-regexp novalue > output &&
372          cmp output expect'
373
374 echo 'emptyvalue.variable ' > expect
375
376 test_expect_success 'get-regexp variable with empty value' \
377         'git config --get-regexp emptyvalue > output &&
378          cmp output expect'
379
380 echo true > expect
381
382 test_expect_success 'get bool variable with no value' \
383         'git config --bool novalue.variable > output &&
384          cmp output expect'
385
386 echo false > expect
387
388 test_expect_success 'get bool variable with empty value' \
389         'git config --bool emptyvalue.variable > output &&
390          cmp output expect'
391
392 test_expect_success 'no arguments, but no crash' '
393         test_must_fail git config >output 2>&1 &&
394         test_i18ngrep usage output
395 '
396
397 cat > .git/config << EOF
398 [a.b]
399         c = d
400 EOF
401
402 cat > expect << EOF
403 [a.b]
404         c = d
405 [a]
406         x = y
407 EOF
408
409 test_expect_success 'new section is partial match of another' '
410         git config a.x y &&
411         test_cmp expect .git/config
412 '
413
414 cat > expect << EOF
415 [a.b]
416         c = d
417 [a]
418         x = y
419         b = c
420 [b]
421         x = y
422 EOF
423
424 test_expect_success 'new variable inserts into proper section' '
425         git config b.x y &&
426         git config a.b c &&
427         test_cmp expect .git/config
428 '
429
430 test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
431         'test_must_fail git config --file non-existing-config -l'
432
433 cat > other-config << EOF
434 [ein]
435         bahn = strasse
436 EOF
437
438 cat > expect << EOF
439 ein.bahn=strasse
440 EOF
441
442 test_expect_success 'alternative GIT_CONFIG' '
443         GIT_CONFIG=other-config git config -l >output &&
444         test_cmp expect output
445 '
446
447 test_expect_success 'alternative GIT_CONFIG (--file)' \
448         'git config --file other-config -l > output && cmp output expect'
449
450 test_expect_success 'refer config from subdirectory' '
451         mkdir x &&
452         (
453                 cd x &&
454                 echo strasse >expect &&
455                 git config --get --file ../other-config ein.bahn >actual &&
456                 test_cmp expect actual
457         )
458
459 '
460
461 test_expect_success 'refer config from subdirectory via GIT_CONFIG' '
462         (
463                 cd x &&
464                 GIT_CONFIG=../other-config git config --get ein.bahn >actual &&
465                 test_cmp expect actual
466         )
467 '
468
469 cat > expect << EOF
470 [ein]
471         bahn = strasse
472 [anwohner]
473         park = ausweis
474 EOF
475
476 test_expect_success '--set in alternative GIT_CONFIG' '
477         GIT_CONFIG=other-config git config anwohner.park ausweis &&
478         test_cmp expect other-config
479 '
480
481 cat > .git/config << EOF
482 # Hallo
483         #Bello
484 [branch "eins"]
485         x = 1
486 [branch.eins]
487         y = 1
488         [branch "1 234 blabl/a"]
489 weird
490 EOF
491
492 test_expect_success "rename section" \
493         "git config --rename-section branch.eins branch.zwei"
494
495 cat > expect << EOF
496 # Hallo
497         #Bello
498 [branch "zwei"]
499         x = 1
500 [branch "zwei"]
501         y = 1
502         [branch "1 234 blabl/a"]
503 weird
504 EOF
505
506 test_expect_success "rename succeeded" "test_cmp expect .git/config"
507
508 test_expect_success "rename non-existing section" '
509         test_must_fail git config --rename-section \
510                 branch."world domination" branch.drei
511 '
512
513 test_expect_success "rename succeeded" "test_cmp expect .git/config"
514
515 test_expect_success "rename another section" \
516         'git config --rename-section branch."1 234 blabl/a" branch.drei'
517
518 cat > expect << EOF
519 # Hallo
520         #Bello
521 [branch "zwei"]
522         x = 1
523 [branch "zwei"]
524         y = 1
525 [branch "drei"]
526 weird
527 EOF
528
529 test_expect_success "rename succeeded" "test_cmp expect .git/config"
530
531 cat >> .git/config << EOF
532 [branch "vier"] z = 1
533 EOF
534
535 test_expect_success "rename a section with a var on the same line" \
536         'git config --rename-section branch.vier branch.zwei'
537
538 cat > expect << EOF
539 # Hallo
540         #Bello
541 [branch "zwei"]
542         x = 1
543 [branch "zwei"]
544         y = 1
545 [branch "drei"]
546 weird
547 [branch "zwei"]
548         z = 1
549 EOF
550
551 test_expect_success "rename succeeded" "test_cmp expect .git/config"
552
553 test_expect_success 'renaming empty section name is rejected' '
554         test_must_fail git config --rename-section branch.zwei ""
555 '
556
557 test_expect_success 'renaming to bogus section is rejected' '
558         test_must_fail git config --rename-section branch.zwei "bogus name"
559 '
560
561 cat >> .git/config << EOF
562   [branch "zwei"] a = 1 [branch "vier"]
563 EOF
564
565 test_expect_success "remove section" "git config --remove-section branch.zwei"
566
567 cat > expect << EOF
568 # Hallo
569         #Bello
570 [branch "drei"]
571 weird
572 EOF
573
574 test_expect_success "section was removed properly" \
575         "test_cmp expect .git/config"
576
577 cat > expect << EOF
578 [gitcvs]
579         enabled = true
580         dbname = %Ggitcvs2.%a.%m.sqlite
581 [gitcvs "ext"]
582         dbname = %Ggitcvs1.%a.%m.sqlite
583 EOF
584
585 test_expect_success 'section ending' '
586
587         rm -f .git/config &&
588         git config gitcvs.enabled true &&
589         git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
590         git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
591         test_cmp expect .git/config
592
593 '
594
595 test_expect_success numbers '
596
597         git config kilo.gram 1k &&
598         git config mega.ton 1m &&
599         k=$(git config --int --get kilo.gram) &&
600         test z1024 = "z$k" &&
601         m=$(git config --int --get mega.ton) &&
602         test z1048576 = "z$m"
603 '
604
605 cat > expect <<EOF
606 fatal: bad config value for 'aninvalid.unit' in .git/config
607 EOF
608
609 test_expect_success 'invalid unit' '
610
611         git config aninvalid.unit "1auto" &&
612         s=$(git config aninvalid.unit) &&
613         test "z1auto" = "z$s" &&
614         if git config --int --get aninvalid.unit 2>actual
615         then
616                 echo config should have failed
617                 false
618         fi &&
619         cmp actual expect
620 '
621
622 cat > expect << EOF
623 true
624 false
625 true
626 false
627 true
628 false
629 true
630 false
631 EOF
632
633 test_expect_success bool '
634
635         git config bool.true1 01 &&
636         git config bool.true2 -1 &&
637         git config bool.true3 YeS &&
638         git config bool.true4 true &&
639         git config bool.false1 000 &&
640         git config bool.false2 "" &&
641         git config bool.false3 nO &&
642         git config bool.false4 FALSE &&
643         rm -f result &&
644         for i in 1 2 3 4
645         do
646             git config --bool --get bool.true$i >>result
647             git config --bool --get bool.false$i >>result
648         done &&
649         cmp expect result'
650
651 test_expect_success 'invalid bool (--get)' '
652
653         git config bool.nobool foobar &&
654         test_must_fail git config --bool --get bool.nobool'
655
656 test_expect_success 'invalid bool (set)' '
657
658         test_must_fail git config --bool bool.nobool foobar'
659
660 cat > expect <<\EOF
661 [bool]
662         true1 = true
663         true2 = true
664         true3 = true
665         true4 = true
666         false1 = false
667         false2 = false
668         false3 = false
669         false4 = false
670 EOF
671
672 test_expect_success 'set --bool' '
673
674         rm -f .git/config &&
675         git config --bool bool.true1 01 &&
676         git config --bool bool.true2 -1 &&
677         git config --bool bool.true3 YeS &&
678         git config --bool bool.true4 true &&
679         git config --bool bool.false1 000 &&
680         git config --bool bool.false2 "" &&
681         git config --bool bool.false3 nO &&
682         git config --bool bool.false4 FALSE &&
683         cmp expect .git/config'
684
685 cat > expect <<\EOF
686 [int]
687         val1 = 1
688         val2 = -1
689         val3 = 5242880
690 EOF
691
692 test_expect_success 'set --int' '
693
694         rm -f .git/config &&
695         git config --int int.val1 01 &&
696         git config --int int.val2 -1 &&
697         git config --int int.val3 5m &&
698         cmp expect .git/config'
699
700 cat >expect <<\EOF
701 [bool]
702         true1 = true
703         true2 = true
704         false1 = false
705         false2 = false
706 [int]
707         int1 = 0
708         int2 = 1
709         int3 = -1
710 EOF
711
712 test_expect_success 'get --bool-or-int' '
713         rm -f .git/config &&
714         (
715                 echo "[bool]"
716                 echo true1
717                 echo true2 = true
718                 echo false = false
719                 echo "[int]"
720                 echo int1 = 0
721                 echo int2 = 1
722                 echo int3 = -1
723         ) >>.git/config &&
724         test $(git config --bool-or-int bool.true1) = true &&
725         test $(git config --bool-or-int bool.true2) = true &&
726         test $(git config --bool-or-int bool.false) = false &&
727         test $(git config --bool-or-int int.int1) = 0 &&
728         test $(git config --bool-or-int int.int2) = 1 &&
729         test $(git config --bool-or-int int.int3) = -1
730
731 '
732
733 cat >expect <<\EOF
734 [bool]
735         true1 = true
736         false1 = false
737         true2 = true
738         false2 = false
739 [int]
740         int1 = 0
741         int2 = 1
742         int3 = -1
743 EOF
744
745 test_expect_success 'set --bool-or-int' '
746         rm -f .git/config &&
747         git config --bool-or-int bool.true1 true &&
748         git config --bool-or-int bool.false1 false &&
749         git config --bool-or-int bool.true2 yes &&
750         git config --bool-or-int bool.false2 no &&
751         git config --bool-or-int int.int1 0 &&
752         git config --bool-or-int int.int2 1 &&
753         git config --bool-or-int int.int3 -1 &&
754         test_cmp expect .git/config
755 '
756
757 cat >expect <<\EOF
758 [path]
759         home = ~/
760         normal = /dev/null
761         trailingtilde = foo~
762 EOF
763
764 test_expect_success NOT_MINGW 'set --path' '
765         rm -f .git/config &&
766         git config --path path.home "~/" &&
767         git config --path path.normal "/dev/null" &&
768         git config --path path.trailingtilde "foo~" &&
769         test_cmp expect .git/config'
770
771 if test_have_prereq NOT_MINGW && test "${HOME+set}"
772 then
773         test_set_prereq HOMEVAR
774 fi
775
776 cat >expect <<EOF
777 $HOME/
778 /dev/null
779 foo~
780 EOF
781
782 test_expect_success HOMEVAR 'get --path' '
783         git config --get --path path.home > result &&
784         git config --get --path path.normal >> result &&
785         git config --get --path path.trailingtilde >> result &&
786         test_cmp expect result
787 '
788
789 cat >expect <<\EOF
790 /dev/null
791 foo~
792 EOF
793
794 test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
795         (
796                 unset HOME;
797                 test_must_fail git config --get --path path.home \
798                         >result 2>msg &&
799                 git config --get --path path.normal >>result &&
800                 git config --get --path path.trailingtilde >>result
801         ) &&
802         grep "[Ff]ailed to expand.*~/" msg &&
803         test_cmp expect result
804 '
805
806 cat > expect << EOF
807 [quote]
808         leading = " test"
809         ending = "test "
810         semicolon = "test;test"
811         hash = "test#test"
812 EOF
813 test_expect_success 'quoting' '
814         rm -f .git/config &&
815         git config quote.leading " test" &&
816         git config quote.ending "test " &&
817         git config quote.semicolon "test;test" &&
818         git config quote.hash "test#test" &&
819         test_cmp expect .git/config
820 '
821
822 test_expect_success 'key with newline' '
823         test_must_fail git config "key.with
824 newline" 123'
825
826 test_expect_success 'value with newline' 'git config key.sub value.with\\\
827 newline'
828
829 cat > .git/config <<\EOF
830 [section]
831         ; comment \
832         continued = cont\
833 inued
834         noncont   = not continued ; \
835         quotecont = "cont;\
836 inued"
837 EOF
838
839 cat > expect <<\EOF
840 section.continued=continued
841 section.noncont=not continued
842 section.quotecont=cont;inued
843 EOF
844
845 test_expect_success 'value continued on next line' '
846         git config --list > result &&
847         cmp result expect
848 '
849
850 cat > .git/config <<\EOF
851 [section "sub=section"]
852         val1 = foo=bar
853         val2 = foo\nbar
854         val3 = \n\n
855         val4 =
856         val5
857 EOF
858
859 cat > expect <<\EOF
860 section.sub=section.val1
861 foo=barQsection.sub=section.val2
862 foo
863 barQsection.sub=section.val3
864
865
866 Qsection.sub=section.val4
867 Qsection.sub=section.val5Q
868 EOF
869 test_expect_success '--null --list' '
870         git config --null --list | nul_to_q >result &&
871         echo >>result &&
872         test_cmp expect result
873 '
874
875 test_expect_success '--null --get-regexp' '
876         git config --null --get-regexp "val[0-9]" | nul_to_q >result &&
877         echo >>result &&
878         test_cmp expect result
879 '
880
881 test_expect_success 'inner whitespace kept verbatim' '
882         git config section.val "foo       bar" &&
883         test "z$(git config section.val)" = "zfoo         bar"
884 '
885
886 test_expect_success SYMLINKS 'symlinked configuration' '
887
888         ln -s notyet myconfig &&
889         GIT_CONFIG=myconfig git config test.frotz nitfol &&
890         test -h myconfig &&
891         test -f notyet &&
892         test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
893         GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
894         test -h myconfig &&
895         test -f notyet &&
896         test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
897         test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
898
899 '
900
901 test_expect_success 'nonexistent configuration' '
902         (
903                 GIT_CONFIG=doesnotexist &&
904                 export GIT_CONFIG &&
905                 test_must_fail git config --list &&
906                 test_must_fail git config test.xyzzy
907         )
908 '
909
910 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
911         ln -s doesnotexist linktonada &&
912         ln -s linktonada linktolinktonada &&
913         (
914                 GIT_CONFIG=linktonada &&
915                 export GIT_CONFIG &&
916                 test_must_fail git config --list &&
917                 GIT_CONFIG=linktolinktonada &&
918                 test_must_fail git config --list
919         )
920 '
921
922 test_expect_success 'check split_cmdline return' "
923         git config alias.split-cmdline-fix 'echo \"' &&
924         test_must_fail git split-cmdline-fix &&
925         echo foo > foo &&
926         git add foo &&
927         git commit -m 'initial commit' &&
928         git config branch.master.mergeoptions 'echo \"' &&
929         test_must_fail git merge master
930         "
931
932 test_expect_success 'git -c "key=value" support' '
933         test "z$(git -c core.name=value config core.name)" = zvalue &&
934         test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue &&
935         test "z$(git -c foo.flag config --bool foo.flag)" = ztrue &&
936         test_must_fail git -c name=value config core.name
937 '
938
939 test_expect_success 'key sanity-checking' '
940         test_must_fail git config foo=bar &&
941         test_must_fail git config foo=.bar &&
942         test_must_fail git config foo.ba=r &&
943         test_must_fail git config foo.1bar &&
944         test_must_fail git config foo."ba
945                                 z".bar &&
946         test_must_fail git config . false &&
947         test_must_fail git config .foo false &&
948         test_must_fail git config foo. false &&
949         test_must_fail git config .foo. false &&
950         git config foo.bar true &&
951         git config foo."ba =z".bar false
952 '
953
954 test_expect_success 'git -c works with aliases of builtins' '
955         git config alias.checkconfig "-c foo.check=bar config foo.check" &&
956         echo bar >expect &&
957         git checkconfig >actual &&
958         test_cmp expect actual
959 '
960
961 test_expect_success 'git -c does not split values on equals' '
962         echo "value with = in it" >expect &&
963         git -c core.foo="value with = in it" config core.foo >actual &&
964         test_cmp expect actual
965 '
966
967 test_expect_success 'git -c dies on bogus config' '
968         test_must_fail git -c core.bare=foo rev-parse
969 '
970
971 test_expect_success 'git -c complains about empty key' '
972         test_must_fail git -c "=foo" rev-parse
973 '
974
975 test_expect_success 'git -c complains about empty key and value' '
976         test_must_fail git -c "" rev-parse
977 '
978
979 test_expect_success 'git config --edit works' '
980         git config -f tmp test.value no &&
981         echo test.value=yes >expect &&
982         GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
983         git config -f tmp --list >actual &&
984         test_cmp expect actual
985 '
986
987 test_expect_success 'git config --edit respects core.editor' '
988         git config -f tmp test.value no &&
989         echo test.value=yes >expect &&
990         test_config core.editor "echo [test]value=yes >" &&
991         git config -f tmp --edit &&
992         git config -f tmp --list >actual &&
993         test_cmp expect actual
994 '
995
996 # malformed configuration files
997 test_expect_success 'barf on syntax error' '
998         cat >.git/config <<-\EOF &&
999         # broken section line
1000         [section]
1001         key garbage
1002         EOF
1003         test_must_fail git config --get section.key >actual 2>error &&
1004         grep " line 3 " error
1005 '
1006
1007 test_expect_success 'barf on incomplete section header' '
1008         cat >.git/config <<-\EOF &&
1009         # broken section line
1010         [section
1011         key = value
1012         EOF
1013         test_must_fail git config --get section.key >actual 2>error &&
1014         grep " line 2 " error
1015 '
1016
1017 test_expect_success 'barf on incomplete string' '
1018         cat >.git/config <<-\EOF &&
1019         # broken section line
1020         [section]
1021         key = "value string
1022         EOF
1023         test_must_fail git config --get section.key >actual 2>error &&
1024         grep " line 3 " error
1025 '
1026
1027 test_done