Merge branch 'mm/maint-config-explicit-bool-display' into maint
[git/git.git] / t / t1300-repo-config.sh
CommitLineData
942c1f53
JS
1#!/bin/sh
2#
3# Copyright (c) 2005 Johannes Schindelin
4#
5
5be60078 6test_description='Test git config in different settings'
942c1f53
JS
7
8. ./test-lib.sh
9
10test -f .git/config && rm .git/config
11
5be60078 12git config core.penguin "little blue"
942c1f53
JS
13
14cat > expect << EOF
942c1f53
JS
15[core]
16 penguin = little blue
17EOF
18
19test_expect_success 'initial' 'cmp .git/config expect'
20
5be60078 21git config Core.Movie BadPhysics
942c1f53
JS
22
23cat > expect << EOF
942c1f53
JS
24[core]
25 penguin = little blue
26 Movie = BadPhysics
27EOF
28
29test_expect_success 'mixed case' 'cmp .git/config expect'
30
5be60078 31git config Cores.WhatEver Second
942c1f53
JS
32
33cat > expect << EOF
942c1f53
JS
34[core]
35 penguin = little blue
36 Movie = BadPhysics
37[Cores]
38 WhatEver = Second
39EOF
40
41test_expect_success 'similar section' 'cmp .git/config expect'
42
5be60078 43git config CORE.UPPERCASE true
942c1f53
JS
44
45cat > expect << EOF
942c1f53
JS
46[core]
47 penguin = little blue
48 Movie = BadPhysics
49 UPPERCASE = true
50[Cores]
51 WhatEver = Second
52EOF
53
54test_expect_success 'similar section' 'cmp .git/config expect'
55
f98d863d 56test_expect_success 'replace with non-match' \
5be60078 57 'git config core.penguin kingpin !blue'
f98d863d
JS
58
59test_expect_success 'replace with non-match (actually matching)' \
5be60078 60 'git config core.penguin "very blue" !kingpin'
f98d863d
JS
61
62cat > expect << EOF
f98d863d
JS
63[core]
64 penguin = very blue
65 Movie = BadPhysics
66 UPPERCASE = true
67 penguin = kingpin
68[Cores]
69 WhatEver = Second
70EOF
71
72test_expect_success 'non-match result' 'cmp .git/config expect'
73
7a31cc0f
FL
74cat > .git/config <<\EOF
75[alpha]
76bar = foo
77[beta]
78baz = multiple \
79lines
80EOF
81
82test_expect_success 'unset with cont. lines' \
83 'git config --unset beta.baz'
84
85cat > expect <<\EOF
86[alpha]
87bar = foo
88[beta]
89EOF
90
91test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
92
942c1f53
JS
93cat > .git/config << EOF
94[beta] ; silly comment # another comment
95noIndent= sillyValue ; 'nother silly comment
96
97# empty line
98 ; comment
99 haha ="beta" # last silly comment
4ddba79d
JS
100haha = hello
101 haha = bello
942c1f53
JS
102[nextSection] noNewline = ouch
103EOF
104
4ddba79d
JS
105cp .git/config .git/config2
106
107test_expect_success 'multiple unset' \
5be60078 108 'git config --unset-all beta.haha'
4ddba79d
JS
109
110cat > expect << EOF
111[beta] ; silly comment # another comment
112noIndent= sillyValue ; 'nother silly comment
113
114# empty line
115 ; comment
116[nextSection] noNewline = ouch
117EOF
118
119test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
120
bf71b4b3
CR
121cp .git/config2 .git/config
122
123test_expect_success '--replace-all missing value' '
124 test_must_fail git config --replace-all beta.haha &&
125 test_cmp .git/config2 .git/config
126'
127
128rm .git/config2
4ddba79d
JS
129
130test_expect_success '--replace-all' \
5be60078 131 'git config --replace-all beta.haha gamma'
4ddba79d
JS
132
133cat > expect << EOF
134[beta] ; silly comment # another comment
135noIndent= sillyValue ; 'nother silly comment
136
137# empty line
138 ; comment
139 haha = gamma
140[nextSection] noNewline = ouch
141EOF
142
143test_expect_success 'all replaced' 'cmp .git/config expect'
144
5be60078 145git config beta.haha alpha
942c1f53
JS
146
147cat > expect << EOF
148[beta] ; silly comment # another comment
149noIndent= sillyValue ; 'nother silly comment
150
151# empty line
152 ; comment
153 haha = alpha
154[nextSection] noNewline = ouch
155EOF
156
157test_expect_success 'really mean test' 'cmp .git/config expect'
158
5be60078 159git config nextsection.nonewline wow
942c1f53
JS
160
161cat > expect << EOF
162[beta] ; silly comment # another comment
163noIndent= sillyValue ; 'nother silly comment
164
165# empty line
166 ; comment
167 haha = alpha
168[nextSection]
169 nonewline = wow
170EOF
171
172test_expect_success 'really really mean test' 'cmp .git/config expect'
173
5be60078
JH
174test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
175git config --unset beta.haha
942c1f53
JS
176
177cat > expect << EOF
178[beta] ; silly comment # another comment
179noIndent= sillyValue ; 'nother silly comment
180
181# empty line
182 ; comment
183[nextSection]
184 nonewline = wow
185EOF
186
187test_expect_success 'unset' 'cmp .git/config expect'
188
5be60078 189git config nextsection.NoNewLine "wow2 for me" "for me$"
942c1f53
JS
190
191cat > expect << EOF
192[beta] ; silly comment # another comment
193noIndent= sillyValue ; 'nother silly comment
194
195# empty line
196 ; comment
197[nextSection]
198 nonewline = wow
199 NoNewLine = wow2 for me
200EOF
201
202test_expect_success 'multivar' 'cmp .git/config expect'
203
f98d863d 204test_expect_success 'non-match' \
5be60078 205 'git config --get nextsection.nonewline !for'
f98d863d
JS
206
207test_expect_success 'non-match value' \
5be60078 208 'test wow = $(git config --get nextsection.nonewline !for)'
f98d863d 209
41ac414e 210test_expect_success 'ambiguous get' '
d492b31c 211 test_must_fail git config --get nextsection.nonewline
41ac414e 212'
4ddba79d
JS
213
214test_expect_success 'get multivar' \
5be60078 215 'git config --get-all nextsection.nonewline'
4ddba79d 216
5be60078 217git config nextsection.nonewline "wow3" "wow$"
942c1f53
JS
218
219cat > expect << EOF
220[beta] ; silly comment # another comment
221noIndent= sillyValue ; 'nother silly comment
222
223# empty line
224 ; comment
225[nextSection]
226 nonewline = wow3
227 NoNewLine = wow2 for me
228EOF
229
230test_expect_success 'multivar replace' 'cmp .git/config expect'
231
41ac414e 232test_expect_success 'ambiguous value' '
d492b31c 233 test_must_fail git config nextsection.nonewline
41ac414e 234'
4ddba79d 235
41ac414e 236test_expect_success 'ambiguous unset' '
d492b31c 237 test_must_fail git config --unset nextsection.nonewline
41ac414e 238'
942c1f53 239
41ac414e 240test_expect_success 'invalid unset' '
d492b31c 241 test_must_fail git config --unset somesection.nonewline
41ac414e 242'
942c1f53 243
5be60078 244git config --unset nextsection.nonewline "wow3$"
942c1f53
JS
245
246cat > expect << EOF
247[beta] ; silly comment # another comment
248noIndent= sillyValue ; 'nother silly comment
249
250# empty line
251 ; comment
252[nextSection]
253 NoNewLine = wow2 for me
254EOF
255
256test_expect_success 'multivar unset' 'cmp .git/config expect'
257
d492b31c 258test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
942c1f53 259
5be60078 260test_expect_success 'correct key' 'git config 123456.a123 987'
942c1f53 261
b17e659d 262test_expect_success 'hierarchical section' \
5be60078 263 'git config Version.1.2.3eX.Alpha beta'
b17e659d
JS
264
265cat > expect << EOF
266[beta] ; silly comment # another comment
267noIndent= sillyValue ; 'nother silly comment
268
269# empty line
270 ; comment
271[nextSection]
272 NoNewLine = wow2 for me
273[123456]
274 a123 = 987
d14f7764
LT
275[Version "1.2.3eX"]
276 Alpha = beta
b17e659d
JS
277EOF
278
279test_expect_success 'hierarchical section value' 'cmp .git/config expect'
280
2fa9a0fb
JS
281cat > expect << EOF
282beta.noindent=sillyValue
283nextsection.nonewline=wow2 for me
284123456.a123=987
d55aaefa 285version.1.2.3eX.alpha=beta
2fa9a0fb
JS
286EOF
287
288test_expect_success 'working --list' \
5be60078 289 'git config --list > output && cmp output expect'
2fa9a0fb 290
1f2baa78
JK
291cat > expect << EOF
292EOF
293
294test_expect_success '--list without repo produces empty output' '
295 git --git-dir=nonexistent config --list >output &&
296 test_cmp expect output
297'
298
2fa9a0fb
JS
299cat > expect << EOF
300beta.noindent sillyValue
301nextsection.nonewline wow2 for me
302EOF
303
304test_expect_success '--get-regexp' \
5be60078 305 'git config --get-regexp in > output && cmp output expect'
2fa9a0fb 306
5be60078 307git config --add nextsection.nonewline "wow4 for you"
89c4afe0
BG
308
309cat > expect << EOF
310wow2 for me
311wow4 for you
312EOF
313
314test_expect_success '--add' \
5be60078 315 'git config --get-all nextsection.nonewline > output && cmp output expect'
89c4afe0 316
f067a137
JF
317cat > .git/config << EOF
318[novalue]
319 variable
09bc098c
CC
320[emptyvalue]
321 variable =
f067a137
JF
322EOF
323
324test_expect_success 'get variable with no value' \
5be60078 325 'git config --get novalue.variable ^$'
f067a137 326
09bc098c
CC
327test_expect_success 'get variable with empty value' \
328 'git config --get emptyvalue.variable ^$'
329
b69ba460
FL
330echo novalue.variable > expect
331
332test_expect_success 'get-regexp variable with no value' \
5be60078 333 'git config --get-regexp novalue > output &&
b69ba460
FL
334 cmp output expect'
335
008e3cc5
MM
336echo 'novalue.variable true' > expect
337
338test_expect_success 'get-regexp --bool variable with no value' \
339 'git config --bool --get-regexp novalue > output &&
340 cmp output expect'
341
09bc098c
CC
342echo 'emptyvalue.variable ' > expect
343
344test_expect_success 'get-regexp variable with empty value' \
345 'git config --get-regexp emptyvalue > output &&
346 cmp output expect'
347
348echo true > expect
349
350test_expect_success 'get bool variable with no value' \
351 'git config --bool novalue.variable > output &&
352 cmp output expect'
353
354echo false > expect
355
356test_expect_success 'get bool variable with empty value' \
357 'git config --bool emptyvalue.variable > output &&
358 cmp output expect'
359
003f69b2
JK
360test_expect_success 'no arguments, but no crash' '
361 test_must_fail git config >output 2>&1 &&
362 grep usage output
363'
2fa9a0fb 364
bd886fd3
SE
365cat > .git/config << EOF
366[a.b]
367 c = d
368EOF
369
5be60078 370git config a.x y
bd886fd3
SE
371
372cat > expect << EOF
373[a.b]
374 c = d
375[a]
376 x = y
377EOF
378
379test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
380
5be60078
JH
381git config b.x y
382git config a.b c
bd886fd3
SE
383
384cat > expect << EOF
385[a.b]
386 c = d
387[a]
388 x = y
389 b = c
390[b]
391 x = y
392EOF
393
394test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
395
773a69fb 396test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
003f69b2 397 'test_must_fail git config --file non-existing-config -l'
773a69fb 398
9c3796fc
JS
399cat > other-config << EOF
400[ein]
401 bahn = strasse
402EOF
403
404cat > expect << EOF
405ein.bahn=strasse
406EOF
407
5be60078 408GIT_CONFIG=other-config git config -l > output
9c3796fc
JS
409
410test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
411
773a69fb
AR
412test_expect_success 'alternative GIT_CONFIG (--file)' \
413 'git config --file other-config -l > output && cmp output expect'
414
65807ee6
JH
415test_expect_success 'refer config from subdirectory' '
416 mkdir x &&
417 (
418 cd x &&
419 echo strasse >expect
420 git config --get --file ../other-config ein.bahn >actual &&
421 test_cmp expect actual
422 )
423
424'
425
5be60078 426GIT_CONFIG=other-config git config anwohner.park ausweis
9c3796fc
JS
427
428cat > expect << EOF
429[ein]
430 bahn = strasse
431[anwohner]
432 park = ausweis
433EOF
434
435test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
436
0667fcfb
JS
437cat > .git/config << EOF
438# Hallo
439 #Bello
440[branch "eins"]
441 x = 1
442[branch.eins]
443 y = 1
444 [branch "1 234 blabl/a"]
445weird
446EOF
447
448test_expect_success "rename section" \
5be60078 449 "git config --rename-section branch.eins branch.zwei"
0667fcfb
JS
450
451cat > expect << EOF
452# Hallo
453 #Bello
454[branch "zwei"]
455 x = 1
456[branch "zwei"]
457 y = 1
458 [branch "1 234 blabl/a"]
459weird
460EOF
461
3af82863 462test_expect_success "rename succeeded" "test_cmp expect .git/config"
0667fcfb 463
41ac414e 464test_expect_success "rename non-existing section" '
d492b31c
SB
465 test_must_fail git config --rename-section \
466 branch."world domination" branch.drei
41ac414e 467'
0667fcfb 468
3af82863 469test_expect_success "rename succeeded" "test_cmp expect .git/config"
0667fcfb
JS
470
471test_expect_success "rename another section" \
5be60078 472 'git config --rename-section branch."1 234 blabl/a" branch.drei'
0667fcfb
JS
473
474cat > expect << EOF
475# Hallo
476 #Bello
477[branch "zwei"]
478 x = 1
479[branch "zwei"]
480 y = 1
481[branch "drei"]
482weird
483EOF
484
3af82863 485test_expect_success "rename succeeded" "test_cmp expect .git/config"
9a5abfc7
AV
486
487cat >> .git/config << EOF
488[branch "vier"] z = 1
489EOF
490
491test_expect_success "rename a section with a var on the same line" \
492 'git config --rename-section branch.vier branch.zwei'
493
494cat > expect << EOF
495# Hallo
496 #Bello
497[branch "zwei"]
498 x = 1
499[branch "zwei"]
500 y = 1
501[branch "drei"]
502weird
503[branch "zwei"]
504 z = 1
505EOF
506
507test_expect_success "rename succeeded" "test_cmp expect .git/config"
0667fcfb 508
118f8b24
PB
509cat >> .git/config << EOF
510 [branch "zwei"] a = 1 [branch "vier"]
511EOF
512
513test_expect_success "remove section" "git config --remove-section branch.zwei"
514
515cat > expect << EOF
516# Hallo
517 #Bello
518[branch "drei"]
519weird
520EOF
521
522test_expect_success "section was removed properly" \
3af82863 523 "test_cmp expect .git/config"
118f8b24 524
b18a2be3
SP
525rm .git/config
526
527cat > expect << EOF
528[gitcvs]
529 enabled = true
530 dbname = %Ggitcvs2.%a.%m.sqlite
531[gitcvs "ext"]
532 dbname = %Ggitcvs1.%a.%m.sqlite
533EOF
534
535test_expect_success 'section ending' '
536
5be60078
JH
537 git config gitcvs.enabled true &&
538 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
539 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
b18a2be3
SP
540 cmp .git/config expect
541
542'
543
d77a64d3
SP
544test_expect_success numbers '
545
5be60078
JH
546 git config kilo.gram 1k &&
547 git config mega.ton 1m &&
548 k=$(git config --int --get kilo.gram) &&
d77a64d3 549 test z1024 = "z$k" &&
5be60078 550 m=$(git config --int --get mega.ton) &&
d77a64d3
SP
551 test z1048576 = "z$m"
552'
553
c8deb5a1
SP
554cat > expect <<EOF
555fatal: bad config value for 'aninvalid.unit' in .git/config
556EOF
557
558test_expect_success 'invalid unit' '
559
560 git config aninvalid.unit "1auto" &&
561 s=$(git config aninvalid.unit) &&
562 test "z1auto" = "z$s" &&
563 if git config --int --get aninvalid.unit 2>actual
564 then
565 echo config should have failed
566 false
567 fi &&
568 cmp actual expect
569'
570
cab333cb
FL
571cat > expect << EOF
572true
573false
574true
575false
576true
577false
578true
579false
580EOF
581
582test_expect_success bool '
583
5be60078
JH
584 git config bool.true1 01 &&
585 git config bool.true2 -1 &&
586 git config bool.true3 YeS &&
587 git config bool.true4 true &&
588 git config bool.false1 000 &&
589 git config bool.false2 "" &&
590 git config bool.false3 nO &&
591 git config bool.false4 FALSE &&
cab333cb
FL
592 rm -f result &&
593 for i in 1 2 3 4
594 do
5be60078
JH
595 git config --bool --get bool.true$i >>result
596 git config --bool --get bool.false$i >>result
cab333cb
FL
597 done &&
598 cmp expect result'
599
41ac414e 600test_expect_success 'invalid bool (--get)' '
cab333cb 601
5be60078 602 git config bool.nobool foobar &&
d492b31c 603 test_must_fail git config --bool --get bool.nobool'
cab333cb 604
41ac414e 605test_expect_success 'invalid bool (set)' '
db1696b8 606
d492b31c 607 test_must_fail git config --bool bool.nobool foobar'
db1696b8
FL
608
609rm .git/config
610
611cat > expect <<\EOF
612[bool]
613 true1 = true
614 true2 = true
615 true3 = true
616 true4 = true
617 false1 = false
618 false2 = false
619 false3 = false
620 false4 = false
621EOF
622
623test_expect_success 'set --bool' '
624
5be60078
JH
625 git config --bool bool.true1 01 &&
626 git config --bool bool.true2 -1 &&
627 git config --bool bool.true3 YeS &&
628 git config --bool bool.true4 true &&
629 git config --bool bool.false1 000 &&
630 git config --bool bool.false2 "" &&
631 git config --bool bool.false3 nO &&
632 git config --bool bool.false4 FALSE &&
db1696b8
FL
633 cmp expect .git/config'
634
635rm .git/config
636
637cat > expect <<\EOF
638[int]
639 val1 = 1
640 val2 = -1
641 val3 = 5242880
642EOF
643
644test_expect_success 'set --int' '
645
5be60078
JH
646 git config --int int.val1 01 &&
647 git config --int int.val2 -1 &&
648 git config --int int.val3 5m &&
db1696b8
FL
649 cmp expect .git/config'
650
cdd4fb15
BG
651rm .git/config
652
c35b0b58
JH
653cat >expect <<\EOF
654[bool]
655 true1 = true
656 true2 = true
657 false1 = false
658 false2 = false
659[int]
660 int1 = 0
661 int2 = 1
662 int3 = -1
663EOF
664
665test_expect_success 'get --bool-or-int' '
666 (
667 echo "[bool]"
668 echo true1
669 echo true2 = true
670 echo false = false
671 echo "[int]"
672 echo int1 = 0
673 echo int2 = 1
674 echo int3 = -1
675 ) >>.git/config &&
676 test $(git config --bool-or-int bool.true1) = true &&
677 test $(git config --bool-or-int bool.true2) = true &&
678 test $(git config --bool-or-int bool.false) = false &&
679 test $(git config --bool-or-int int.int1) = 0 &&
680 test $(git config --bool-or-int int.int2) = 1 &&
681 test $(git config --bool-or-int int.int3) = -1
682
683'
684
685rm .git/config
686cat >expect <<\EOF
687[bool]
688 true1 = true
689 false1 = false
690 true2 = true
691 false2 = false
692[int]
693 int1 = 0
694 int2 = 1
695 int3 = -1
696EOF
697
698test_expect_success 'set --bool-or-int' '
699 git config --bool-or-int bool.true1 true &&
700 git config --bool-or-int bool.false1 false &&
701 git config --bool-or-int bool.true2 yes &&
702 git config --bool-or-int bool.false2 no &&
703 git config --bool-or-int int.int1 0 &&
704 git config --bool-or-int int.int2 1 &&
705 git config --bool-or-int int.int3 -1 &&
706 test_cmp expect .git/config
707'
708
709rm .git/config
710
1349484e
MM
711cat >expect <<\EOF
712[path]
713 home = ~/
714 normal = /dev/null
715 trailingtilde = foo~
716EOF
717
3ba9ba8f 718test_expect_success NOT_MINGW 'set --path' '
1349484e
MM
719 git config --path path.home "~/" &&
720 git config --path path.normal "/dev/null" &&
721 git config --path path.trailingtilde "foo~" &&
722 test_cmp expect .git/config'
723
3ba9ba8f 724if test_have_prereq NOT_MINGW && test "${HOME+set}"
79bf1490
JN
725then
726 test_set_prereq HOMEVAR
727fi
728
1349484e
MM
729cat >expect <<EOF
730$HOME/
731/dev/null
732foo~
733EOF
734
79bf1490 735test_expect_success HOMEVAR 'get --path' '
1349484e
MM
736 git config --get --path path.home > result &&
737 git config --get --path path.normal >> result &&
738 git config --get --path path.trailingtilde >> result &&
739 test_cmp expect result
740'
741
79bf1490
JN
742cat >expect <<\EOF
743/dev/null
744foo~
745EOF
746
3ba9ba8f 747test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
79bf1490
JN
748 (
749 unset HOME;
750 test_must_fail git config --get --path path.home \
751 >result 2>msg &&
752 git config --get --path path.normal >>result &&
753 git config --get --path path.trailingtilde >>result
754 ) &&
755 grep "[Ff]ailed to expand.*~/" msg &&
756 test_cmp expect result
757'
758
1349484e
MM
759rm .git/config
760
5be60078
JH
761git config quote.leading " test"
762git config quote.ending "test "
763git config quote.semicolon "test;test"
764git config quote.hash "test#test"
cdd4fb15
BG
765
766cat > expect << EOF
767[quote]
768 leading = " test"
769 ending = "test "
770 semicolon = "test;test"
771 hash = "test#test"
772EOF
773
774test_expect_success 'quoting' 'cmp .git/config expect'
775
41ac414e 776test_expect_success 'key with newline' '
d492b31c 777 test_must_fail git config "key.with
41ac414e 778newline" 123'
6f71686e 779
e0d10e1c 780test_expect_success 'value with newline' 'git config key.sub value.with\\\
6f71686e
JS
781newline'
782
83cd10a0
JN
783cat > .git/config <<\EOF
784[section]
785 ; comment \
786 continued = cont\
787inued
788 noncont = not continued ; \
789 quotecont = "cont;\
790inued"
791EOF
792
793cat > expect <<\EOF
794section.continued=continued
795section.noncont=not continued
796section.quotecont=cont;inued
797EOF
798
e0d10e1c 799git config --list > result
83cd10a0
JN
800
801test_expect_success 'value continued on next line' 'cmp result expect'
802
2275d502
FL
803cat > .git/config <<\EOF
804[section "sub=section"]
805 val1 = foo=bar
806 val2 = foo\nbar
807 val3 = \n\n
808 val4 =
809 val5
810EOF
811
812cat > expect <<\EOF
2b9a5020
AR
813section.sub=section.val1
814foo=barQsection.sub=section.val2
815foo
816barQsection.sub=section.val3
2275d502
FL
817
818
2b9a5020
AR
819Qsection.sub=section.val4
820Qsection.sub=section.val5Q
2275d502
FL
821EOF
822
e85fe4d8 823git config --null --list | perl -pe 'y/\000/Q/' > result
2b9a5020 824echo >>result
2275d502
FL
825
826test_expect_success '--null --list' 'cmp result expect'
827
e85fe4d8 828git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
2b9a5020 829echo >>result
2275d502
FL
830
831test_expect_success '--null --get-regexp' 'cmp result expect'
832
ebdaae37
BS
833test_expect_success 'inner whitespace kept verbatim' '
834 git config section.val "foo bar" &&
835 test "z$(git config section.val)" = "zfoo bar"
836'
837
704a3143 838test_expect_success SYMLINKS 'symlinked configuration' '
65a5a21d
JH
839
840 ln -s notyet myconfig &&
841 GIT_CONFIG=myconfig git config test.frotz nitfol &&
842 test -h myconfig &&
843 test -f notyet &&
844 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
845 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
846 test -h myconfig &&
847 test -f notyet &&
848 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
849 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
850
851'
852
1f2baa78
JK
853test_expect_success 'nonexistent configuration' '
854 (
855 GIT_CONFIG=doesnotexist &&
856 export GIT_CONFIG &&
857 test_must_fail git config --list &&
858 test_must_fail git config test.xyzzy
859 )
860'
861
862test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
863 ln -s doesnotexist linktonada &&
864 ln -s linktonada linktolinktonada &&
865 (
866 GIT_CONFIG=linktonada &&
867 export GIT_CONFIG &&
868 test_must_fail git config --list &&
869 GIT_CONFIG=linktolinktonada &&
870 test_must_fail git config --list
871 )
872'
873
dc4179f9
DM
874test_expect_success 'check split_cmdline return' "
875 git config alias.split-cmdline-fix 'echo \"' &&
876 test_must_fail git split-cmdline-fix &&
877 echo foo > foo &&
878 git add foo &&
879 git commit -m 'initial commit' &&
880 git config branch.master.mergeoptions 'echo \"' &&
881 test_must_fail git merge master
882 "
883
8b1fa778 884test_expect_success 'git -c "key=value" support' '
8b1fa778 885 test "z$(git -c core.name=value config core.name)" = zvalue &&
b09c53a3
LP
886 test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue &&
887 test "z$(git -c foo.flag config --bool foo.flag)" = ztrue &&
888 test_must_fail git -c name=value config core.name
889'
890
891test_expect_success 'key sanity-checking' '
892 test_must_fail git config foo=bar &&
893 test_must_fail git config foo=.bar &&
894 test_must_fail git config foo.ba=r &&
895 test_must_fail git config foo.1bar &&
896 test_must_fail git config foo."ba
897 z".bar &&
2169ddc0
LP
898 test_must_fail git config . false &&
899 test_must_fail git config .foo false &&
900 test_must_fail git config foo. false &&
901 test_must_fail git config .foo. false &&
b09c53a3
LP
902 git config foo.bar true &&
903 git config foo."ba =z".bar false
8b1fa778
AR
904'
905
73546c08 906test_expect_success 'git -c works with aliases of builtins' '
06eb708f
JK
907 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
908 echo bar >expect &&
909 git checkconfig >actual &&
910 test_cmp expect actual
911'
912
5bf6529a
JK
913test_expect_success 'git -c does not split values on equals' '
914 echo "value with = in it" >expect &&
915 git -c core.foo="value with = in it" config core.foo >actual &&
916 test_cmp expect actual
917'
918
1c2c9bee
JK
919test_expect_success 'git -c dies on bogus config' '
920 test_must_fail git -c core.bare=foo rev-parse
921'
922
923test_expect_success 'git -c complains about empty key' '
924 test_must_fail git -c "=foo" rev-parse
925'
926
c5d6350b
JK
927test_expect_success 'git -c complains about empty key and value' '
928 test_must_fail git -c "" rev-parse
929'
930
942c1f53 931test_done