]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1300-config.sh
t1300: add a few more hairy examples of sections becoming empty
[thirdparty/git.git] / t / t1300-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 40test_expect_success 'similar section' '
02380389 41 git config Cores.WhatEver Second &&
5a953fc5
JK
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
ed838e66
JK
58test_expect_success 'replace with non-match' '
59 git config core.penguin kingpin !blue
60'
f98d863d 61
ed838e66
JK
62test_expect_success 'replace with non-match (actually matching)' '
63 git config core.penguin "very blue" !kingpin
64'
f98d863d
JS
65
66cat > expect << EOF
f98d863d
JS
67[core]
68 penguin = very blue
69 Movie = BadPhysics
70 UPPERCASE = true
71 penguin = kingpin
72[Cores]
73 WhatEver = Second
74EOF
75
5a953fc5 76test_expect_success 'non-match result' 'test_cmp expect .git/config'
f98d863d 77
88d42af8
JK
78test_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
84test_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
90test_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'
f98d863d 104
7a31cc0f
FL
105cat > .git/config <<\EOF
106[alpha]
107bar = foo
108[beta]
109baz = multiple \
110lines
85bf5d61 111foo = bar
7a31cc0f
FL
112EOF
113
ed838e66
JK
114test_expect_success 'unset with cont. lines' '
115 git config --unset beta.baz
116'
7a31cc0f
FL
117
118cat > expect <<\EOF
119[alpha]
120bar = foo
121[beta]
85bf5d61 122foo = bar
7a31cc0f
FL
123EOF
124
5a953fc5 125test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
7a31cc0f 126
942c1f53
JS
127cat > .git/config << EOF
128[beta] ; silly comment # another comment
129noIndent= sillyValue ; 'nother silly comment
130
131# empty line
132 ; comment
133 haha ="beta" # last silly comment
4ddba79d
JS
134haha = hello
135 haha = bello
942c1f53
JS
136[nextSection] noNewline = ouch
137EOF
138
4ddba79d
JS
139cp .git/config .git/config2
140
ed838e66
JK
141test_expect_success 'multiple unset' '
142 git config --unset-all beta.haha
143'
4ddba79d
JS
144
145cat > expect << EOF
146[beta] ; silly comment # another comment
147noIndent= sillyValue ; 'nother silly comment
148
149# empty line
150 ; comment
151[nextSection] noNewline = ouch
152EOF
153
ed838e66
JK
154test_expect_success 'multiple unset is correct' '
155 test_cmp expect .git/config
156'
4ddba79d 157
bf71b4b3
CR
158cp .git/config2 .git/config
159
160test_expect_success '--replace-all missing value' '
161 test_must_fail git config --replace-all beta.haha &&
162 test_cmp .git/config2 .git/config
163'
164
165rm .git/config2
4ddba79d 166
ed838e66
JK
167test_expect_success '--replace-all' '
168 git config --replace-all beta.haha gamma
169'
4ddba79d
JS
170
171cat > expect << EOF
172[beta] ; silly comment # another comment
173noIndent= sillyValue ; 'nother silly comment
174
175# empty line
176 ; comment
177 haha = gamma
178[nextSection] noNewline = ouch
179EOF
180
ed838e66
JK
181test_expect_success 'all replaced' '
182 test_cmp expect .git/config
183'
942c1f53
JS
184
185cat > expect << EOF
186[beta] ; silly comment # another comment
187noIndent= sillyValue ; 'nother silly comment
188
189# empty line
190 ; comment
191 haha = alpha
192[nextSection] noNewline = ouch
193EOF
5a953fc5
JK
194test_expect_success 'really mean test' '
195 git config beta.haha alpha &&
196 test_cmp expect .git/config
197'
942c1f53
JS
198
199cat > expect << EOF
200[beta] ; silly comment # another comment
201noIndent= sillyValue ; 'nother silly comment
202
203# empty line
204 ; comment
205 haha = alpha
206[nextSection]
207 nonewline = wow
208EOF
5a953fc5
JK
209test_expect_success 'really really mean test' '
210 git config nextsection.nonewline wow &&
211 test_cmp expect .git/config
212'
942c1f53 213
ed838e66
JK
214test_expect_success 'get value' '
215 echo alpha >expect &&
216 git config beta.haha >actual &&
217 test_cmp expect actual
218'
942c1f53
JS
219
220cat > expect << EOF
221[beta] ; silly comment # another comment
222noIndent= sillyValue ; 'nother silly comment
223
224# empty line
225 ; comment
226[nextSection]
227 nonewline = wow
228EOF
5a953fc5
JK
229test_expect_success 'unset' '
230 git config --unset beta.haha &&
231 test_cmp expect .git/config
232'
942c1f53
JS
233
234cat > expect << EOF
235[beta] ; silly comment # another comment
236noIndent= sillyValue ; 'nother silly comment
237
238# empty line
239 ; comment
240[nextSection]
241 nonewline = wow
242 NoNewLine = wow2 for me
243EOF
5a953fc5
JK
244test_expect_success 'multivar' '
245 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
246 test_cmp expect .git/config
247'
942c1f53 248
ed838e66
JK
249test_expect_success 'non-match' '
250 git config --get nextsection.nonewline !for
251'
f98d863d 252
ed838e66
JK
253test_expect_success 'non-match value' '
254 echo wow >expect &&
255 git config --get nextsection.nonewline !for >actual &&
256 test_cmp expect actual
257'
f98d863d 258
00b347d3
JK
259test_expect_success 'multi-valued get returns final one' '
260 echo "wow2 for me" >expect &&
261 git config --get nextsection.nonewline >actual &&
262 test_cmp expect actual
41ac414e 263'
4ddba79d 264
cb20b691
JK
265test_expect_success 'multi-valued get-all returns all' '
266 cat >expect <<-\EOF &&
267 wow
268 wow2 for me
269 EOF
270 git config --get-all nextsection.nonewline >actual &&
271 test_cmp expect actual
ed838e66 272'
4ddba79d 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 = wow3
282 NoNewLine = wow2 for me
283EOF
5a953fc5
JK
284test_expect_success 'multivar replace' '
285 git config nextsection.nonewline "wow3" "wow$" &&
286 test_cmp expect .git/config
287'
942c1f53 288
41ac414e 289test_expect_success 'ambiguous unset' '
d492b31c 290 test_must_fail git config --unset nextsection.nonewline
41ac414e 291'
942c1f53 292
41ac414e 293test_expect_success 'invalid unset' '
d492b31c 294 test_must_fail git config --unset somesection.nonewline
41ac414e 295'
942c1f53 296
942c1f53
JS
297cat > expect << EOF
298[beta] ; silly comment # another comment
299noIndent= sillyValue ; 'nother silly comment
300
301# empty line
302 ; comment
303[nextSection]
304 NoNewLine = wow2 for me
305EOF
306
5a953fc5
JK
307test_expect_success 'multivar unset' '
308 git config --unset nextsection.nonewline "wow3$" &&
309 test_cmp expect .git/config
310'
942c1f53 311
d492b31c 312test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
942c1f53 313
5be60078 314test_expect_success 'correct key' 'git config 123456.a123 987'
942c1f53 315
ed838e66
JK
316test_expect_success 'hierarchical section' '
317 git config Version.1.2.3eX.Alpha beta
318'
b17e659d
JS
319
320cat > expect << EOF
321[beta] ; silly comment # another comment
322noIndent= sillyValue ; 'nother silly comment
323
324# empty line
325 ; comment
326[nextSection]
327 NoNewLine = wow2 for me
328[123456]
329 a123 = 987
d14f7764
LT
330[Version "1.2.3eX"]
331 Alpha = beta
b17e659d
JS
332EOF
333
ed838e66
JK
334test_expect_success 'hierarchical section value' '
335 test_cmp expect .git/config
336'
b17e659d 337
2fa9a0fb
JS
338cat > expect << EOF
339beta.noindent=sillyValue
340nextsection.nonewline=wow2 for me
341123456.a123=987
d55aaefa 342version.1.2.3eX.alpha=beta
2fa9a0fb
JS
343EOF
344
ed838e66
JK
345test_expect_success 'working --list' '
346 git config --list > output &&
347 test_cmp expect output
348'
1f2baa78
JK
349cat > expect << EOF
350EOF
351
352test_expect_success '--list without repo produces empty output' '
353 git --git-dir=nonexistent config --list >output &&
354 test_cmp expect output
355'
356
578625fa
SG
357cat > expect << EOF
358beta.noindent
359nextsection.nonewline
360123456.a123
361version.1.2.3eX.alpha
362EOF
363
364test_expect_success '--name-only --list' '
365 git config --name-only --list >output &&
366 test_cmp expect output
367'
368
2fa9a0fb
JS
369cat > expect << EOF
370beta.noindent sillyValue
371nextsection.nonewline wow2 for me
372EOF
373
ed838e66
JK
374test_expect_success '--get-regexp' '
375 git config --get-regexp in >output &&
376 test_cmp expect output
377'
2fa9a0fb 378
578625fa
SG
379cat > expect << EOF
380beta.noindent
381nextsection.nonewline
382EOF
383
384test_expect_success '--name-only --get-regexp' '
385 git config --name-only --get-regexp in >output &&
386 test_cmp expect output
387'
388
89c4afe0
BG
389cat > expect << EOF
390wow2 for me
391wow4 for you
392EOF
393
5a953fc5
JK
394test_expect_success '--add' '
395 git config --add nextsection.nonewline "wow4 for you" &&
396 git config --get-all nextsection.nonewline > output &&
397 test_cmp expect output
398'
89c4afe0 399
f067a137
JF
400cat > .git/config << EOF
401[novalue]
402 variable
09bc098c
CC
403[emptyvalue]
404 variable =
f067a137
JF
405EOF
406
ed838e66
JK
407test_expect_success 'get variable with no value' '
408 git config --get novalue.variable ^$
409'
f067a137 410
ed838e66
JK
411test_expect_success 'get variable with empty value' '
412 git config --get emptyvalue.variable ^$
413'
09bc098c 414
b69ba460
FL
415echo novalue.variable > expect
416
ed838e66
JK
417test_expect_success 'get-regexp variable with no value' '
418 git config --get-regexp novalue > output &&
419 test_cmp expect output
420'
b69ba460 421
008e3cc5
MM
422echo 'novalue.variable true' > expect
423
ed838e66
JK
424test_expect_success 'get-regexp --bool variable with no value' '
425 git config --bool --get-regexp novalue > output &&
426 test_cmp expect output
427'
008e3cc5 428
09bc098c
CC
429echo 'emptyvalue.variable ' > expect
430
ed838e66
JK
431test_expect_success 'get-regexp variable with empty value' '
432 git config --get-regexp emptyvalue > output &&
433 test_cmp expect output
434'
09bc098c
CC
435
436echo true > expect
437
ed838e66
JK
438test_expect_success 'get bool variable with no value' '
439 git config --bool novalue.variable > output &&
440 test_cmp expect output
441'
09bc098c
CC
442
443echo false > expect
444
ed838e66
JK
445test_expect_success 'get bool variable with empty value' '
446 git config --bool emptyvalue.variable > output &&
447 test_cmp expect output
448'
09bc098c 449
003f69b2
JK
450test_expect_success 'no arguments, but no crash' '
451 test_must_fail git config >output 2>&1 &&
9a001381 452 test_i18ngrep usage output
003f69b2 453'
2fa9a0fb 454
bd886fd3
SE
455cat > .git/config << EOF
456[a.b]
457 c = d
458EOF
459
bd886fd3
SE
460cat > expect << EOF
461[a.b]
462 c = d
463[a]
464 x = y
465EOF
466
5a953fc5
JK
467test_expect_success 'new section is partial match of another' '
468 git config a.x y &&
469 test_cmp expect .git/config
470'
bd886fd3
SE
471
472cat > expect << EOF
473[a.b]
474 c = d
475[a]
476 x = y
477 b = c
478[b]
479 x = y
480EOF
481
5a953fc5
JK
482test_expect_success 'new variable inserts into proper section' '
483 git config b.x y &&
484 git config a.b c &&
485 test_cmp expect .git/config
486'
bd886fd3 487
f7e87141 488test_expect_success 'alternative --file (non-existing file should fail)' '
ed838e66
JK
489 test_must_fail git config --file non-existing-config -l
490'
773a69fb 491
9c3796fc
JS
492cat > other-config << EOF
493[ein]
494 bahn = strasse
495EOF
496
497cat > expect << EOF
498ein.bahn=strasse
499EOF
500
5a953fc5 501test_expect_success 'alternative GIT_CONFIG' '
3caec73b 502 GIT_CONFIG=other-config git config --list >output &&
5a953fc5
JK
503 test_cmp expect output
504'
9c3796fc 505
ed838e66 506test_expect_success 'alternative GIT_CONFIG (--file)' '
3caec73b 507 git config --file other-config --list >output &&
ed838e66
JK
508 test_cmp expect output
509'
773a69fb 510
3caec73b
KS
511test_expect_success 'alternative GIT_CONFIG (--file=-)' '
512 git config --file - --list <other-config >output &&
513 test_cmp expect output
514'
515
516test_expect_success 'setting a value in stdin is an error' '
517 test_must_fail git config --file - some.value foo
518'
519
520test_expect_success 'editing stdin is an error' '
521 test_must_fail git config --file - --edit
522'
523
65807ee6
JH
524test_expect_success 'refer config from subdirectory' '
525 mkdir x &&
526 (
527 cd x &&
27370b11 528 echo strasse >expect &&
65807ee6
JH
529 git config --get --file ../other-config ein.bahn >actual &&
530 test_cmp expect actual
531 )
532
533'
534
f7e87141 535test_expect_success 'refer config from subdirectory via --file' '
270a3443
JK
536 (
537 cd x &&
f7e87141 538 git config --file=../other-config --get ein.bahn >actual &&
270a3443
JK
539 test_cmp expect actual
540 )
541'
542
9c3796fc
JS
543cat > expect << EOF
544[ein]
545 bahn = strasse
546[anwohner]
547 park = ausweis
548EOF
549
f7e87141
JK
550test_expect_success '--set in alternative file' '
551 git config --file=other-config anwohner.park ausweis &&
5a953fc5
JK
552 test_cmp expect other-config
553'
9c3796fc 554
0667fcfb
JS
555cat > .git/config << EOF
556# Hallo
557 #Bello
558[branch "eins"]
559 x = 1
560[branch.eins]
561 y = 1
562 [branch "1 234 blabl/a"]
563weird
564EOF
565
ed838e66
JK
566test_expect_success 'rename section' '
567 git config --rename-section branch.eins branch.zwei
568'
0667fcfb
JS
569
570cat > expect << EOF
571# Hallo
572 #Bello
573[branch "zwei"]
574 x = 1
575[branch "zwei"]
576 y = 1
577 [branch "1 234 blabl/a"]
578weird
579EOF
580
ed838e66
JK
581test_expect_success 'rename succeeded' '
582 test_cmp expect .git/config
583'
0667fcfb 584
ed838e66 585test_expect_success 'rename non-existing section' '
d492b31c
SB
586 test_must_fail git config --rename-section \
587 branch."world domination" branch.drei
41ac414e 588'
0667fcfb 589
ed838e66
JK
590test_expect_success 'rename succeeded' '
591 test_cmp expect .git/config
592'
0667fcfb 593
ed838e66
JK
594test_expect_success 'rename another section' '
595 git config --rename-section branch."1 234 blabl/a" branch.drei
596'
0667fcfb
JS
597
598cat > expect << EOF
599# Hallo
600 #Bello
601[branch "zwei"]
602 x = 1
603[branch "zwei"]
604 y = 1
605[branch "drei"]
606weird
607EOF
608
ed838e66
JK
609test_expect_success 'rename succeeded' '
610 test_cmp expect .git/config
611'
9a5abfc7
AV
612
613cat >> .git/config << EOF
614[branch "vier"] z = 1
615EOF
616
ed838e66
JK
617test_expect_success 'rename a section with a var on the same line' '
618 git config --rename-section branch.vier branch.zwei
619'
9a5abfc7
AV
620
621cat > expect << EOF
622# Hallo
623 #Bello
624[branch "zwei"]
625 x = 1
626[branch "zwei"]
627 y = 1
628[branch "drei"]
629weird
630[branch "zwei"]
631 z = 1
632EOF
633
ed838e66
JK
634test_expect_success 'rename succeeded' '
635 test_cmp expect .git/config
636'
0667fcfb 637
94a35b1a
JK
638test_expect_success 'renaming empty section name is rejected' '
639 test_must_fail git config --rename-section branch.zwei ""
640'
641
642test_expect_success 'renaming to bogus section is rejected' '
643 test_must_fail git config --rename-section branch.zwei "bogus name"
644'
645
118f8b24
PB
646cat >> .git/config << EOF
647 [branch "zwei"] a = 1 [branch "vier"]
648EOF
649
ed838e66
JK
650test_expect_success 'remove section' '
651 git config --remove-section branch.zwei
652'
118f8b24
PB
653
654cat > expect << EOF
655# Hallo
656 #Bello
657[branch "drei"]
658weird
659EOF
660
ed838e66
JK
661test_expect_success 'section was removed properly' '
662 test_cmp expect .git/config
663'
118f8b24 664
b18a2be3
SP
665cat > expect << EOF
666[gitcvs]
667 enabled = true
668 dbname = %Ggitcvs2.%a.%m.sqlite
669[gitcvs "ext"]
670 dbname = %Ggitcvs1.%a.%m.sqlite
671EOF
672
673test_expect_success 'section ending' '
795290e5 674 rm -f .git/config &&
5be60078
JH
675 git config gitcvs.enabled true &&
676 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
677 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
5a953fc5 678 test_cmp expect .git/config
b18a2be3
SP
679
680'
681
d77a64d3 682test_expect_success numbers '
5be60078
JH
683 git config kilo.gram 1k &&
684 git config mega.ton 1m &&
ed838e66
JK
685 echo 1024 >expect &&
686 echo 1048576 >>expect &&
687 git config --int --get kilo.gram >actual &&
688 git config --int --get mega.ton >>actual &&
689 test_cmp expect actual
d77a64d3
SP
690'
691
00160242
JK
692test_expect_success '--int is at least 64 bits' '
693 git config giga.watts 121g &&
694 echo 129922760704 >expect &&
695 git config --int --get giga.watts >actual &&
696 test_cmp expect actual
697'
698
c8deb5a1 699test_expect_success 'invalid unit' '
c8deb5a1 700 git config aninvalid.unit "1auto" &&
ed838e66
JK
701 echo 1auto >expect &&
702 git config aninvalid.unit >actual &&
703 test_cmp expect actual &&
ed838e66 704 test_must_fail git config --int --get aninvalid.unit 2>actual &&
2ec20212 705 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
c8deb5a1
SP
706'
707
e2e14251
JS
708test_expect_success 'line number is reported correctly' '
709 printf "[bool]\n\tvar\n" >invalid &&
710 test_must_fail git config -f invalid --path bool.var 2>actual &&
711 test_i18ngrep "line 2" actual
712'
713
473166b9 714test_expect_success 'invalid stdin config' '
473166b9 715 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
2ec20212 716 test_i18ngrep "bad config line 1 in standard input" output
473166b9
LS
717'
718
cab333cb
FL
719cat > expect << EOF
720true
721false
722true
723false
724true
725false
726true
727false
728EOF
729
730test_expect_success bool '
731
5be60078
JH
732 git config bool.true1 01 &&
733 git config bool.true2 -1 &&
734 git config bool.true3 YeS &&
735 git config bool.true4 true &&
736 git config bool.false1 000 &&
737 git config bool.false2 "" &&
738 git config bool.false3 nO &&
739 git config bool.false4 FALSE &&
cab333cb
FL
740 rm -f result &&
741 for i in 1 2 3 4
742 do
5be60078
JH
743 git config --bool --get bool.true$i >>result
744 git config --bool --get bool.false$i >>result
cab333cb 745 done &&
ed838e66 746 test_cmp expect result'
cab333cb 747
41ac414e 748test_expect_success 'invalid bool (--get)' '
cab333cb 749
5be60078 750 git config bool.nobool foobar &&
d492b31c 751 test_must_fail git config --bool --get bool.nobool'
cab333cb 752
41ac414e 753test_expect_success 'invalid bool (set)' '
db1696b8 754
d492b31c 755 test_must_fail git config --bool bool.nobool foobar'
db1696b8 756
db1696b8
FL
757cat > expect <<\EOF
758[bool]
759 true1 = true
760 true2 = true
761 true3 = true
762 true4 = true
763 false1 = false
764 false2 = false
765 false3 = false
766 false4 = false
767EOF
768
769test_expect_success 'set --bool' '
770
795290e5 771 rm -f .git/config &&
5be60078
JH
772 git config --bool bool.true1 01 &&
773 git config --bool bool.true2 -1 &&
774 git config --bool bool.true3 YeS &&
775 git config --bool bool.true4 true &&
776 git config --bool bool.false1 000 &&
777 git config --bool bool.false2 "" &&
778 git config --bool bool.false3 nO &&
779 git config --bool bool.false4 FALSE &&
ed838e66 780 test_cmp expect .git/config'
db1696b8 781
db1696b8
FL
782cat > expect <<\EOF
783[int]
784 val1 = 1
785 val2 = -1
786 val3 = 5242880
787EOF
788
789test_expect_success 'set --int' '
790
795290e5 791 rm -f .git/config &&
5be60078
JH
792 git config --int int.val1 01 &&
793 git config --int int.val2 -1 &&
794 git config --int int.val3 5m &&
ed838e66
JK
795 test_cmp expect .git/config
796'
db1696b8 797
ed838e66
JK
798test_expect_success 'get --bool-or-int' '
799 cat >.git/config <<-\EOF &&
800 [bool]
801 true1
c35b0b58 802 true2 = true
ed838e66
JK
803 false = false
804 [int]
c35b0b58
JH
805 int1 = 0
806 int2 = 1
807 int3 = -1
ed838e66
JK
808 EOF
809 cat >expect <<-\EOF &&
810 true
811 true
812 false
813 0
814 1
815 -1
816 EOF
817 {
818 git config --bool-or-int bool.true1 &&
819 git config --bool-or-int bool.true2 &&
820 git config --bool-or-int bool.false &&
821 git config --bool-or-int int.int1 &&
822 git config --bool-or-int int.int2 &&
823 git config --bool-or-int int.int3
824 } >actual &&
825 test_cmp expect actual
c35b0b58
JH
826'
827
c35b0b58
JH
828cat >expect <<\EOF
829[bool]
830 true1 = true
831 false1 = false
832 true2 = true
833 false2 = false
834[int]
835 int1 = 0
836 int2 = 1
837 int3 = -1
838EOF
839
840test_expect_success 'set --bool-or-int' '
795290e5 841 rm -f .git/config &&
c35b0b58
JH
842 git config --bool-or-int bool.true1 true &&
843 git config --bool-or-int bool.false1 false &&
844 git config --bool-or-int bool.true2 yes &&
845 git config --bool-or-int bool.false2 no &&
846 git config --bool-or-int int.int1 0 &&
847 git config --bool-or-int int.int2 1 &&
848 git config --bool-or-int int.int3 -1 &&
849 test_cmp expect .git/config
850'
851
1349484e
MM
852cat >expect <<\EOF
853[path]
854 home = ~/
855 normal = /dev/null
856 trailingtilde = foo~
857EOF
858
f57a8715 859test_expect_success !MINGW 'set --path' '
795290e5 860 rm -f .git/config &&
1349484e
MM
861 git config --path path.home "~/" &&
862 git config --path path.normal "/dev/null" &&
863 git config --path path.trailingtilde "foo~" &&
864 test_cmp expect .git/config'
865
f57a8715 866if test_have_prereq !MINGW && test "${HOME+set}"
79bf1490
JN
867then
868 test_set_prereq HOMEVAR
869fi
870
1349484e
MM
871cat >expect <<EOF
872$HOME/
873/dev/null
874foo~
875EOF
876
79bf1490 877test_expect_success HOMEVAR 'get --path' '
1349484e
MM
878 git config --get --path path.home > result &&
879 git config --get --path path.normal >> result &&
880 git config --get --path path.trailingtilde >> result &&
881 test_cmp expect result
882'
883
79bf1490
JN
884cat >expect <<\EOF
885/dev/null
886foo~
887EOF
888
f57a8715 889test_expect_success !MINGW 'get --path copes with unset $HOME' '
79bf1490
JN
890 (
891 unset HOME;
892 test_must_fail git config --get --path path.home \
893 >result 2>msg &&
894 git config --get --path path.normal >>result &&
895 git config --get --path path.trailingtilde >>result
896 ) &&
1edbaac3 897 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
79bf1490
JN
898 test_cmp expect result
899'
900
962c38ee
CMN
901test_expect_success 'get --path barfs on boolean variable' '
902 echo "[path]bool" >.git/config &&
903 test_must_fail git config --get --path path.bool
904'
905
5f967424
HM
906test_expect_success 'get --expiry-date' '
907 rel="3.weeks.5.days.00:00" &&
908 rel_out="$rel ->" &&
909 cat >.git/config <<-\EOF &&
910 [date]
911 valid1 = "3.weeks.5.days 00:00"
912 valid2 = "Fri Jun 4 15:46:55 2010"
913 valid3 = "2017/11/11 11:11:11PM"
914 valid4 = "2017/11/10 09:08:07 PM"
915 valid5 = "never"
916 invalid1 = "abc"
917 EOF
918 cat >expect <<-EOF &&
919 $(test-date timestamp $rel)
920 1275666415
921 1510441871
922 1510348087
923 0
924 EOF
925 {
926 echo "$rel_out $(git config --expiry-date date.valid1)"
927 git config --expiry-date date.valid2 &&
928 git config --expiry-date date.valid3 &&
929 git config --expiry-date date.valid4 &&
930 git config --expiry-date date.valid5
931 } >actual &&
932 test_cmp expect actual &&
933 test_must_fail git config --expiry-date date.invalid1
934'
935
cdd4fb15
BG
936cat > expect << EOF
937[quote]
938 leading = " test"
939 ending = "test "
940 semicolon = "test;test"
941 hash = "test#test"
942EOF
5a953fc5 943test_expect_success 'quoting' '
795290e5 944 rm -f .git/config &&
5a953fc5
JK
945 git config quote.leading " test" &&
946 git config quote.ending "test " &&
947 git config quote.semicolon "test;test" &&
948 git config quote.hash "test#test" &&
949 test_cmp expect .git/config
950'
cdd4fb15 951
41ac414e 952test_expect_success 'key with newline' '
d492b31c 953 test_must_fail git config "key.with
41ac414e 954newline" 123'
6f71686e 955
e0d10e1c 956test_expect_success 'value with newline' 'git config key.sub value.with\\\
6f71686e
JS
957newline'
958
83cd10a0
JN
959cat > .git/config <<\EOF
960[section]
961 ; comment \
962 continued = cont\
963inued
964 noncont = not continued ; \
965 quotecont = "cont;\
966inued"
967EOF
968
969cat > expect <<\EOF
970section.continued=continued
971section.noncont=not continued
972section.quotecont=cont;inued
973EOF
974
5a953fc5
JK
975test_expect_success 'value continued on next line' '
976 git config --list > result &&
ed838e66 977 test_cmp result expect
5a953fc5 978'
83cd10a0 979
2275d502
FL
980cat > .git/config <<\EOF
981[section "sub=section"]
982 val1 = foo=bar
983 val2 = foo\nbar
984 val3 = \n\n
985 val4 =
986 val5
987EOF
988
989cat > expect <<\EOF
2b9a5020
AR
990section.sub=section.val1
991foo=barQsection.sub=section.val2
992foo
993barQsection.sub=section.val3
2275d502
FL
994
995
2b9a5020
AR
996Qsection.sub=section.val4
997Qsection.sub=section.val5Q
2275d502 998EOF
5a953fc5 999test_expect_success '--null --list' '
a0578e03
LS
1000 git config --null --list >result.raw &&
1001 nul_to_q <result.raw >result &&
5a953fc5
JK
1002 echo >>result &&
1003 test_cmp expect result
1004'
2275d502 1005
5a953fc5 1006test_expect_success '--null --get-regexp' '
a0578e03
LS
1007 git config --null --get-regexp "val[0-9]" >result.raw &&
1008 nul_to_q <result.raw >result &&
5a953fc5
JK
1009 echo >>result &&
1010 test_cmp expect result
1011'
2275d502 1012
ebdaae37
BS
1013test_expect_success 'inner whitespace kept verbatim' '
1014 git config section.val "foo bar" &&
ed838e66
JK
1015 echo "foo bar" >expect &&
1016 git config section.val >actual &&
1017 test_cmp expect actual
ebdaae37
BS
1018'
1019
704a3143 1020test_expect_success SYMLINKS 'symlinked configuration' '
65a5a21d 1021 ln -s notyet myconfig &&
f7e87141 1022 git config --file=myconfig test.frotz nitfol &&
65a5a21d
JH
1023 test -h myconfig &&
1024 test -f notyet &&
f7e87141
JK
1025 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1026 git config --file=myconfig test.xyzzy rezrov &&
65a5a21d
JH
1027 test -h myconfig &&
1028 test -f notyet &&
ed838e66
JK
1029 cat >expect <<-\EOF &&
1030 nitfol
1031 rezrov
1032 EOF
1033 {
f7e87141
JK
1034 git config --file=notyet test.frotz &&
1035 git config --file=notyet test.xyzzy
ed838e66
JK
1036 } >actual &&
1037 test_cmp expect actual
65a5a21d
JH
1038'
1039
1f2baa78 1040test_expect_success 'nonexistent configuration' '
551a3e60
JK
1041 test_must_fail git config --file=doesnotexist --list &&
1042 test_must_fail git config --file=doesnotexist test.xyzzy
1f2baa78
JK
1043'
1044
1045test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1046 ln -s doesnotexist linktonada &&
1047 ln -s linktonada linktolinktonada &&
551a3e60
JK
1048 test_must_fail git config --file=linktonada --list &&
1049 test_must_fail git config --file=linktolinktonada --list
1f2baa78
JK
1050'
1051
dc4179f9
DM
1052test_expect_success 'check split_cmdline return' "
1053 git config alias.split-cmdline-fix 'echo \"' &&
1054 test_must_fail git split-cmdline-fix &&
1055 echo foo > foo &&
1056 git add foo &&
1057 git commit -m 'initial commit' &&
1058 git config branch.master.mergeoptions 'echo \"' &&
1059 test_must_fail git merge master
ed838e66 1060"
dc4179f9 1061
8b1fa778 1062test_expect_success 'git -c "key=value" support' '
ed838e66
JK
1063 cat >expect <<-\EOF &&
1064 value
1065 value
1066 true
1067 EOF
1068 {
1069 git -c core.name=value config core.name &&
1070 git -c foo.CamelCase=value config foo.camelcase &&
1071 git -c foo.flag config --bool foo.flag
1072 } >actual &&
1073 test_cmp expect actual &&
b09c53a3
LP
1074 test_must_fail git -c name=value config core.name
1075'
1076
a789ca70
JH
1077# We just need a type-specifier here that cares about the
1078# distinction internally between a NULL boolean and a real
1079# string (because most of git's internal parsers do care).
1080# Using "--path" works, but we do not otherwise care about
1081# its semantics.
1082test_expect_success 'git -c can represent empty string' '
1083 echo >expect &&
1084 git -c foo.empty= config --path foo.empty >actual &&
1085 test_cmp expect actual
1086'
1087
b09c53a3
LP
1088test_expect_success 'key sanity-checking' '
1089 test_must_fail git config foo=bar &&
1090 test_must_fail git config foo=.bar &&
1091 test_must_fail git config foo.ba=r &&
1092 test_must_fail git config foo.1bar &&
1093 test_must_fail git config foo."ba
1094 z".bar &&
2169ddc0
LP
1095 test_must_fail git config . false &&
1096 test_must_fail git config .foo false &&
1097 test_must_fail git config foo. false &&
1098 test_must_fail git config .foo. false &&
b09c53a3
LP
1099 git config foo.bar true &&
1100 git config foo."ba =z".bar false
8b1fa778
AR
1101'
1102
73546c08 1103test_expect_success 'git -c works with aliases of builtins' '
06eb708f
JK
1104 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1105 echo bar >expect &&
1106 git checkconfig >actual &&
1107 test_cmp expect actual
1108'
1109
643df7e2 1110test_expect_success 'aliases can be CamelCased' '
084b0440
JS
1111 test_config alias.CamelCased "rev-parse HEAD" &&
1112 git CamelCased >out &&
1113 git rev-parse HEAD >expect &&
1114 test_cmp expect out
1115'
1116
5bf6529a
JK
1117test_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
1c2c9bee
JK
1123test_expect_success 'git -c dies on bogus config' '
1124 test_must_fail git -c core.bare=foo rev-parse
1125'
1126
1127test_expect_success 'git -c complains about empty key' '
1128 test_must_fail git -c "=foo" rev-parse
1129'
1130
c5d6350b
JK
1131test_expect_success 'git -c complains about empty key and value' '
1132 test_must_fail git -c "" rev-parse
1133'
1134
d1f88498
JK
1135test_expect_success 'multiple git -c appends config' '
1136 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1137 cat >expect <<-\EOF &&
1138 x.one 1
1139 x.two 2
1140 EOF
1141 git -c x.one=1 x >actual &&
1142 test_cmp expect actual
1143'
1144
1274a155
JH
1145test_expect_success 'last one wins: two level vars' '
1146
1147 # sec.var and sec.VAR are the same variable, as the first
1148 # and the last level of a configuration variable name is
1149 # case insensitive.
1150
1151 echo VAL >expect &&
1152
1153 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1154 test_cmp expect actual &&
1155 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1156 test_cmp expect actual &&
1157
1158 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1159 test_cmp expect actual &&
1160 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1161 test_cmp expect actual
1162'
1163
1164test_expect_success 'last one wins: three level vars' '
1165
1166 # v.a.r and v.A.r are not the same variable, as the middle
1167 # level of a three-level configuration variable name is
1168 # case sensitive.
1169
1170 echo val >expect &&
1171 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1172 test_cmp expect actual &&
1173 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1174 test_cmp expect actual &&
1175
1176 # v.a.r and V.a.R are the same variable, as the first
1177 # and the last level of a configuration variable name is
1178 # case insensitive.
1179
1180 echo VAL >expect &&
1181 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1182 test_cmp expect actual &&
1183 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1184 test_cmp expect actual &&
1185 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1186 test_cmp expect actual &&
1187 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1188 test_cmp expect actual
1189'
1190
1191for VAR in a .a a. a.0b a."b c". a."b c".0d
1192do
1193 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1194 test_must_fail git -c "$VAR=VAL" config -l
1195 '
1196done
1197
1198for VAR in a.b a."b c".d
1199do
1200 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1201 echo VAL >expect &&
1202 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1203 test_cmp expect actual
1204 '
1205done
1206
d1f88498
JK
1207test_expect_success 'git -c is not confused by empty environment' '
1208 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1209'
1210
270a3443
JK
1211test_expect_success 'git config --edit works' '
1212 git config -f tmp test.value no &&
1213 echo test.value=yes >expect &&
1214 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1215 git config -f tmp --list >actual &&
1216 test_cmp expect actual
1217'
1218
1219test_expect_success 'git config --edit respects core.editor' '
1220 git config -f tmp test.value no &&
1221 echo test.value=yes >expect &&
1222 test_config core.editor "echo [test]value=yes >" &&
1223 git config -f tmp --edit &&
1224 git config -f tmp --list >actual &&
1225 test_cmp expect actual
1226'
1227
4b340593
MS
1228# malformed configuration files
1229test_expect_success 'barf on syntax error' '
1230 cat >.git/config <<-\EOF &&
1231 # broken section line
1232 [section]
1233 key garbage
1234 EOF
1235 test_must_fail git config --get section.key >actual 2>error &&
1edbaac3 1236 test_i18ngrep " line 3 " error
4b340593
MS
1237'
1238
1239test_expect_success 'barf on incomplete section header' '
1240 cat >.git/config <<-\EOF &&
1241 # broken section line
1242 [section
1243 key = value
1244 EOF
1245 test_must_fail git config --get section.key >actual 2>error &&
1edbaac3 1246 test_i18ngrep " line 2 " error
4b340593
MS
1247'
1248
1249test_expect_success 'barf on incomplete string' '
1250 cat >.git/config <<-\EOF &&
1251 # broken section line
1252 [section]
1253 key = "value string
1254 EOF
1255 test_must_fail git config --get section.key >actual 2>error &&
1edbaac3 1256 test_i18ngrep " line 3 " error
4b340593
MS
1257'
1258
d4770964
JH
1259test_expect_success 'urlmatch' '
1260 cat >.git/config <<-\EOF &&
1261 [http]
1262 sslVerify
1263 [http "https://weak.example.com"]
1264 sslVerify = false
1265 cookieFile = /tmp/cookie.txt
1266 EOF
1267
27b30be6
JK
1268 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1269 test_must_be_empty actual &&
1270
d4770964
JH
1271 echo true >expect &&
1272 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1273 test_cmp expect actual &&
1274
1275 echo false >expect &&
1276 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1277 test_cmp expect actual &&
1278
1279 {
1280 echo http.cookiefile /tmp/cookie.txt &&
1281 echo http.sslverify false
1282 } >expect &&
1283 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1284 test_cmp expect actual
1285'
1286
af99049c
PS
1287test_expect_success 'urlmatch favors more specific URLs' '
1288 cat >.git/config <<-\EOF &&
1289 [http "https://example.com/"]
1290 cookieFile = /tmp/root.txt
1291 [http "https://example.com/subdirectory"]
1292 cookieFile = /tmp/subdirectory.txt
1293 [http "https://user@example.com/"]
1294 cookieFile = /tmp/user.txt
1295 [http "https://averylonguser@example.com/"]
1296 cookieFile = /tmp/averylonguser.txt
a272b9e7
PS
1297 [http "https://preceding.example.com"]
1298 cookieFile = /tmp/preceding.txt
1299 [http "https://*.example.com"]
1300 cookieFile = /tmp/wildcard.txt
1301 [http "https://*.example.com/wildcardwithsubdomain"]
1302 cookieFile = /tmp/wildcardwithsubdomain.txt
1303 [http "https://trailing.example.com"]
1304 cookieFile = /tmp/trailing.txt
1305 [http "https://user@*.example.com/"]
1306 cookieFile = /tmp/wildcardwithuser.txt
1307 [http "https://sub.example.com/"]
1308 cookieFile = /tmp/sub.txt
af99049c
PS
1309 EOF
1310
1311 echo http.cookiefile /tmp/root.txt >expect &&
1312 git config --get-urlmatch HTTP https://example.com >actual &&
1313 test_cmp expect actual &&
1314
1315 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1316 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1317 test_cmp expect actual &&
1318
1319 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1320 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1321 test_cmp expect actual &&
1322
1323 echo http.cookiefile /tmp/user.txt >expect &&
1324 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1325 test_cmp expect actual &&
1326
1327 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1328 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
a272b9e7
PS
1329 test_cmp expect actual &&
1330
1331 echo http.cookiefile /tmp/preceding.txt >expect &&
1332 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1333 test_cmp expect actual &&
1334
1335 echo http.cookiefile /tmp/wildcard.txt >expect &&
1336 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1337 test_cmp expect actual &&
1338
1339 echo http.cookiefile /tmp/sub.txt >expect &&
1340 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1341 test_cmp expect actual &&
1342
1343 echo http.cookiefile /tmp/trailing.txt >expect &&
1344 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1345 test_cmp expect actual &&
1346
1347 echo http.cookiefile /tmp/sub.txt >expect &&
1348 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1349 test_cmp expect actual
1350'
1351
1352test_expect_success 'urlmatch with wildcard' '
1353 cat >.git/config <<-\EOF &&
1354 [http]
1355 sslVerify
1356 [http "https://*.example.com"]
1357 sslVerify = false
1358 cookieFile = /tmp/cookie.txt
1359 EOF
1360
1361 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1362 test_must_be_empty actual &&
1363
1364 echo true >expect &&
1365 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1366 test_cmp expect actual &&
1367
1368 echo true >expect &&
1369 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1370 test_cmp expect actual &&
1371
1372 echo true >expect &&
1373 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1374 test_cmp expect actual &&
1375
1376 echo false >expect &&
1377 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1378 test_cmp expect actual &&
1379
1380 {
1381 echo http.cookiefile /tmp/cookie.txt &&
1382 echo http.sslverify false
1383 } >expect &&
1384 git config --get-urlmatch HTTP https://good.example.com >actual &&
1385 test_cmp expect actual &&
1386
1387 echo http.sslverify >expect &&
1388 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
af99049c
PS
1389 test_cmp expect actual
1390'
1391
53ca053b 1392# good section hygiene
dde154b5 1393test_expect_failure '--unset last key removes section (except if commented)' '
53ca053b
JK
1394 cat >.git/config <<-\EOF &&
1395 # some generic comment on the configuration file itself
1396 # a comment specific to this "section" section.
1397 [section]
1398 # some intervening lines
1399 # that should also be dropped
1400
1401 key = value
1402 # please be careful when you update the above variable
1403 EOF
1404
1405 cat >expect <<-\EOF &&
1406 # some generic comment on the configuration file itself
dde154b5
JS
1407 # a comment specific to this "section" section.
1408 [section]
1409 # some intervening lines
1410 # that should also be dropped
1411
1412 # please be careful when you update the above variable
1413 EOF
1414
1415 git config --unset section.key &&
1416 test_cmp expect .git/config &&
1417
1418 cat >.git/config <<-\EOF &&
1419 [section]
1420 key = value
1421 [next-section]
1422 EOF
1423
1424 cat >expect <<-\EOF &&
1425 [next-section]
53ca053b
JK
1426 EOF
1427
1428 git config --unset section.key &&
422e8ef2
JS
1429 test_cmp expect .git/config &&
1430
1431 q_to_tab >.git/config <<-\EOF &&
1432 [one]
1433 Qkey = "multiline \
1434 QQ# with comment"
1435 [two]
1436 key = true
1437 EOF
1438 git config --unset two.key &&
1439 ! grep two .git/config &&
1440
1441 q_to_tab >.git/config <<-\EOF &&
1442 [one]
1443 Qkey = "multiline \
1444 QQ# with comment"
1445 [one]
1446 key = true
1447 EOF
1448 git config --unset-all one.key &&
1449 test_line_count = 0 .git/config &&
1450
1451 q_to_tab >.git/config <<-\EOF &&
1452 [one]
1453 Qkey = true
1454 Q# a comment not at the start
1455 [two]
1456 Qkey = true
1457 EOF
1458 git config --unset two.key &&
1459 grep two .git/config &&
1460
1461 q_to_tab >.git/config <<-\EOF &&
1462 [one]
1463 Qkey = not [two "subsection"]
1464 [two "subsection"]
1465 [two "subsection"]
1466 Qkey = true
1467 [TWO "subsection"]
1468 [one]
1469 EOF
1470 git config --unset two.subsection.key &&
1471 test "not [two subsection]" = "$(git config one.key)" &&
1472 test_line_count = 3 .git/config
53ca053b
JK
1473'
1474
1475test_expect_failure 'adding a key into an empty section reuses header' '
1476 cat >.git/config <<-\EOF &&
1477 [section]
1478 EOF
1479
1480 q_to_tab >expect <<-\EOF &&
1481 [section]
1482 Qkey = value
1483 EOF
1484
60687de5 1485 git config section.key value &&
53ca053b
JK
1486 test_cmp expect .git/config
1487'
1488
daa22c6f
EW
1489test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1490 chmod 0600 .git/config &&
1491 git config imap.pass Hunter2 &&
1492 perl -e \
1493 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
1494 git config --rename-section imap pop &&
1495 perl -e \
1496 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1497'
1498
45bf3297
JS
1499! test_have_prereq MINGW ||
1500HOME="$(pwd)" # convert to Windows path
1501
70bd879a
LS
1502test_expect_success 'set up --show-origin tests' '
1503 INCLUDE_DIR="$HOME/include" &&
1504 mkdir -p "$INCLUDE_DIR" &&
1505 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1506 [user]
1507 absolute = include
1508 EOF
1509 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1510 [user]
1511 relative = include
1512 EOF
1513 cat >"$HOME"/.gitconfig <<-EOF &&
1514 [user]
1515 global = true
1516 override = global
1517 [include]
1518 path = "$INCLUDE_DIR/absolute.include"
1519 EOF
1520 cat >.git/config <<-\EOF
1521 [user]
1522 local = true
1523 override = local
1524 [include]
1525 path = ../include/relative.include
1526 EOF
1527'
1528
1529test_expect_success '--show-origin with --list' '
1530 cat >expect <<-EOF &&
1531 file:$HOME/.gitconfig user.global=true
1532 file:$HOME/.gitconfig user.override=global
1533 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1534 file:$INCLUDE_DIR/absolute.include user.absolute=include
1535 file:.git/config user.local=true
1536 file:.git/config user.override=local
1537 file:.git/config include.path=../include/relative.include
1538 file:.git/../include/relative.include user.relative=include
1539 command line: user.cmdline=true
1540 EOF
1541 git -c user.cmdline=true config --list --show-origin >output &&
1542 test_cmp expect output
1543'
1544
1545test_expect_success '--show-origin with --list --null' '
1546 cat >expect <<-EOF &&
1547 file:$HOME/.gitconfigQuser.global
1548 trueQfile:$HOME/.gitconfigQuser.override
1549 globalQfile:$HOME/.gitconfigQinclude.path
1550 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1551 includeQfile:.git/configQuser.local
1552 trueQfile:.git/configQuser.override
1553 localQfile:.git/configQinclude.path
1554 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1555 includeQcommand line:Quser.cmdline
1556 trueQ
1557 EOF
1558 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1559 nul_to_q <output.raw >output &&
1560 # The here-doc above adds a newline that the --null output would not
1561 # include. Add it here to make the two comparable.
1562 echo >>output &&
1563 test_cmp expect output
1564'
1565
1566test_expect_success '--show-origin with single file' '
1567 cat >expect <<-\EOF &&
1568 file:.git/config user.local=true
1569 file:.git/config user.override=local
1570 file:.git/config include.path=../include/relative.include
1571 EOF
1572 git config --local --list --show-origin >output &&
1573 test_cmp expect output
1574'
1575
1576test_expect_success '--show-origin with --get-regexp' '
1577 cat >expect <<-EOF &&
1578 file:$HOME/.gitconfig user.global true
1579 file:.git/config user.local true
1580 EOF
1581 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1582 test_cmp expect output
1583'
1584
1585test_expect_success '--show-origin getting a single key' '
1586 cat >expect <<-\EOF &&
1587 file:.git/config local
1588 EOF
1589 git config --show-origin user.override >output &&
1590 test_cmp expect output
1591'
1592
1593test_expect_success 'set up custom config file' '
1594 CUSTOM_CONFIG_FILE="file\" (dq) and spaces.conf" &&
1595 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1596 [user]
1597 custom = true
1598 EOF
1599'
1600
45bf3297 1601test_expect_success !MINGW '--show-origin escape special file name characters' '
70bd879a
LS
1602 cat >expect <<-\EOF &&
1603 file:"file\" (dq) and spaces.conf" user.custom=true
1604 EOF
1605 git config --file "$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1606 test_cmp expect output
1607'
1608
1609test_expect_success '--show-origin stdin' '
1610 cat >expect <<-\EOF &&
1611 standard input: user.custom=true
1612 EOF
1613 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1614 test_cmp expect output
1615'
1616
1617test_expect_success '--show-origin stdin with file include' '
1618 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1619 [user]
1620 stdin = include
1621 EOF
1622 cat >expect <<-EOF &&
1623 file:$INCLUDE_DIR/stdin.include include
1624 EOF
1625 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" \
1626 | git config --show-origin --includes --file - user.stdin >output &&
1627 test_cmp expect output
1628'
1629
45bf3297 1630test_expect_success !MINGW '--show-origin blob' '
70bd879a
LS
1631 cat >expect <<-\EOF &&
1632 blob:a9d9f9e555b5c6f07cbe09d3f06fe3df11e09c08 user.custom=true
1633 EOF
1634 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1635 git config --blob=$blob --show-origin --list >output &&
1636 test_cmp expect output
1637'
1638
45bf3297 1639test_expect_success !MINGW '--show-origin blob ref' '
70bd879a
LS
1640 cat >expect <<-\EOF &&
1641 blob:"master:file\" (dq) and spaces.conf" user.custom=true
1642 EOF
1643 git add "$CUSTOM_CONFIG_FILE" &&
1644 git commit -m "new config file" &&
1645 git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1646 test_cmp expect output
1647'
1648
25cd2919 1649test_expect_success '--local requires a repo' '
588a538a
JK
1650 # we expect 128 to ensure that we do not simply
1651 # fail to find anything and return code "1"
1652 test_expect_code 128 nongit git config --local foo.bar
1653'
1654
46fc89ce 1655test_expect_success '--replace-all does not invent newlines' '
e9313952
JS
1656 q_to_tab >.git/config <<-\EOF &&
1657 [abc]key
1658 QkeepSection
1659 [xyz]
1660 Qkey = 1
1661 [abc]
1662 Qkey = a
1663 EOF
1664 q_to_tab >expect <<-\EOF &&
1665 [abc]
1666 QkeepSection
1667 [xyz]
1668 Qkey = 1
1669 [abc]
1670 Qkey = b
1671 EOF
1672 git config --replace-all abc.key b &&
1673 test_cmp .git/config expect
1674'
1675
942c1f53 1676test_done