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