]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1300-config.sh
t1300: add more tests for whitespace and inline comments
[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 7
06d53148 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
67606301 11TEST_PASSES_SANITIZE_LEAK=true
942c1f53
JS
12. ./test-lib.sh
13
d71bc1b4
DS
14test_expect_success 'setup whitespace config' '
15 sed -e "s/^|//" \
16 -e "s/[$]$//" \
17 -e "s/X/ /g" >.git/config <<-\EOF
18 [section]
19 | solid = rock
20 | sparse = big XX blue
21 | sparseAndTail = big XX blue $
22 | sparseAndTailQuoted = "big XX blue "
23 | sparseAndBiggerTail = big XX blue X X
24 | sparseAndBiggerTailQuoted = "big XX blue X X"
25 | sparseAndBiggerTailQuotedPlus = "big XX blue X X"X $
26 | headAndTail = Xbig blue $
27 | headAndTailQuoted = "Xbig blue "
28 | headAndTailQuotedPlus = "Xbig blue " $
29 | annotated = big blueX# to be discarded
30 | annotatedQuoted = "big blue"X# to be discarded
31 EOF
32'
33
34test_expect_success 'no internal whitespace' '
35 echo "rock" >expect &&
36 git config --get section.solid >actual &&
37 test_cmp expect actual
38'
39
40test_expect_success 'internal whitespace' '
41 echo "big QQ blue" | q_to_tab >expect &&
42 git config --get section.sparse >actual &&
43 test_cmp expect actual
44'
45
46test_expect_success 'internal and trailing whitespace' '
47 echo "big QQ blue" | q_to_tab >expect &&
48 git config --get section.sparseAndTail >actual &&
49 test_cmp expect actual
50'
51
52test_expect_success 'internal and trailing whitespace, all quoted' '
53 echo "big QQ blue " | q_to_tab >expect &&
54 git config --get section.sparseAndTailQuoted >actual &&
55 test_cmp expect actual
56'
57
58test_expect_success 'internal and more trailing whitespace' '
59 echo "big QQ blue" | q_to_tab >expect &&
60 git config --get section.sparseAndBiggerTail >actual &&
61 test_cmp expect actual
62'
63
64test_expect_success 'internal and more trailing whitespace, all quoted' '
65 echo "big QQ blue Q Q" | q_to_tab >expect &&
66 git config --get section.sparseAndBiggerTailQuoted >actual &&
67 test_cmp expect actual
68'
69
70test_expect_success 'internal and more trailing whitespace, not all quoted' '
71 echo "big QQ blue Q Q" | q_to_tab >expect &&
72 git config --get section.sparseAndBiggerTailQuotedPlus >actual &&
73 test_cmp expect actual
74'
75
76test_expect_success 'leading and trailing whitespace' '
77 echo "big blue" >expect &&
78 git config --get section.headAndTail >actual &&
79 test_cmp expect actual
80'
81
82test_expect_success 'leading and trailing whitespace, all quoted' '
83 echo "Qbig blue " | q_to_tab >expect &&
84 git config --get section.headAndTailQuoted >actual &&
85 test_cmp expect actual
86'
87
88test_expect_success 'leading and trailing whitespace, not all quoted' '
89 echo "Qbig blue " | q_to_tab >expect &&
90 git config --get section.headAndTailQuotedPlus >actual &&
91 test_cmp expect actual
92'
93
94test_expect_success 'inline comment' '
95 echo "big blue" >expect &&
96 git config --get section.annotated >actual &&
97 test_cmp expect actual
98'
99
100test_expect_success 'inline comment, quoted' '
101 echo "big blue" >expect &&
102 git config --get section.annotatedQuoted >actual &&
103 test_cmp expect actual
104'
105
5a953fc5
JK
106test_expect_success 'clear default config' '
107 rm -f .git/config
108'
942c1f53
JS
109
110cat > expect << EOF
04f6b0a1 111[section]
942c1f53
JS
112 penguin = little blue
113EOF
5a953fc5 114test_expect_success 'initial' '
04f6b0a1 115 git config section.penguin "little blue" &&
5a953fc5
JK
116 test_cmp expect .git/config
117'
942c1f53
JS
118
119cat > expect << EOF
04f6b0a1 120[section]
942c1f53
JS
121 penguin = little blue
122 Movie = BadPhysics
123EOF
5a953fc5 124test_expect_success 'mixed case' '
04f6b0a1 125 git config Section.Movie BadPhysics &&
5a953fc5
JK
126 test_cmp expect .git/config
127'
942c1f53
JS
128
129cat > expect << EOF
04f6b0a1 130[section]
942c1f53
JS
131 penguin = little blue
132 Movie = BadPhysics
04f6b0a1 133[Sections]
942c1f53
JS
134 WhatEver = Second
135EOF
5a953fc5 136test_expect_success 'similar section' '
04f6b0a1 137 git config Sections.WhatEver Second &&
5a953fc5
JK
138 test_cmp expect .git/config
139'
942c1f53
JS
140
141cat > expect << EOF
04f6b0a1 142[section]
942c1f53
JS
143 penguin = little blue
144 Movie = BadPhysics
145 UPPERCASE = true
04f6b0a1 146[Sections]
942c1f53
JS
147 WhatEver = Second
148EOF
5a953fc5 149test_expect_success 'uppercase section' '
04f6b0a1 150 git config SECTION.UPPERCASE true &&
5a953fc5
JK
151 test_cmp expect .git/config
152'
942c1f53 153
ed838e66 154test_expect_success 'replace with non-match' '
04f6b0a1 155 git config section.penguin kingpin !blue
ed838e66 156'
f98d863d 157
ed838e66 158test_expect_success 'replace with non-match (actually matching)' '
04f6b0a1 159 git config section.penguin "very blue" !kingpin
ed838e66 160'
f98d863d
JS
161
162cat > expect << EOF
04f6b0a1 163[section]
f98d863d
JS
164 penguin = very blue
165 Movie = BadPhysics
166 UPPERCASE = true
167 penguin = kingpin
04f6b0a1 168[Sections]
f98d863d
JS
169 WhatEver = Second
170EOF
171
5a953fc5 172test_expect_success 'non-match result' 'test_cmp expect .git/config'
f98d863d 173
88d42af8 174test_expect_success 'find mixed-case key by canonical name' '
04f6b0a1 175 test_cmp_config Second sections.whatever
88d42af8
JK
176'
177
178test_expect_success 'find mixed-case key by non-canonical name' '
04f6b0a1 179 test_cmp_config Second SeCtIoNs.WhAtEvEr
88d42af8
JK
180'
181
182test_expect_success 'subsections are not canonicalized by git-config' '
183 cat >>.git/config <<-\EOF &&
184 [section.SubSection]
185 key = one
186 [section "SubSection"]
187 key = two
188 EOF
a5db0b77
NTND
189 test_cmp_config one section.subsection.key &&
190 test_cmp_config two section.SubSection.key
88d42af8 191'
f98d863d 192
3d77fbb6
AR
193test_missing_key () {
194 local key="$1" &&
195 local title="$2" &&
196 test_expect_success "value for $title is not printed" '
197 test_must_fail git config "$key" >out 2>err &&
198 test_must_be_empty out &&
199 test_must_be_empty err
200 '
201}
202
203test_missing_key 'missingsection.missingkey' 'missing section and missing key'
204test_missing_key 'missingsection.penguin' 'missing section and existing key'
205test_missing_key 'section.missingkey' 'existing section and missing key'
206test_missing_key 'section.MissingSubSection.missingkey' 'missing subsection and missing key'
207test_missing_key 'section.SubSection.missingkey' 'existing subsection and missing key'
208test_missing_key 'section.MissingSubSection.key' 'missing subsection and existing key'
209
7a31cc0f
FL
210cat > .git/config <<\EOF
211[alpha]
212bar = foo
213[beta]
214baz = multiple \
215lines
85bf5d61 216foo = bar
7a31cc0f
FL
217EOF
218
ed838e66
JK
219test_expect_success 'unset with cont. lines' '
220 git config --unset beta.baz
221'
7a31cc0f
FL
222
223cat > expect <<\EOF
224[alpha]
225bar = foo
226[beta]
85bf5d61 227foo = bar
7a31cc0f
FL
228EOF
229
5a953fc5 230test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
7a31cc0f 231
942c1f53
JS
232cat > .git/config << EOF
233[beta] ; silly comment # another comment
234noIndent= sillyValue ; 'nother silly comment
235
236# empty line
237 ; comment
238 haha ="beta" # last silly comment
4ddba79d
JS
239haha = hello
240 haha = bello
942c1f53
JS
241[nextSection] noNewline = ouch
242EOF
243
4ddba79d
JS
244cp .git/config .git/config2
245
ed838e66
JK
246test_expect_success 'multiple unset' '
247 git config --unset-all beta.haha
248'
4ddba79d
JS
249
250cat > expect << EOF
251[beta] ; silly comment # another comment
252noIndent= sillyValue ; 'nother silly comment
253
254# empty line
255 ; comment
256[nextSection] noNewline = ouch
257EOF
258
ed838e66
JK
259test_expect_success 'multiple unset is correct' '
260 test_cmp expect .git/config
261'
4ddba79d 262
bf71b4b3
CR
263cp .git/config2 .git/config
264
265test_expect_success '--replace-all missing value' '
266 test_must_fail git config --replace-all beta.haha &&
267 test_cmp .git/config2 .git/config
268'
269
270rm .git/config2
4ddba79d 271
ed838e66
JK
272test_expect_success '--replace-all' '
273 git config --replace-all beta.haha gamma
274'
4ddba79d
JS
275
276cat > expect << EOF
277[beta] ; silly comment # another comment
278noIndent= sillyValue ; 'nother silly comment
279
280# empty line
281 ; comment
282 haha = gamma
283[nextSection] noNewline = ouch
284EOF
285
ed838e66
JK
286test_expect_success 'all replaced' '
287 test_cmp expect .git/config
288'
942c1f53
JS
289
290cat > expect << EOF
291[beta] ; silly comment # another comment
292noIndent= sillyValue ; 'nother silly comment
293
294# empty line
295 ; comment
296 haha = alpha
297[nextSection] noNewline = ouch
298EOF
5a953fc5
JK
299test_expect_success 'really mean test' '
300 git config beta.haha alpha &&
301 test_cmp expect .git/config
302'
942c1f53
JS
303
304cat > expect << EOF
305[beta] ; silly comment # another comment
306noIndent= sillyValue ; 'nother silly comment
307
308# empty line
309 ; comment
310 haha = alpha
311[nextSection]
312 nonewline = wow
313EOF
5a953fc5
JK
314test_expect_success 'really really mean test' '
315 git config nextsection.nonewline wow &&
316 test_cmp expect .git/config
317'
942c1f53 318
ed838e66 319test_expect_success 'get value' '
a5db0b77 320 test_cmp_config alpha beta.haha
ed838e66 321'
942c1f53
JS
322
323cat > expect << EOF
324[beta] ; silly comment # another comment
325noIndent= sillyValue ; 'nother silly comment
326
327# empty line
328 ; comment
329[nextSection]
330 nonewline = wow
331EOF
5a953fc5
JK
332test_expect_success 'unset' '
333 git config --unset beta.haha &&
334 test_cmp expect .git/config
335'
942c1f53
JS
336
337cat > expect << EOF
338[beta] ; silly comment # another comment
339noIndent= sillyValue ; 'nother silly comment
340
341# empty line
342 ; comment
343[nextSection]
344 nonewline = wow
345 NoNewLine = wow2 for me
346EOF
5a953fc5
JK
347test_expect_success 'multivar' '
348 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
349 test_cmp expect .git/config
350'
942c1f53 351
ed838e66
JK
352test_expect_success 'non-match' '
353 git config --get nextsection.nonewline !for
354'
f98d863d 355
ed838e66 356test_expect_success 'non-match value' '
a5db0b77 357 test_cmp_config wow --get nextsection.nonewline !for
ed838e66 358'
f98d863d 359
00b347d3 360test_expect_success 'multi-valued get returns final one' '
a5db0b77 361 test_cmp_config "wow2 for me" --get nextsection.nonewline
41ac414e 362'
4ddba79d 363
cb20b691
JK
364test_expect_success 'multi-valued get-all returns all' '
365 cat >expect <<-\EOF &&
366 wow
367 wow2 for me
368 EOF
369 git config --get-all nextsection.nonewline >actual &&
370 test_cmp expect actual
ed838e66 371'
4ddba79d 372
942c1f53
JS
373cat > expect << EOF
374[beta] ; silly comment # another comment
375noIndent= sillyValue ; 'nother silly comment
376
377# empty line
378 ; comment
379[nextSection]
380 nonewline = wow3
381 NoNewLine = wow2 for me
382EOF
5a953fc5
JK
383test_expect_success 'multivar replace' '
384 git config nextsection.nonewline "wow3" "wow$" &&
385 test_cmp expect .git/config
386'
942c1f53 387
41ac414e 388test_expect_success 'ambiguous unset' '
d492b31c 389 test_must_fail git config --unset nextsection.nonewline
41ac414e 390'
942c1f53 391
41ac414e 392test_expect_success 'invalid unset' '
d492b31c 393 test_must_fail git config --unset somesection.nonewline
41ac414e 394'
942c1f53 395
942c1f53
JS
396cat > expect << EOF
397[beta] ; silly comment # another comment
398noIndent= sillyValue ; 'nother silly comment
399
400# empty line
401 ; comment
402[nextSection]
403 NoNewLine = wow2 for me
404EOF
405
5a953fc5
JK
406test_expect_success 'multivar unset' '
407 git config --unset nextsection.nonewline "wow3$" &&
408 test_cmp expect .git/config
409'
942c1f53 410
d492b31c 411test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
942c1f53 412
5be60078 413test_expect_success 'correct key' 'git config 123456.a123 987'
942c1f53 414
ed838e66
JK
415test_expect_success 'hierarchical section' '
416 git config Version.1.2.3eX.Alpha beta
417'
b17e659d
JS
418
419cat > expect << EOF
420[beta] ; silly comment # another comment
421noIndent= sillyValue ; 'nother silly comment
422
423# empty line
424 ; comment
425[nextSection]
426 NoNewLine = wow2 for me
427[123456]
428 a123 = 987
d14f7764
LT
429[Version "1.2.3eX"]
430 Alpha = beta
b17e659d
JS
431EOF
432
ed838e66
JK
433test_expect_success 'hierarchical section value' '
434 test_cmp expect .git/config
435'
b17e659d 436
2fa9a0fb
JS
437cat > expect << EOF
438beta.noindent=sillyValue
439nextsection.nonewline=wow2 for me
440123456.a123=987
d55aaefa 441version.1.2.3eX.alpha=beta
2fa9a0fb
JS
442EOF
443
ed838e66
JK
444test_expect_success 'working --list' '
445 git config --list > output &&
446 test_cmp expect output
447'
1f2baa78
JK
448test_expect_success '--list without repo produces empty output' '
449 git --git-dir=nonexistent config --list >output &&
1c5e94f4 450 test_must_be_empty output
1f2baa78
JK
451'
452
578625fa
SG
453cat > expect << EOF
454beta.noindent
455nextsection.nonewline
456123456.a123
457version.1.2.3eX.alpha
458EOF
459
460test_expect_success '--name-only --list' '
461 git config --name-only --list >output &&
462 test_cmp expect output
463'
464
2fa9a0fb
JS
465cat > expect << EOF
466beta.noindent sillyValue
467nextsection.nonewline wow2 for me
468EOF
469
ed838e66
JK
470test_expect_success '--get-regexp' '
471 git config --get-regexp in >output &&
472 test_cmp expect output
473'
2fa9a0fb 474
578625fa
SG
475cat > expect << EOF
476beta.noindent
477nextsection.nonewline
478EOF
479
480test_expect_success '--name-only --get-regexp' '
481 git config --name-only --get-regexp in >output &&
482 test_cmp expect output
483'
484
89c4afe0
BG
485cat > expect << EOF
486wow2 for me
487wow4 for you
488EOF
489
5a953fc5
JK
490test_expect_success '--add' '
491 git config --add nextsection.nonewline "wow4 for you" &&
492 git config --get-all nextsection.nonewline > output &&
493 test_cmp expect output
494'
89c4afe0 495
f067a137
JF
496cat > .git/config << EOF
497[novalue]
498 variable
09bc098c
CC
499[emptyvalue]
500 variable =
f067a137
JF
501EOF
502
ed838e66
JK
503test_expect_success 'get variable with no value' '
504 git config --get novalue.variable ^$
505'
f067a137 506
ed838e66
JK
507test_expect_success 'get variable with empty value' '
508 git config --get emptyvalue.variable ^$
509'
09bc098c 510
b69ba460
FL
511echo novalue.variable > expect
512
ed838e66
JK
513test_expect_success 'get-regexp variable with no value' '
514 git config --get-regexp novalue > output &&
515 test_cmp expect output
516'
b69ba460 517
008e3cc5
MM
518echo 'novalue.variable true' > expect
519
ed838e66
JK
520test_expect_success 'get-regexp --bool variable with no value' '
521 git config --bool --get-regexp novalue > output &&
522 test_cmp expect output
523'
008e3cc5 524
09bc098c
CC
525echo 'emptyvalue.variable ' > expect
526
ed838e66
JK
527test_expect_success 'get-regexp variable with empty value' '
528 git config --get-regexp emptyvalue > output &&
529 test_cmp expect output
530'
09bc098c
CC
531
532echo true > expect
533
ed838e66
JK
534test_expect_success 'get bool variable with no value' '
535 git config --bool novalue.variable > output &&
536 test_cmp expect output
537'
09bc098c
CC
538
539echo false > expect
540
ed838e66
JK
541test_expect_success 'get bool variable with empty value' '
542 git config --bool emptyvalue.variable > output &&
543 test_cmp expect output
544'
09bc098c 545
003f69b2
JK
546test_expect_success 'no arguments, but no crash' '
547 test_must_fail git config >output 2>&1 &&
9a001381 548 test_i18ngrep usage output
003f69b2 549'
2fa9a0fb 550
bd886fd3
SE
551cat > .git/config << EOF
552[a.b]
553 c = d
554EOF
555
bd886fd3
SE
556cat > expect << EOF
557[a.b]
558 c = d
559[a]
560 x = y
561EOF
562
5a953fc5
JK
563test_expect_success 'new section is partial match of another' '
564 git config a.x y &&
565 test_cmp expect .git/config
566'
bd886fd3
SE
567
568cat > expect << EOF
569[a.b]
570 c = d
571[a]
572 x = y
573 b = c
574[b]
575 x = y
576EOF
577
5a953fc5
JK
578test_expect_success 'new variable inserts into proper section' '
579 git config b.x y &&
580 git config a.b c &&
581 test_cmp expect .git/config
582'
bd886fd3 583
f7e87141 584test_expect_success 'alternative --file (non-existing file should fail)' '
34479d71
585 test_must_fail git config --file non-existing-config -l &&
586 test_must_fail git config --file non-existing-config test.xyzzy
ed838e66 587'
773a69fb 588
9c3796fc
JS
589cat > other-config << EOF
590[ein]
591 bahn = strasse
592EOF
593
594cat > expect << EOF
595ein.bahn=strasse
596EOF
597
5a953fc5 598test_expect_success 'alternative GIT_CONFIG' '
3caec73b 599 GIT_CONFIG=other-config git config --list >output &&
5a953fc5
JK
600 test_cmp expect output
601'
9c3796fc 602
ed838e66 603test_expect_success 'alternative GIT_CONFIG (--file)' '
3caec73b 604 git config --file other-config --list >output &&
ed838e66
JK
605 test_cmp expect output
606'
773a69fb 607
3caec73b
KS
608test_expect_success 'alternative GIT_CONFIG (--file=-)' '
609 git config --file - --list <other-config >output &&
610 test_cmp expect output
611'
612
613test_expect_success 'setting a value in stdin is an error' '
614 test_must_fail git config --file - some.value foo
615'
616
617test_expect_success 'editing stdin is an error' '
618 test_must_fail git config --file - --edit
619'
620
65807ee6
JH
621test_expect_success 'refer config from subdirectory' '
622 mkdir x &&
a5db0b77 623 test_cmp_config -C x strasse --file=../other-config --get ein.bahn
270a3443
JK
624'
625
9c3796fc
JS
626cat > expect << EOF
627[ein]
628 bahn = strasse
629[anwohner]
630 park = ausweis
631EOF
632
f7e87141
JK
633test_expect_success '--set in alternative file' '
634 git config --file=other-config anwohner.park ausweis &&
5a953fc5
JK
635 test_cmp expect other-config
636'
9c3796fc 637
0667fcfb
JS
638cat > .git/config << EOF
639# Hallo
640 #Bello
641[branch "eins"]
642 x = 1
643[branch.eins]
644 y = 1
645 [branch "1 234 blabl/a"]
646weird
647EOF
648
ed838e66
JK
649test_expect_success 'rename section' '
650 git config --rename-section branch.eins branch.zwei
651'
0667fcfb
JS
652
653cat > expect << EOF
654# Hallo
655 #Bello
656[branch "zwei"]
657 x = 1
658[branch "zwei"]
659 y = 1
660 [branch "1 234 blabl/a"]
661weird
662EOF
663
ed838e66
JK
664test_expect_success 'rename succeeded' '
665 test_cmp expect .git/config
666'
0667fcfb 667
ed838e66 668test_expect_success 'rename non-existing section' '
d492b31c
SB
669 test_must_fail git config --rename-section \
670 branch."world domination" branch.drei
41ac414e 671'
0667fcfb 672
ed838e66
JK
673test_expect_success 'rename succeeded' '
674 test_cmp expect .git/config
675'
0667fcfb 676
ed838e66
JK
677test_expect_success 'rename another section' '
678 git config --rename-section branch."1 234 blabl/a" branch.drei
679'
0667fcfb
JS
680
681cat > expect << EOF
682# Hallo
683 #Bello
684[branch "zwei"]
685 x = 1
686[branch "zwei"]
687 y = 1
688[branch "drei"]
689weird
690EOF
691
ed838e66
JK
692test_expect_success 'rename succeeded' '
693 test_cmp expect .git/config
694'
9a5abfc7
AV
695
696cat >> .git/config << EOF
697[branch "vier"] z = 1
698EOF
699
ed838e66
JK
700test_expect_success 'rename a section with a var on the same line' '
701 git config --rename-section branch.vier branch.zwei
702'
9a5abfc7
AV
703
704cat > expect << EOF
705# Hallo
706 #Bello
707[branch "zwei"]
708 x = 1
709[branch "zwei"]
710 y = 1
711[branch "drei"]
712weird
713[branch "zwei"]
714 z = 1
715EOF
716
ed838e66
JK
717test_expect_success 'rename succeeded' '
718 test_cmp expect .git/config
719'
0667fcfb 720
94a35b1a
JK
721test_expect_success 'renaming empty section name is rejected' '
722 test_must_fail git config --rename-section branch.zwei ""
723'
724
725test_expect_success 'renaming to bogus section is rejected' '
726 test_must_fail git config --rename-section branch.zwei "bogus name"
727'
728
a5bb10fd 729test_expect_success 'renaming a section with a long line' '
29198213
TB
730 {
731 printf "[b]\\n" &&
732 printf " c = d %1024s [a] e = f\\n" " " &&
733 printf "[a] g = h\\n"
734 } >y &&
735 git config -f y --rename-section a xyz &&
736 test_must_fail git config -f y b.e
737'
738
a5bb10fd 739test_expect_success 'renaming an embedded section with a long line' '
29198213
TB
740 {
741 printf "[b]\\n" &&
742 printf " c = d %1024s [a] [foo] e = f\\n" " " &&
743 printf "[a] g = h\\n"
744 } >y &&
745 git config -f y --rename-section a xyz &&
746 test_must_fail git config -f y foo.e
747'
748
3bb3d6ba
TB
749test_expect_success 'renaming a section with an overly-long line' '
750 {
751 printf "[b]\\n" &&
752 printf " c = d %525000s e" " " &&
753 printf "[a] g = h\\n"
754 } >y &&
755 test_must_fail git config -f y --rename-section a xyz 2>err &&
b524e896 756 grep "refusing to work with overly long line in .y. on line 2" err
3bb3d6ba
TB
757'
758
118f8b24
PB
759cat >> .git/config << EOF
760 [branch "zwei"] a = 1 [branch "vier"]
761EOF
762
ed838e66
JK
763test_expect_success 'remove section' '
764 git config --remove-section branch.zwei
765'
118f8b24
PB
766
767cat > expect << EOF
768# Hallo
769 #Bello
770[branch "drei"]
771weird
772EOF
773
ed838e66
JK
774test_expect_success 'section was removed properly' '
775 test_cmp expect .git/config
776'
118f8b24 777
b18a2be3
SP
778cat > expect << EOF
779[gitcvs]
780 enabled = true
781 dbname = %Ggitcvs2.%a.%m.sqlite
782[gitcvs "ext"]
783 dbname = %Ggitcvs1.%a.%m.sqlite
784EOF
785
786test_expect_success 'section ending' '
795290e5 787 rm -f .git/config &&
5be60078
JH
788 git config gitcvs.enabled true &&
789 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
790 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
5a953fc5 791 test_cmp expect .git/config
b18a2be3
SP
792
793'
794
d77a64d3 795test_expect_success numbers '
5be60078
JH
796 git config kilo.gram 1k &&
797 git config mega.ton 1m &&
ed838e66
JK
798 echo 1024 >expect &&
799 echo 1048576 >>expect &&
800 git config --int --get kilo.gram >actual &&
801 git config --int --get mega.ton >>actual &&
802 test_cmp expect actual
d77a64d3
SP
803'
804
00160242
JK
805test_expect_success '--int is at least 64 bits' '
806 git config giga.watts 121g &&
a5db0b77
NTND
807 echo >expect &&
808 test_cmp_config 129922760704 --int --get giga.watts
00160242
JK
809'
810
c8deb5a1 811test_expect_success 'invalid unit' '
c8deb5a1 812 git config aninvalid.unit "1auto" &&
a5db0b77 813 test_cmp_config 1auto aninvalid.unit &&
ed838e66 814 test_must_fail git config --int --get aninvalid.unit 2>actual &&
2ec20212 815 test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
c8deb5a1
SP
816'
817
f276e2a4
AK
818test_expect_success 'invalid unit boolean' '
819 git config commit.gpgsign "1true" &&
820 test_cmp_config 1true commit.gpgsign &&
821 test_must_fail git config --bool --get commit.gpgsign 2>actual &&
822 test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
823'
824
e2e14251
JS
825test_expect_success 'line number is reported correctly' '
826 printf "[bool]\n\tvar\n" >invalid &&
827 test_must_fail git config -f invalid --path bool.var 2>actual &&
828 test_i18ngrep "line 2" actual
829'
830
473166b9 831test_expect_success 'invalid stdin config' '
473166b9 832 echo "[broken" | test_must_fail git config --list --file - >output 2>&1 &&
2ec20212 833 test_i18ngrep "bad config line 1 in standard input" output
473166b9
LS
834'
835
cab333cb
FL
836cat > expect << EOF
837true
838false
839true
840false
841true
842false
843true
844false
845EOF
846
847test_expect_success bool '
848
5be60078
JH
849 git config bool.true1 01 &&
850 git config bool.true2 -1 &&
851 git config bool.true3 YeS &&
852 git config bool.true4 true &&
853 git config bool.false1 000 &&
854 git config bool.false2 "" &&
855 git config bool.false3 nO &&
856 git config bool.false4 FALSE &&
cab333cb
FL
857 rm -f result &&
858 for i in 1 2 3 4
859 do
74d2f569 860 git config --bool --get bool.true$i >>result &&
db5875aa 861 git config --bool --get bool.false$i >>result || return 1
e3e042b1 862 done &&
ed838e66 863 test_cmp expect result'
cab333cb 864
41ac414e 865test_expect_success 'invalid bool (--get)' '
cab333cb 866
5be60078 867 git config bool.nobool foobar &&
d492b31c 868 test_must_fail git config --bool --get bool.nobool'
cab333cb 869
41ac414e 870test_expect_success 'invalid bool (set)' '
db1696b8 871
d492b31c 872 test_must_fail git config --bool bool.nobool foobar'
db1696b8 873
db1696b8
FL
874cat > expect <<\EOF
875[bool]
876 true1 = true
877 true2 = true
878 true3 = true
879 true4 = true
880 false1 = false
881 false2 = false
882 false3 = false
883 false4 = false
884EOF
885
886test_expect_success 'set --bool' '
887
795290e5 888 rm -f .git/config &&
5be60078
JH
889 git config --bool bool.true1 01 &&
890 git config --bool bool.true2 -1 &&
891 git config --bool bool.true3 YeS &&
892 git config --bool bool.true4 true &&
893 git config --bool bool.false1 000 &&
894 git config --bool bool.false2 "" &&
895 git config --bool bool.false3 nO &&
896 git config --bool bool.false4 FALSE &&
ed838e66 897 test_cmp expect .git/config'
db1696b8 898
db1696b8
FL
899cat > expect <<\EOF
900[int]
901 val1 = 1
902 val2 = -1
903 val3 = 5242880
904EOF
905
906test_expect_success 'set --int' '
907
795290e5 908 rm -f .git/config &&
5be60078
JH
909 git config --int int.val1 01 &&
910 git config --int int.val2 -1 &&
911 git config --int int.val3 5m &&
ed838e66
JK
912 test_cmp expect .git/config
913'
db1696b8 914
ed838e66
JK
915test_expect_success 'get --bool-or-int' '
916 cat >.git/config <<-\EOF &&
917 [bool]
918 true1
c35b0b58 919 true2 = true
ed838e66
JK
920 false = false
921 [int]
c35b0b58
JH
922 int1 = 0
923 int2 = 1
924 int3 = -1
ed838e66
JK
925 EOF
926 cat >expect <<-\EOF &&
927 true
928 true
929 false
930 0
931 1
932 -1
933 EOF
934 {
935 git config --bool-or-int bool.true1 &&
936 git config --bool-or-int bool.true2 &&
937 git config --bool-or-int bool.false &&
938 git config --bool-or-int int.int1 &&
939 git config --bool-or-int int.int2 &&
940 git config --bool-or-int int.int3
941 } >actual &&
942 test_cmp expect actual
c35b0b58
JH
943'
944
c35b0b58
JH
945cat >expect <<\EOF
946[bool]
947 true1 = true
948 false1 = false
949 true2 = true
950 false2 = false
951[int]
952 int1 = 0
953 int2 = 1
954 int3 = -1
955EOF
956
957test_expect_success 'set --bool-or-int' '
795290e5 958 rm -f .git/config &&
c35b0b58
JH
959 git config --bool-or-int bool.true1 true &&
960 git config --bool-or-int bool.false1 false &&
961 git config --bool-or-int bool.true2 yes &&
962 git config --bool-or-int bool.false2 no &&
963 git config --bool-or-int int.int1 0 &&
964 git config --bool-or-int int.int2 1 &&
965 git config --bool-or-int int.int3 -1 &&
966 test_cmp expect .git/config
967'
968
1349484e
MM
969cat >expect <<\EOF
970[path]
971 home = ~/
972 normal = /dev/null
973 trailingtilde = foo~
974EOF
975
f57a8715 976test_expect_success !MINGW 'set --path' '
795290e5 977 rm -f .git/config &&
1349484e
MM
978 git config --path path.home "~/" &&
979 git config --path path.normal "/dev/null" &&
980 git config --path path.trailingtilde "foo~" &&
981 test_cmp expect .git/config'
982
f57a8715 983if test_have_prereq !MINGW && test "${HOME+set}"
79bf1490
JN
984then
985 test_set_prereq HOMEVAR
986fi
987
1349484e
MM
988cat >expect <<EOF
989$HOME/
990/dev/null
991foo~
992EOF
993
79bf1490 994test_expect_success HOMEVAR 'get --path' '
1349484e
MM
995 git config --get --path path.home > result &&
996 git config --get --path path.normal >> result &&
997 git config --get --path path.trailingtilde >> result &&
998 test_cmp expect result
999'
1000
79bf1490
JN
1001cat >expect <<\EOF
1002/dev/null
1003foo~
1004EOF
1005
f57a8715 1006test_expect_success !MINGW 'get --path copes with unset $HOME' '
79bf1490 1007 (
ed6c994a 1008 sane_unset HOME &&
79bf1490
JN
1009 test_must_fail git config --get --path path.home \
1010 >result 2>msg &&
1011 git config --get --path path.normal >>result &&
1012 git config --get --path path.trailingtilde >>result
1013 ) &&
1edbaac3 1014 test_i18ngrep "[Ff]ailed to expand.*~/" msg &&
79bf1490
JN
1015 test_cmp expect result
1016'
1017
962c38ee
CMN
1018test_expect_success 'get --path barfs on boolean variable' '
1019 echo "[path]bool" >.git/config &&
1020 test_must_fail git config --get --path path.bool
1021'
1022
5f967424
HM
1023test_expect_success 'get --expiry-date' '
1024 rel="3.weeks.5.days.00:00" &&
1025 rel_out="$rel ->" &&
1026 cat >.git/config <<-\EOF &&
1027 [date]
1028 valid1 = "3.weeks.5.days 00:00"
1029 valid2 = "Fri Jun 4 15:46:55 2010"
1030 valid3 = "2017/11/11 11:11:11PM"
1031 valid4 = "2017/11/10 09:08:07 PM"
1032 valid5 = "never"
1033 invalid1 = "abc"
1034 EOF
1035 cat >expect <<-EOF &&
a801a7cf 1036 $(test-tool date timestamp $rel)
5f967424
HM
1037 1275666415
1038 1510441871
1039 1510348087
1040 0
1041 EOF
d38722eb 1042 : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
5f967424 1043 {
7abcbcb7 1044 echo "$rel_out $(git config --expiry-date date.valid1)" &&
5f967424
HM
1045 git config --expiry-date date.valid2 &&
1046 git config --expiry-date date.valid3 &&
1047 git config --expiry-date date.valid4 &&
1048 git config --expiry-date date.valid5
1049 } >actual &&
1050 test_cmp expect actual &&
1051 test_must_fail git config --expiry-date date.invalid1
1052'
1053
63e2a0f8
TB
1054test_expect_success 'get --type=color' '
1055 rm .git/config &&
1056 git config foo.color "red" &&
1057 git config --get --type=color foo.color >actual.raw &&
1058 test_decode_color <actual.raw >actual &&
1059 echo "<RED>" >expect &&
1060 test_cmp expect actual
1061'
1062
1063cat >expect << EOF
1064[foo]
1065 color = red
1066EOF
1067
1068test_expect_success 'set --type=color' '
1069 rm .git/config &&
1070 git config --type=color foo.color "red" &&
1071 test_cmp expect .git/config
1072'
1073
1074test_expect_success 'get --type=color barfs on non-color' '
1075 echo "[foo]bar=not-a-color" >.git/config &&
1076 test_must_fail git config --get --type=color foo.bar
1077'
1078
1079test_expect_success 'set --type=color barfs on non-color' '
1080 test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
1081 test_i18ngrep "cannot parse color" error
1082'
1083
cdd4fb15
BG
1084cat > expect << EOF
1085[quote]
1086 leading = " test"
1087 ending = "test "
1088 semicolon = "test;test"
1089 hash = "test#test"
1090EOF
5a953fc5 1091test_expect_success 'quoting' '
795290e5 1092 rm -f .git/config &&
5a953fc5
JK
1093 git config quote.leading " test" &&
1094 git config quote.ending "test " &&
1095 git config quote.semicolon "test;test" &&
1096 git config quote.hash "test#test" &&
1097 test_cmp expect .git/config
1098'
cdd4fb15 1099
41ac414e 1100test_expect_success 'key with newline' '
d492b31c 1101 test_must_fail git config "key.with
41ac414e 1102newline" 123'
6f71686e 1103
e0d10e1c 1104test_expect_success 'value with newline' 'git config key.sub value.with\\\
6f71686e
JS
1105newline'
1106
83cd10a0
JN
1107cat > .git/config <<\EOF
1108[section]
1109 ; comment \
1110 continued = cont\
1111inued
1112 noncont = not continued ; \
1113 quotecont = "cont;\
1114inued"
1115EOF
1116
1117cat > expect <<\EOF
1118section.continued=continued
1119section.noncont=not continued
1120section.quotecont=cont;inued
1121EOF
1122
5a953fc5
JK
1123test_expect_success 'value continued on next line' '
1124 git config --list > result &&
dcbaa0b3 1125 test_cmp expect result
5a953fc5 1126'
83cd10a0 1127
2275d502
FL
1128cat > .git/config <<\EOF
1129[section "sub=section"]
1130 val1 = foo=bar
1131 val2 = foo\nbar
1132 val3 = \n\n
1133 val4 =
1134 val5
1135EOF
1136
1137cat > expect <<\EOF
2b9a5020
AR
1138section.sub=section.val1
1139foo=barQsection.sub=section.val2
1140foo
1141barQsection.sub=section.val3
2275d502
FL
1142
1143
2b9a5020
AR
1144Qsection.sub=section.val4
1145Qsection.sub=section.val5Q
2275d502 1146EOF
5a953fc5 1147test_expect_success '--null --list' '
a0578e03
LS
1148 git config --null --list >result.raw &&
1149 nul_to_q <result.raw >result &&
5a953fc5
JK
1150 echo >>result &&
1151 test_cmp expect result
1152'
2275d502 1153
5a953fc5 1154test_expect_success '--null --get-regexp' '
a0578e03
LS
1155 git config --null --get-regexp "val[0-9]" >result.raw &&
1156 nul_to_q <result.raw >result &&
5a953fc5
JK
1157 echo >>result &&
1158 test_cmp expect result
1159'
2275d502 1160
d71bc1b4
DS
1161test_expect_success 'inner whitespace kept verbatim, spaces only' '
1162 echo "foo bar" >expect &&
1163 git config section.val "foo bar" &&
1164 git config --get section.val >actual &&
1165 test_cmp expect actual
1166'
1167
1168test_expect_success 'inner whitespace kept verbatim, horizontal tabs only' '
1169 echo "fooQQbar" | q_to_tab >expect &&
1170 git config section.val "$(cat expect)" &&
1171 git config --get section.val >actual &&
1172 test_cmp expect actual
1173'
1174
1175test_expect_success 'inner whitespace kept verbatim, horizontal tabs and spaces' '
1176 echo "foo Q bar" | q_to_tab >expect &&
1177 git config section.val "$(cat expect)" &&
1178 git config --get section.val >actual &&
1179 test_cmp expect actual
ebdaae37
BS
1180'
1181
704a3143 1182test_expect_success SYMLINKS 'symlinked configuration' '
65a5a21d 1183 ln -s notyet myconfig &&
f7e87141 1184 git config --file=myconfig test.frotz nitfol &&
65a5a21d
JH
1185 test -h myconfig &&
1186 test -f notyet &&
f7e87141
JK
1187 test "z$(git config --file=notyet test.frotz)" = znitfol &&
1188 git config --file=myconfig test.xyzzy rezrov &&
65a5a21d
JH
1189 test -h myconfig &&
1190 test -f notyet &&
ed838e66
JK
1191 cat >expect <<-\EOF &&
1192 nitfol
1193 rezrov
1194 EOF
1195 {
f7e87141
JK
1196 git config --file=notyet test.frotz &&
1197 git config --file=notyet test.xyzzy
ed838e66
JK
1198 } >actual &&
1199 test_cmp expect actual
65a5a21d
JH
1200'
1201
1f2baa78
JK
1202test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1203 ln -s doesnotexist linktonada &&
1204 ln -s linktonada linktolinktonada &&
551a3e60
JK
1205 test_must_fail git config --file=linktonada --list &&
1206 test_must_fail git config --file=linktolinktonada --list
1f2baa78
JK
1207'
1208
dc4179f9
DM
1209test_expect_success 'check split_cmdline return' "
1210 git config alias.split-cmdline-fix 'echo \"' &&
1211 test_must_fail git split-cmdline-fix &&
1212 echo foo > foo &&
1213 git add foo &&
1214 git commit -m 'initial commit' &&
06d53148
JS
1215 git config branch.main.mergeoptions 'echo \"' &&
1216 test_must_fail git merge main
ed838e66 1217"
dc4179f9 1218
8b1fa778 1219test_expect_success 'git -c "key=value" support' '
ed838e66
JK
1220 cat >expect <<-\EOF &&
1221 value
1222 value
1223 true
1224 EOF
1225 {
04f6b0a1 1226 git -c section.name=value config section.name &&
ed838e66
JK
1227 git -c foo.CamelCase=value config foo.camelcase &&
1228 git -c foo.flag config --bool foo.flag
1229 } >actual &&
1230 test_cmp expect actual &&
04f6b0a1 1231 test_must_fail git -c name=value config section.name
b09c53a3
LP
1232'
1233
a789ca70
JH
1234# We just need a type-specifier here that cares about the
1235# distinction internally between a NULL boolean and a real
1236# string (because most of git's internal parsers do care).
1237# Using "--path" works, but we do not otherwise care about
1238# its semantics.
1239test_expect_success 'git -c can represent empty string' '
1240 echo >expect &&
1241 git -c foo.empty= config --path foo.empty >actual &&
1242 test_cmp expect actual
1243'
1244
b09c53a3
LP
1245test_expect_success 'key sanity-checking' '
1246 test_must_fail git config foo=bar &&
1247 test_must_fail git config foo=.bar &&
1248 test_must_fail git config foo.ba=r &&
1249 test_must_fail git config foo.1bar &&
1250 test_must_fail git config foo."ba
1251 z".bar &&
2169ddc0
LP
1252 test_must_fail git config . false &&
1253 test_must_fail git config .foo false &&
1254 test_must_fail git config foo. false &&
1255 test_must_fail git config .foo. false &&
b09c53a3
LP
1256 git config foo.bar true &&
1257 git config foo."ba =z".bar false
8b1fa778
AR
1258'
1259
73546c08 1260test_expect_success 'git -c works with aliases of builtins' '
06eb708f
JK
1261 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
1262 echo bar >expect &&
1263 git checkconfig >actual &&
1264 test_cmp expect actual
1265'
1266
643df7e2 1267test_expect_success 'aliases can be CamelCased' '
084b0440
JS
1268 test_config alias.CamelCased "rev-parse HEAD" &&
1269 git CamelCased >out &&
1270 git rev-parse HEAD >expect &&
1271 test_cmp expect out
1272'
1273
5bf6529a
JK
1274test_expect_success 'git -c does not split values on equals' '
1275 echo "value with = in it" >expect &&
04f6b0a1 1276 git -c section.foo="value with = in it" config section.foo >actual &&
5bf6529a
JK
1277 test_cmp expect actual
1278'
1279
1c2c9bee
JK
1280test_expect_success 'git -c dies on bogus config' '
1281 test_must_fail git -c core.bare=foo rev-parse
1282'
1283
1284test_expect_success 'git -c complains about empty key' '
1285 test_must_fail git -c "=foo" rev-parse
1286'
1287
c5d6350b
JK
1288test_expect_success 'git -c complains about empty key and value' '
1289 test_must_fail git -c "" rev-parse
1290'
1291
d1f88498
JK
1292test_expect_success 'multiple git -c appends config' '
1293 test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1294 cat >expect <<-\EOF &&
1295 x.one 1
1296 x.two 2
1297 EOF
1298 git -c x.one=1 x >actual &&
1299 test_cmp expect actual
1300'
1301
1274a155
JH
1302test_expect_success 'last one wins: two level vars' '
1303
1304 # sec.var and sec.VAR are the same variable, as the first
1305 # and the last level of a configuration variable name is
1306 # case insensitive.
1307
1308 echo VAL >expect &&
1309
1310 git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual &&
1311 test_cmp expect actual &&
1312 git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual &&
1313 test_cmp expect actual &&
1314
1315 git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual &&
1316 test_cmp expect actual &&
1317 git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual &&
1318 test_cmp expect actual
1319'
1320
1321test_expect_success 'last one wins: three level vars' '
1322
1323 # v.a.r and v.A.r are not the same variable, as the middle
1324 # level of a three-level configuration variable name is
1325 # case sensitive.
1326
1327 echo val >expect &&
1328 git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual &&
1329 test_cmp expect actual &&
1330 git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual &&
1331 test_cmp expect actual &&
1332
1333 # v.a.r and V.a.R are the same variable, as the first
1334 # and the last level of a configuration variable name is
1335 # case insensitive.
1336
1337 echo VAL >expect &&
1338 git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual &&
1339 test_cmp expect actual &&
1340 git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual &&
1341 test_cmp expect actual &&
1342 git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual &&
1343 test_cmp expect actual &&
1344 git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual &&
1345 test_cmp expect actual
1346'
1347
999d9026
SB
1348test_expect_success 'old-fashioned settings are case insensitive' '
1349 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1350
1351 cat >testConfig_actual <<-EOF &&
3de7ee36
MR
1352 [V.A]
1353 r = value1
999d9026
SB
1354 EOF
1355 q_to_tab >testConfig_expect <<-EOF &&
3de7ee36
MR
1356 [V.A]
1357 Qr = value2
999d9026
SB
1358 EOF
1359 git config -f testConfig_actual "v.a.r" value2 &&
1360 test_cmp testConfig_expect testConfig_actual &&
1361
1362 cat >testConfig_actual <<-EOF &&
3de7ee36
MR
1363 [V.A]
1364 r = value1
999d9026
SB
1365 EOF
1366 q_to_tab >testConfig_expect <<-EOF &&
3de7ee36
MR
1367 [V.A]
1368 QR = value2
999d9026
SB
1369 EOF
1370 git config -f testConfig_actual "V.a.R" value2 &&
1371 test_cmp testConfig_expect testConfig_actual &&
1372
1373 cat >testConfig_actual <<-EOF &&
3de7ee36
MR
1374 [V.A]
1375 r = value1
999d9026
SB
1376 EOF
1377 q_to_tab >testConfig_expect <<-EOF &&
3de7ee36
MR
1378 [V.A]
1379 r = value1
1380 Qr = value2
999d9026
SB
1381 EOF
1382 git config -f testConfig_actual "V.A.r" value2 &&
1383 test_cmp testConfig_expect testConfig_actual &&
1384
1385 cat >testConfig_actual <<-EOF &&
3de7ee36
MR
1386 [V.A]
1387 r = value1
999d9026
SB
1388 EOF
1389 q_to_tab >testConfig_expect <<-EOF &&
3de7ee36
MR
1390 [V.A]
1391 r = value1
1392 Qr = value2
999d9026
SB
1393 EOF
1394 git config -f testConfig_actual "v.A.r" value2 &&
1395 test_cmp testConfig_expect testConfig_actual
1396'
1397
1398test_expect_success 'setting different case sensitive subsections ' '
1399 test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
1400
1401 cat >testConfig_actual <<-EOF &&
3de7ee36
MR
1402 [V "A"]
1403 R = v1
1404 [K "E"]
1405 Y = v1
1406 [a "b"]
1407 c = v1
1408 [d "e"]
1409 f = v1
999d9026
SB
1410 EOF
1411 q_to_tab >testConfig_expect <<-EOF &&
3de7ee36
MR
1412 [V "A"]
1413 Qr = v2
1414 [K "E"]
1415 Qy = v2
1416 [a "b"]
1417 Qc = v2
1418 [d "e"]
1419 f = v1
1420 [d "E"]
1421 Qf = v2
999d9026
SB
1422 EOF
1423 # exact match
1424 git config -f testConfig_actual a.b.c v2 &&
1425 # match section and subsection, key is cased differently.
1426 git config -f testConfig_actual K.E.y v2 &&
1427 # section and key are matched case insensitive, but subsection needs
1428 # to match; When writing out new values only the key is adjusted
1429 git config -f testConfig_actual v.A.r v2 &&
1430 # subsection is not matched:
1431 git config -f testConfig_actual d.E.f v2 &&
1432 test_cmp testConfig_expect testConfig_actual
1433'
1434
1274a155
JH
1435for VAR in a .a a. a.0b a."b c". a."b c".0d
1436do
1437 test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
1438 test_must_fail git -c "$VAR=VAL" config -l
1439 '
1440done
1441
1442for VAR in a.b a."b c".d
1443do
1444 test_expect_success "git -c $VAR=VAL works with valid '$VAR'" '
1445 echo VAL >expect &&
1446 git -c "$VAR=VAL" config --get "$VAR" >actual &&
1447 test_cmp expect actual
1448 '
1449done
1450
d1f88498
JK
1451test_expect_success 'git -c is not confused by empty environment' '
1452 GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
1453'
1454
f9dbb64f
JK
1455test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1456 v="${SQ}key.one=foo${SQ}" &&
1457 v="$v ${SQ}key.two=bar${SQ}" &&
1458 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1459 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1460 cat >expect <<-EOF &&
1461 key.one foo
1462 key.two bar
1463 key.ambiguous section.whatever=value
1464 EOF
1465 test_cmp expect actual
1466'
1467
1468test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1469 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1470 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1471 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1472 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1473 cat >expect <<-EOF &&
1474 key.one foo
1475 key.two bar
1476 key.ambiguous=section.whatever value
1477 EOF
1478 test_cmp expect actual
1479'
1480
1481test_expect_success 'old and new-style entries can mix' '
1482 v="${SQ}key.oldone=oldfoo${SQ}" &&
1483 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1484 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1485 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1486 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1487 cat >expect <<-EOF &&
1488 key.oldone oldfoo
1489 key.newone newfoo
1490 key.oldtwo oldbar
1491 key.newtwo newbar
1492 EOF
1493 test_cmp expect actual
1494'
1495
1496test_expect_success 'old and new bools with ambiguous subsection' '
1497 v="${SQ}key.with=equals.oldbool${SQ}" &&
1498 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1499 GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1500 cat >expect <<-EOF &&
1501 key.with equals.oldbool
1502 key.with=equals.newbool
1503 EOF
1504 test_cmp expect actual
1505'
1506
ddbbf8eb
JK
1507test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1508 cat >expect <<-\EOF &&
1509 env.one one
1510 env.two two
1511 EOF
bd482d6e 1512 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
ddbbf8eb
JK
1513 git config --get-regexp "env.*" >actual &&
1514 test_cmp expect actual &&
1515
1516 cat >expect <<-EOF &&
bd482d6e 1517 env.one one${SQ}
ddbbf8eb
JK
1518 env.two two
1519 EOF
bd482d6e 1520 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
ddbbf8eb
JK
1521 git config --get-regexp "env.*" >actual &&
1522 test_cmp expect actual &&
1523
1524 test_must_fail env \
bd482d6e 1525 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
ddbbf8eb
JK
1526 git config --get-regexp "env.*"
1527'
1528
ce81b1da
PS
1529test_expect_success 'git --config-env=key=envvar support' '
1530 cat >expect <<-\EOF &&
1531 value
1532 value
c331551c
PS
1533 value
1534 value
1535 false
ce81b1da
PS
1536 false
1537 EOF
1538 {
1539 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
c331551c 1540 ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
ce81b1da 1541 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
c331551c
PS
1542 ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1543 ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1544 ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
ce81b1da
PS
1545 } >actual &&
1546 test_cmp expect actual
1547'
1548
c331551c
PS
1549test_expect_success 'git --config-env with missing value' '
1550 test_must_fail env ENVVAR=value git --config-env 2>error &&
1551 grep "no config key given for --config-env" error &&
1552 test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1553 grep "invalid config format: config" error
1554'
1555
ce81b1da
PS
1556test_expect_success 'git --config-env fails with invalid parameters' '
1557 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1558 test_i18ngrep "invalid config format: foo.flag" error &&
1559 test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
1560 test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
1561 sane_unset NONEXISTENT &&
1562 test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
1563 test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
1564'
1565
1566test_expect_success 'git -c and --config-env work together' '
1567 cat >expect <<-\EOF &&
1568 bar.cmd cmd-value
1569 bar.env env-value
1570 EOF
1571 ENVVAR=env-value git \
1572 -c bar.cmd=cmd-value \
1573 --config-env=bar.env=ENVVAR \
1574 config --get-regexp "^bar.*" >actual &&
1575 test_cmp expect actual
1576'
1577
1578test_expect_success 'git -c and --config-env override each other' '
1579 cat >expect <<-\EOF &&
1580 env
1581 cmd
1582 EOF
1583 {
1584 ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
1585 ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
1586 } >actual &&
1587 test_cmp expect actual
1588'
1589
1ff21c05
PS
1590test_expect_success '--config-env handles keys with equals' '
1591 echo value=with=equals >expect &&
1592 ENVVAR=value=with=equals git \
1593 --config-env=section.subsection=with=equals.key=ENVVAR \
1594 config section.subsection=with=equals.key >actual &&
1595 test_cmp expect actual
1596'
1597
d8d77153
PS
1598test_expect_success 'git config handles environment config pairs' '
1599 GIT_CONFIG_COUNT=2 \
1600 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1601 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1602 git config --get-regexp "pair.*" >actual &&
1603 cat >expect <<-EOF &&
1604 pair.one foo
1605 pair.two bar
1606 EOF
1607 test_cmp expect actual
1608'
1609
1610test_expect_success 'git config ignores pairs without count' '
1611 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1612 git config pair.one 2>error &&
1613 test_must_be_empty error
1614'
1615
d8d77153
PS
1616test_expect_success 'git config ignores pairs exceeding count' '
1617 GIT_CONFIG_COUNT=1 \
1618 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1619 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
93f86046 1620 git config --get-regexp "pair.*" >actual 2>error &&
d8d77153
PS
1621 cat >expect <<-EOF &&
1622 pair.one value
1623 EOF
93f86046
AR
1624 test_cmp expect actual &&
1625 test_must_be_empty error
d8d77153
PS
1626'
1627
1628test_expect_success 'git config ignores pairs with zero count' '
1629 test_must_fail env \
1630 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
93f86046 1631 git config pair.one 2>error &&
d8d77153
PS
1632 test_must_be_empty error
1633'
1634
1635test_expect_success 'git config ignores pairs with empty count' '
1636 test_must_fail env \
1637 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
93f86046 1638 git config pair.one 2>error &&
d8d77153
PS
1639 test_must_be_empty error
1640'
1641
1642test_expect_success 'git config fails with invalid count' '
1643 test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
1644 test_i18ngrep "bogus count" error &&
1645 test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
1646 test_i18ngrep "too many entries" error
1647'
1648
1649test_expect_success 'git config fails with missing config key' '
1650 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
1651 git config --list 2>error &&
1652 test_i18ngrep "missing config key" error
1653'
1654
1655test_expect_success 'git config fails with missing config value' '
1656 test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
1657 git config --list 2>error &&
1658 test_i18ngrep "missing config value" error
1659'
1660
1661test_expect_success 'git config fails with invalid config pair key' '
1662 test_must_fail env GIT_CONFIG_COUNT=1 \
1663 GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
1664 git config --list &&
1665 test_must_fail env GIT_CONFIG_COUNT=1 \
1666 GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
1667 git config --list
1668'
1669
1670test_expect_success 'environment overrides config file' '
1671 test_when_finished "rm -f .git/config" &&
1672 cat >.git/config <<-EOF &&
1673 [pair]
1674 one = value
1675 EOF
1676 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1677 git config pair.one >actual &&
1678 cat >expect <<-EOF &&
1679 override
1680 EOF
1681 test_cmp expect actual
1682'
1683
1684test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1685 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1686 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1687 git config pair.one >actual &&
1688 cat >expect <<-EOF &&
1689 override
1690 EOF
1691 test_cmp expect actual
1692'
1693
1694test_expect_success 'command line overrides environment config' '
1695 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1696 git -c pair.one=override config pair.one >actual &&
1697 cat >expect <<-EOF &&
1698 override
1699 EOF
1700 test_cmp expect actual
1701'
1702
270a3443
JK
1703test_expect_success 'git config --edit works' '
1704 git config -f tmp test.value no &&
1705 echo test.value=yes >expect &&
1706 GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit &&
1707 git config -f tmp --list >actual &&
1708 test_cmp expect actual
1709'
1710
1711test_expect_success 'git config --edit respects core.editor' '
1712 git config -f tmp test.value no &&
1713 echo test.value=yes >expect &&
1714 test_config core.editor "echo [test]value=yes >" &&
1715 git config -f tmp --edit &&
1716 git config -f tmp --list >actual &&
1717 test_cmp expect actual
1718'
1719
4b340593
MS
1720# malformed configuration files
1721test_expect_success 'barf on syntax error' '
1722 cat >.git/config <<-\EOF &&
6fc68e7c 1723 # broken key=value
4b340593
MS
1724 [section]
1725 key garbage
1726 EOF
a7cae290 1727 test_must_fail git config --get section.key 2>error &&
1edbaac3 1728 test_i18ngrep " line 3 " error
4b340593
MS
1729'
1730
1731test_expect_success 'barf on incomplete section header' '
1732 cat >.git/config <<-\EOF &&
1733 # broken section line
1734 [section
1735 key = value
1736 EOF
a7cae290 1737 test_must_fail git config --get section.key 2>error &&
1edbaac3 1738 test_i18ngrep " line 2 " error
4b340593
MS
1739'
1740
1741test_expect_success 'barf on incomplete string' '
1742 cat >.git/config <<-\EOF &&
6fc68e7c 1743 # broken value string
4b340593
MS
1744 [section]
1745 key = "value string
1746 EOF
a7cae290 1747 test_must_fail git config --get section.key 2>error &&
1edbaac3 1748 test_i18ngrep " line 3 " error
4b340593
MS
1749'
1750
d4770964
JH
1751test_expect_success 'urlmatch' '
1752 cat >.git/config <<-\EOF &&
1753 [http]
1754 sslVerify
1755 [http "https://weak.example.com"]
1756 sslVerify = false
1757 cookieFile = /tmp/cookie.txt
1758 EOF
1759
27b30be6
JK
1760 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1761 test_must_be_empty actual &&
1762
d4770964
JH
1763 echo true >expect &&
1764 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1765 test_cmp expect actual &&
1766
1767 echo false >expect &&
1768 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1769 test_cmp expect actual &&
1770
1771 {
1772 echo http.cookiefile /tmp/cookie.txt &&
1773 echo http.sslverify false
1774 } >expect &&
1775 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1776 test_cmp expect actual
1777'
1778
26b66932
GC
1779test_expect_success 'urlmatch with --show-scope' '
1780 cat >.git/config <<-\EOF &&
1781 [http "https://weak.example.com"]
1782 sslVerify = false
1783 cookieFile = /tmp/cookie.txt
1784 EOF
1785
1786 cat >expect <<-EOF &&
1787 local http.cookiefile /tmp/cookie.txt
1788 local http.sslverify false
1789 EOF
1790 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1791 test_cmp expect actual
1792'
1793
af99049c
PS
1794test_expect_success 'urlmatch favors more specific URLs' '
1795 cat >.git/config <<-\EOF &&
1796 [http "https://example.com/"]
1797 cookieFile = /tmp/root.txt
1798 [http "https://example.com/subdirectory"]
1799 cookieFile = /tmp/subdirectory.txt
1800 [http "https://user@example.com/"]
1801 cookieFile = /tmp/user.txt
1802 [http "https://averylonguser@example.com/"]
1803 cookieFile = /tmp/averylonguser.txt
a272b9e7
PS
1804 [http "https://preceding.example.com"]
1805 cookieFile = /tmp/preceding.txt
1806 [http "https://*.example.com"]
1807 cookieFile = /tmp/wildcard.txt
1808 [http "https://*.example.com/wildcardwithsubdomain"]
1809 cookieFile = /tmp/wildcardwithsubdomain.txt
732f9344 1810 [http "https://*.example.*"]
1811 cookieFile = /tmp/multiwildcard.txt
a272b9e7
PS
1812 [http "https://trailing.example.com"]
1813 cookieFile = /tmp/trailing.txt
1814 [http "https://user@*.example.com/"]
1815 cookieFile = /tmp/wildcardwithuser.txt
1816 [http "https://sub.example.com/"]
1817 cookieFile = /tmp/sub.txt
af99049c
PS
1818 EOF
1819
1820 echo http.cookiefile /tmp/root.txt >expect &&
1821 git config --get-urlmatch HTTP https://example.com >actual &&
1822 test_cmp expect actual &&
1823
1824 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1825 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1826 test_cmp expect actual &&
1827
1828 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1829 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1830 test_cmp expect actual &&
1831
1832 echo http.cookiefile /tmp/user.txt >expect &&
1833 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1834 test_cmp expect actual &&
1835
1836 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1837 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
a272b9e7
PS
1838 test_cmp expect actual &&
1839
1840 echo http.cookiefile /tmp/preceding.txt >expect &&
1841 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1842 test_cmp expect actual &&
1843
1844 echo http.cookiefile /tmp/wildcard.txt >expect &&
1845 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1846 test_cmp expect actual &&
1847
1848 echo http.cookiefile /tmp/sub.txt >expect &&
1849 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1850 test_cmp expect actual &&
1851
1852 echo http.cookiefile /tmp/trailing.txt >expect &&
1853 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1854 test_cmp expect actual &&
1855
1856 echo http.cookiefile /tmp/sub.txt >expect &&
1857 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
732f9344 1858 test_cmp expect actual &&
1859
1860 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1861 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
a272b9e7
PS
1862 test_cmp expect actual
1863'
1864
1865test_expect_success 'urlmatch with wildcard' '
1866 cat >.git/config <<-\EOF &&
1867 [http]
1868 sslVerify
1869 [http "https://*.example.com"]
1870 sslVerify = false
1871 cookieFile = /tmp/cookie.txt
1872 EOF
1873
1874 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1875 test_must_be_empty actual &&
1876
1877 echo true >expect &&
1878 git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
1879 test_cmp expect actual &&
1880
1881 echo true >expect &&
1882 git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
1883 test_cmp expect actual &&
1884
1885 echo true >expect &&
1886 git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
1887 test_cmp expect actual &&
1888
1889 echo false >expect &&
1890 git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
1891 test_cmp expect actual &&
1892
1893 {
1894 echo http.cookiefile /tmp/cookie.txt &&
1895 echo http.sslverify false
1896 } >expect &&
1897 git config --get-urlmatch HTTP https://good.example.com >actual &&
1898 test_cmp expect actual &&
1899
1900 echo http.sslverify >expect &&
1901 git config --get-urlmatch HTTP https://more.example.com.au >actual &&
af99049c
PS
1902 test_cmp expect actual
1903'
1904
53ca053b 1905# good section hygiene
22aedfcc 1906test_expect_success '--unset last key removes section (except if commented)' '
53ca053b
JK
1907 cat >.git/config <<-\EOF &&
1908 # some generic comment on the configuration file itself
1909 # a comment specific to this "section" section.
1910 [section]
1911 # some intervening lines
1912 # that should also be dropped
1913
1914 key = value
1915 # please be careful when you update the above variable
1916 EOF
1917
1918 cat >expect <<-\EOF &&
1919 # some generic comment on the configuration file itself
dde154b5
JS
1920 # a comment specific to this "section" section.
1921 [section]
1922 # some intervening lines
1923 # that should also be dropped
1924
1925 # please be careful when you update the above variable
53ca053b
JK
1926 EOF
1927
1928 git config --unset section.key &&
dde154b5
JS
1929 test_cmp expect .git/config &&
1930
1931 cat >.git/config <<-\EOF &&
1932 [section]
1933 key = value
1934 [next-section]
1935 EOF
1936
1937 cat >expect <<-\EOF &&
1938 [next-section]
53ca053b
JK
1939 EOF
1940
1941 git config --unset section.key &&
422e8ef2
JS
1942 test_cmp expect .git/config &&
1943
1944 q_to_tab >.git/config <<-\EOF &&
1945 [one]
1946 Qkey = "multiline \
1947 QQ# with comment"
1948 [two]
1949 key = true
1950 EOF
1951 git config --unset two.key &&
1952 ! grep two .git/config &&
1953
1954 q_to_tab >.git/config <<-\EOF &&
1955 [one]
1956 Qkey = "multiline \
1957 QQ# with comment"
1958 [one]
1959 key = true
1960 EOF
1961 git config --unset-all one.key &&
1962 test_line_count = 0 .git/config &&
1963
1964 q_to_tab >.git/config <<-\EOF &&
1965 [one]
1966 Qkey = true
1967 Q# a comment not at the start
1968 [two]
1969 Qkey = true
1970 EOF
1971 git config --unset two.key &&
1972 grep two .git/config &&
1973
1974 q_to_tab >.git/config <<-\EOF &&
1975 [one]
1976 Qkey = not [two "subsection"]
1977 [two "subsection"]
1978 [two "subsection"]
1979 Qkey = true
1980 [TWO "subsection"]
1981 [one]
1982 EOF
1983 git config --unset two.subsection.key &&
1984 test "not [two subsection]" = "$(git config one.key)" &&
1985 test_line_count = 3 .git/config
53ca053b
JK
1986'
1987
22aedfcc 1988test_expect_success '--unset-all removes section if empty & uncommented' '
b73bdc34
JS
1989 cat >.git/config <<-\EOF &&
1990 [section]
1991 key = value1
1992 key = value2
1993 EOF
1994
1995 git config --unset-all section.key &&
1996 test_line_count = 0 .git/config
53ca053b
JK
1997'
1998
c71d8bb3 1999test_expect_success 'adding a key into an empty section reuses header' '
53ca053b
JK
2000 cat >.git/config <<-\EOF &&
2001 [section]
2002 EOF
2003
2004 q_to_tab >expect <<-\EOF &&
2005 [section]
2006 Qkey = value
2007 EOF
2008
60687de5 2009 git config section.key value &&
53ca053b
JK
2010 test_cmp expect .git/config
2011'
2012
daa22c6f
EW
2013test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
2014 chmod 0600 .git/config &&
2015 git config imap.pass Hunter2 &&
2016 perl -e \
2017 "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" &&
2018 git config --rename-section imap pop &&
2019 perl -e \
2020 "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
2021'
2022
45bf3297
JS
2023! test_have_prereq MINGW ||
2024HOME="$(pwd)" # convert to Windows path
2025
70bd879a
LS
2026test_expect_success 'set up --show-origin tests' '
2027 INCLUDE_DIR="$HOME/include" &&
2028 mkdir -p "$INCLUDE_DIR" &&
2029 cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
3de7ee36
MR
2030 [user]
2031 absolute = include
70bd879a
LS
2032 EOF
2033 cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
3de7ee36
MR
2034 [user]
2035 relative = include
70bd879a
LS
2036 EOF
2037 cat >"$HOME"/.gitconfig <<-EOF &&
3de7ee36
MR
2038 [user]
2039 global = true
2040 override = global
2041 [include]
2042 path = "$INCLUDE_DIR/absolute.include"
70bd879a
LS
2043 EOF
2044 cat >.git/config <<-\EOF
3de7ee36
MR
2045 [user]
2046 local = true
2047 override = local
2048 [include]
2049 path = ../include/relative.include
70bd879a
LS
2050 EOF
2051'
2052
2053test_expect_success '--show-origin with --list' '
2054 cat >expect <<-EOF &&
3de7ee36
MR
2055 file:$HOME/.gitconfig user.global=true
2056 file:$HOME/.gitconfig user.override=global
2057 file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2058 file:$INCLUDE_DIR/absolute.include user.absolute=include
2059 file:.git/config user.local=true
2060 file:.git/config user.override=local
2061 file:.git/config include.path=../include/relative.include
2062 file:.git/../include/relative.include user.relative=include
d8d77153 2063 command line: user.environ=true
3de7ee36 2064 command line: user.cmdline=true
70bd879a 2065 EOF
d8d77153
PS
2066 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
2067 git -c user.cmdline=true config --list --show-origin >output &&
70bd879a
LS
2068 test_cmp expect output
2069'
2070
2071test_expect_success '--show-origin with --list --null' '
2072 cat >expect <<-EOF &&
3de7ee36
MR
2073 file:$HOME/.gitconfigQuser.global
2074 trueQfile:$HOME/.gitconfigQuser.override
2075 globalQfile:$HOME/.gitconfigQinclude.path
2076 $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
2077 includeQfile:.git/configQuser.local
2078 trueQfile:.git/configQuser.override
2079 localQfile:.git/configQinclude.path
2080 ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
2081 includeQcommand line:Quser.cmdline
2082 trueQ
70bd879a
LS
2083 EOF
2084 git -c user.cmdline=true config --null --list --show-origin >output.raw &&
2085 nul_to_q <output.raw >output &&
2086 # The here-doc above adds a newline that the --null output would not
2087 # include. Add it here to make the two comparable.
2088 echo >>output &&
2089 test_cmp expect output
2090'
2091
2092test_expect_success '--show-origin with single file' '
2093 cat >expect <<-\EOF &&
3de7ee36
MR
2094 file:.git/config user.local=true
2095 file:.git/config user.override=local
2096 file:.git/config include.path=../include/relative.include
70bd879a
LS
2097 EOF
2098 git config --local --list --show-origin >output &&
2099 test_cmp expect output
2100'
2101
2102test_expect_success '--show-origin with --get-regexp' '
2103 cat >expect <<-EOF &&
3de7ee36
MR
2104 file:$HOME/.gitconfig user.global true
2105 file:.git/config user.local true
70bd879a
LS
2106 EOF
2107 git config --show-origin --get-regexp "user\.[g|l].*" >output &&
2108 test_cmp expect output
2109'
2110
2111test_expect_success '--show-origin getting a single key' '
2112 cat >expect <<-\EOF &&
3de7ee36 2113 file:.git/config local
70bd879a
LS
2114 EOF
2115 git config --show-origin user.override >output &&
2116 test_cmp expect output
2117'
2118
2119test_expect_success 'set up custom config file' '
417be08d 2120 CUSTOM_CONFIG_FILE="custom.conf" &&
70bd879a 2121 cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
3de7ee36
MR
2122 [user]
2123 custom = true
70bd879a
LS
2124 EOF
2125'
2126
417be08d
MR
2127test_expect_success !MINGW 'set up custom config file with special name characters' '
2128 WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" &&
2129 cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE"
2130'
2131
45bf3297 2132test_expect_success !MINGW '--show-origin escape special file name characters' '
70bd879a 2133 cat >expect <<-\EOF &&
3de7ee36 2134 file:"file\" (dq) and spaces.conf" user.custom=true
70bd879a 2135 EOF
417be08d 2136 git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output &&
70bd879a
LS
2137 test_cmp expect output
2138'
2139
2140test_expect_success '--show-origin stdin' '
2141 cat >expect <<-\EOF &&
3de7ee36 2142 standard input: user.custom=true
70bd879a
LS
2143 EOF
2144 git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
2145 test_cmp expect output
2146'
2147
2148test_expect_success '--show-origin stdin with file include' '
2149 cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
3de7ee36
MR
2150 [user]
2151 stdin = include
70bd879a
LS
2152 EOF
2153 cat >expect <<-EOF &&
3de7ee36 2154 file:$INCLUDE_DIR/stdin.include include
70bd879a 2155 EOF
bdbc17e8
MD
2156 echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" |
2157 git config --show-origin --includes --file - user.stdin >output &&
2158
70bd879a
LS
2159 test_cmp expect output
2160'
2161
417be08d 2162test_expect_success '--show-origin blob' '
70bd879a 2163 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
0dc3ad99 2164 cat >expect <<-EOF &&
3de7ee36 2165 blob:$blob user.custom=true
0dc3ad99 2166 EOF
70bd879a
LS
2167 git config --blob=$blob --show-origin --list >output &&
2168 test_cmp expect output
2169'
2170
417be08d 2171test_expect_success '--show-origin blob ref' '
70bd879a 2172 cat >expect <<-\EOF &&
06d53148 2173 blob:main:custom.conf user.custom=true
70bd879a
LS
2174 EOF
2175 git add "$CUSTOM_CONFIG_FILE" &&
2176 git commit -m "new config file" &&
06d53148 2177 git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
70bd879a
LS
2178 test_cmp expect output
2179'
2180
26b66932
GC
2181test_expect_success '--show-origin with --default' '
2182 git config --show-origin --default foo some.key >actual &&
2183 echo "command line: foo" >expect &&
2184 test_cmp expect actual
2185'
2186
145d59f4
MR
2187test_expect_success '--show-scope with --list' '
2188 cat >expect <<-EOF &&
2189 global user.global=true
2190 global user.override=global
2191 global include.path=$INCLUDE_DIR/absolute.include
2192 global user.absolute=include
2193 local user.local=true
2194 local user.override=local
2195 local include.path=../include/relative.include
2196 local user.relative=include
db7961e6
GC
2197 local core.repositoryformatversion=1
2198 local extensions.worktreeconfig=true
2199 worktree user.worktree=true
145d59f4
MR
2200 command user.cmdline=true
2201 EOF
db7961e6
GC
2202 git worktree add wt1 &&
2203 # We need these to test for worktree scope, but outside of this
2204 # test, this is just noise
2205 test_config core.repositoryformatversion 1 &&
2206 test_config extensions.worktreeConfig true &&
2207 git config --worktree user.worktree true &&
145d59f4
MR
2208 git -c user.cmdline=true config --list --show-scope >output &&
2209 test_cmp expect output
2210'
2211
2212test_expect_success !MINGW '--show-scope with --blob' '
2213 blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2214 cat >expect <<-EOF &&
2215 command user.custom=true
2216 EOF
2217 git config --blob=$blob --show-scope --list >output &&
2218 test_cmp expect output
2219'
2220
2221test_expect_success '--show-scope with --local' '
2222 cat >expect <<-\EOF &&
2223 local user.local=true
2224 local user.override=local
2225 local include.path=../include/relative.include
2226 EOF
2227 git config --local --list --show-scope >output &&
2228 test_cmp expect output
2229'
2230
2231test_expect_success '--show-scope getting a single value' '
2232 cat >expect <<-\EOF &&
2233 local true
2234 EOF
2235 git config --show-scope --get user.local >output &&
2236 test_cmp expect output
2237'
2238
2239test_expect_success '--show-scope with --show-origin' '
2240 cat >expect <<-EOF &&
2241 global file:$HOME/.gitconfig user.global=true
2242 global file:$HOME/.gitconfig user.override=global
2243 global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
2244 global file:$INCLUDE_DIR/absolute.include user.absolute=include
2245 local file:.git/config user.local=true
2246 local file:.git/config user.override=local
2247 local file:.git/config include.path=../include/relative.include
2248 local file:.git/../include/relative.include user.relative=include
2249 command command line: user.cmdline=true
2250 EOF
2251 git -c user.cmdline=true config --list --show-origin --show-scope >output &&
2252 test_cmp expect output
2253'
2254
26b66932
GC
2255test_expect_success '--show-scope with --default' '
2256 git config --show-scope --default foo some.key >actual &&
2257 echo "command foo" >expect &&
2258 test_cmp expect actual
2259'
2260
4179b489 2261test_expect_success 'override global and system config' '
eb1cd602 2262 test_when_finished rm -f \"\$HOME\"/.gitconfig &&
4179b489
PS
2263 cat >"$HOME"/.gitconfig <<-EOF &&
2264 [home]
2265 config = true
2266 EOF
eb1cd602
ÆAB
2267
2268 test_when_finished rm -rf \"\$HOME\"/.config/git &&
4179b489
PS
2269 mkdir -p "$HOME"/.config/git &&
2270 cat >"$HOME"/.config/git/config <<-EOF &&
2271 [xdg]
2272 config = true
2273 EOF
2274 cat >.git/config <<-EOF &&
2275 [local]
2276 config = true
2277 EOF
2278 cat >custom-global-config <<-EOF &&
2279 [global]
2280 config = true
2281 EOF
2282 cat >custom-system-config <<-EOF &&
2283 [system]
2284 config = true
2285 EOF
2286
2287 cat >expect <<-EOF &&
2288 global xdg.config=true
2289 global home.config=true
2290 local local.config=true
2291 EOF
2292 git config --show-scope --list >output &&
2293 test_cmp expect output &&
2294
4179b489
PS
2295 cat >expect <<-EOF &&
2296 system system.config=true
2297 global global.config=true
2298 local local.config=true
2299 EOF
482d5499 2300 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
4179b489
PS
2301 git config --show-scope --list >output &&
2302 test_cmp expect output &&
2303
2304 cat >expect <<-EOF &&
2305 local local.config=true
2306 EOF
482d5499
PS
2307 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \
2308 git config --show-scope --list >output &&
4179b489
PS
2309 test_cmp expect output
2310'
2311
2312test_expect_success 'override global and system config with missing file' '
2313 test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list &&
2314 test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list &&
2315 GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
2316'
2317
2318test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' '
2319 # `git config --system` has different semantics compared to other
2320 # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the
2321 # variable has an effect via a different proxy.
2322 cat >alias-config <<-EOF &&
2323 [alias]
2324 hello-world = !echo "hello world"
2325 EOF
2326 test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \
2327 git hello-world &&
2328 GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \
2329 git hello-world >actual &&
2330 echo "hello world" >expect &&
2331 test_cmp expect actual
2332'
2333
2334test_expect_success 'write to overridden global and system config' '
2335 cat >expect <<EOF &&
2336[config]
2337 key = value
2338EOF
2339
2340 GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
2341 test_cmp expect write-to-global &&
2342
2343 GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
2344 test_cmp expect write-to-system
2345'
2346
378fe5fc
MT
2347for opt in --local --worktree
2348do
2349 test_expect_success "$opt requires a repo" '
2350 # we expect 128 to ensure that we do not simply
2351 # fail to find anything and return code "1"
2352 test_expect_code 128 nongit git config $opt foo.bar
2353 '
2354done
588a538a 2355
0a8950be 2356cat >.git/config <<-\EOF &&
04f6b0a1 2357[section]
fb0dc3ba 2358foo = true
0a8950be 2359number = 10
fb0dc3ba 2360big = 1M
0a8950be
TB
2361EOF
2362
fb0dc3ba 2363test_expect_success 'identical modern --type specifiers are allowed' '
04f6b0a1 2364 test_cmp_config 1048576 --type=int --type=int section.big
0a8950be
TB
2365'
2366
fb0dc3ba 2367test_expect_success 'identical legacy --type specifiers are allowed' '
04f6b0a1 2368 test_cmp_config 1048576 --int --int section.big
fb0dc3ba
TB
2369'
2370
2371test_expect_success 'identical mixed --type specifiers are allowed' '
04f6b0a1 2372 test_cmp_config 1048576 --int --type=int section.big
fb0dc3ba
TB
2373'
2374
2375test_expect_success 'non-identical modern --type specifiers are not allowed' '
04f6b0a1 2376 test_must_fail git config --type=int --type=bool section.big 2>error &&
fb0dc3ba
TB
2377 test_i18ngrep "only one type at a time" error
2378'
2379
2380test_expect_success 'non-identical legacy --type specifiers are not allowed' '
04f6b0a1 2381 test_must_fail git config --int --bool section.big 2>error &&
fb0dc3ba
TB
2382 test_i18ngrep "only one type at a time" error
2383'
2384
2385test_expect_success 'non-identical mixed --type specifiers are not allowed' '
04f6b0a1 2386 test_must_fail git config --type=int --bool section.big 2>error &&
fb0dc3ba
TB
2387 test_i18ngrep "only one type at a time" error
2388'
2389
2390test_expect_success '--type allows valid type specifiers' '
04f6b0a1 2391 test_cmp_config true --type=bool section.foo
fb0dc3ba
TB
2392'
2393
2394test_expect_success '--no-type unsets type specifiers' '
04f6b0a1 2395 test_cmp_config 10 --type=bool --no-type section.number
fb0dc3ba
TB
2396'
2397
2398test_expect_success 'unset type specifiers may be reset to conflicting ones' '
04f6b0a1 2399 test_cmp_config 1048576 --type=bool --no-type --type=int section.big
fb0dc3ba
TB
2400'
2401
2402test_expect_success '--type rejects unknown specifiers' '
04f6b0a1 2403 test_must_fail git config --type=nonsense section.foo 2>error &&
fb0dc3ba
TB
2404 test_i18ngrep "unrecognized --type argument" error
2405'
2406
7595c0ec
PW
2407test_expect_success '--type=int requires at least one digit' '
2408 test_must_fail git config --type int --default m some.key >out 2>error &&
2409 grep "bad numeric config value" error &&
2410 test_must_be_empty out
2411'
2412
46fc89ce 2413test_expect_success '--replace-all does not invent newlines' '
e9313952
JS
2414 q_to_tab >.git/config <<-\EOF &&
2415 [abc]key
2416 QkeepSection
2417 [xyz]
2418 Qkey = 1
2419 [abc]
2420 Qkey = a
2421 EOF
2422 q_to_tab >expect <<-\EOF &&
2423 [abc]
2424 QkeepSection
2425 [xyz]
2426 Qkey = 1
2427 [abc]
2428 Qkey = b
2429 EOF
2430 git config --replace-all abc.key b &&
dcbaa0b3 2431 test_cmp expect .git/config
e9313952
JS
2432'
2433
2076dba2
DS
2434test_expect_success 'set all config with value-pattern' '
2435 test_when_finished rm -f config initial &&
2436 git config --file=initial abc.key one &&
2437
2438 # no match => add new entry
2439 cp initial config &&
2440 git config --file=config abc.key two a+ &&
2441 git config --file=config --list >actual &&
2442 cat >expect <<-\EOF &&
2443 abc.key=one
2444 abc.key=two
2445 EOF
2446 test_cmp expect actual &&
2447
2448 # multiple matches => failure
2449 test_must_fail git config --file=config abc.key three o+ 2>err &&
2450 test_i18ngrep "has multiple values" err &&
2451
2452 # multiple values, no match => add
2453 git config --file=config abc.key three a+ &&
2454 git config --file=config --list >actual &&
2455 cat >expect <<-\EOF &&
2456 abc.key=one
2457 abc.key=two
2458 abc.key=three
2459 EOF
2460 test_cmp expect actual &&
2461
2462 # single match => replace
2463 git config --file=config abc.key four h+ &&
2464 git config --file=config --list >actual &&
2465 cat >expect <<-\EOF &&
2466 abc.key=one
2467 abc.key=two
2468 abc.key=four
2469 EOF
2470 test_cmp expect actual
2471'
2472
d1567194
DS
2473test_expect_success '--replace-all and value-pattern' '
2474 test_when_finished rm -f config &&
2475 git config --file=config --add abc.key one &&
2476 git config --file=config --add abc.key two &&
2477 git config --file=config --add abc.key three &&
2478 git config --file=config --replace-all abc.key four "o+" &&
2479 git config --file=config --list >actual &&
2480 cat >expect <<-\EOF &&
2481 abc.key=four
2482 abc.key=three
2483 EOF
2484 test_cmp expect actual
2485'
2486
fda43942
DS
2487test_expect_success 'refuse --fixed-value for incompatible actions' '
2488 test_when_finished rm -f config &&
2489 git config --file=config dev.null bogus &&
2490
2491 # These modes do not allow --fixed-value at all
2492 test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
2493 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2494 test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
2495 test_must_fail git config --file=config --fixed-value --rename-section dev null &&
2496 test_must_fail git config --file=config --fixed-value --remove-section dev &&
2497 test_must_fail git config --file=config --fixed-value --list &&
2498 test_must_fail git config --file=config --fixed-value --get-color dev.null &&
2499 test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
2500
2501 # These modes complain when --fixed-value has no value-pattern
2502 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2503 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2504 test_must_fail git config --file=config --fixed-value --get dev.null &&
2505 test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2506 test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2507 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2508 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2509'
2510
c90702a1
DS
2511test_expect_success '--fixed-value uses exact string matching' '
2512 test_when_finished rm -f config initial &&
2513 META="a+b*c?d[e]f.g" &&
2514 git config --file=initial fixed.test "$META" &&
2515
2516 cp initial config &&
2517 git config --file=config fixed.test bogus "$META" &&
2518 git config --file=config --list >actual &&
2519 cat >expect <<-EOF &&
2520 fixed.test=$META
2521 fixed.test=bogus
2522 EOF
2523 test_cmp expect actual &&
2524
2525 cp initial config &&
2526 git config --file=config --fixed-value fixed.test bogus "$META" &&
2527 git config --file=config --list >actual &&
2528 cat >expect <<-\EOF &&
2529 fixed.test=bogus
2530 EOF
2531 test_cmp expect actual &&
2532
2533 cp initial config &&
2534 test_must_fail git config --file=config --unset fixed.test "$META" &&
2535 git config --file=config --fixed-value --unset fixed.test "$META" &&
2536 test_must_fail git config --file=config fixed.test &&
2537
2538 cp initial config &&
2539 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2540 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2541 test_must_fail git config --file=config fixed.test &&
2542
2543 cp initial config &&
2544 git config --file=config --replace-all fixed.test bogus "$META" &&
2545 git config --file=config --list >actual &&
2546 cat >expect <<-EOF &&
2547 fixed.test=$META
2548 fixed.test=bogus
2549 EOF
2550 test_cmp expect actual &&
2551
2552 git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
2553 git config --file=config --list >actual &&
2554 cat >expect <<-EOF &&
2555 fixed.test=bogus
2556 fixed.test=bogus
2557 EOF
2558 test_cmp expect actual
2559'
2560
3f1bae1d
DS
2561test_expect_success '--get and --get-all with --fixed-value' '
2562 test_when_finished rm -f config &&
2563 META="a+b*c?d[e]f.g" &&
2564 git config --file=config fixed.test bogus &&
2565 git config --file=config --add fixed.test "$META" &&
2566
2567 git config --file=config --get fixed.test bogus &&
2568 test_must_fail git config --file=config --get fixed.test "$META" &&
2569 git config --file=config --get --fixed-value fixed.test "$META" &&
2570 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2571
2572 git config --file=config --get-all fixed.test bogus &&
2573 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2574 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2575 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2576
2577 git config --file=config --get-regexp fixed+ bogus &&
2578 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2579 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2580 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2581'
2582
399b1984
JT
2583test_expect_success 'includeIf.hasconfig:remote.*.url' '
2584 git init hasremoteurlTest &&
2585 test_when_finished "rm -rf hasremoteurlTest" &&
2586
2587 cat >include-this <<-\EOF &&
2588 [user]
2589 this = this-is-included
2590 EOF
2591 cat >dont-include-that <<-\EOF &&
2592 [user]
2593 that = that-is-not-included
2594 EOF
2595 cat >>hasremoteurlTest/.git/config <<-EOF &&
2596 [includeIf "hasconfig:remote.*.url:foourl"]
2597 path = "$(pwd)/include-this"
2598 [includeIf "hasconfig:remote.*.url:barurl"]
2599 path = "$(pwd)/dont-include-that"
2600 [remote "foo"]
2601 url = foourl
2602 EOF
2603
2604 echo this-is-included >expect-this &&
2605 git -C hasremoteurlTest config --get user.this >actual-this &&
2606 test_cmp expect-this actual-this &&
2607
2608 test_must_fail git -C hasremoteurlTest config --get user.that
2609'
2610
2611test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' '
2612 git init hasremoteurlTest &&
2613 test_when_finished "rm -rf hasremoteurlTest" &&
2614
2615 cat >include-two-three <<-\EOF &&
2616 [user]
2617 two = included-config
2618 three = included-config
2619 EOF
2620 cat >>hasremoteurlTest/.git/config <<-EOF &&
2621 [remote "foo"]
2622 url = foourl
2623 [user]
2624 one = main-config
2625 two = main-config
2626 [includeIf "hasconfig:remote.*.url:foourl"]
2627 path = "$(pwd)/include-two-three"
2628 [user]
2629 three = main-config
2630 EOF
2631
2632 echo main-config >expect-main-config &&
2633 echo included-config >expect-included-config &&
2634
2635 git -C hasremoteurlTest config --get user.one >actual &&
2636 test_cmp expect-main-config actual &&
2637
2638 git -C hasremoteurlTest config --get user.two >actual &&
2639 test_cmp expect-included-config actual &&
2640
2641 git -C hasremoteurlTest config --get user.three >actual &&
2642 test_cmp expect-main-config actual
2643'
2644
2645test_expect_success 'includeIf.hasconfig:remote.*.url globs' '
2646 git init hasremoteurlTest &&
2647 test_when_finished "rm -rf hasremoteurlTest" &&
2648
2649 printf "[user]\ndss = yes\n" >double-star-start &&
2650 printf "[user]\ndse = yes\n" >double-star-end &&
2651 printf "[user]\ndsm = yes\n" >double-star-middle &&
2652 printf "[user]\nssm = yes\n" >single-star-middle &&
2653 printf "[user]\nno = no\n" >no &&
2654
2655 cat >>hasremoteurlTest/.git/config <<-EOF &&
2656 [remote "foo"]
2657 url = https://foo/bar/baz
2658 [includeIf "hasconfig:remote.*.url:**/baz"]
2659 path = "$(pwd)/double-star-start"
2660 [includeIf "hasconfig:remote.*.url:**/nomatch"]
2661 path = "$(pwd)/no"
2662 [includeIf "hasconfig:remote.*.url:https:/**"]
2663 path = "$(pwd)/double-star-end"
2664 [includeIf "hasconfig:remote.*.url:nomatch:/**"]
2665 path = "$(pwd)/no"
2666 [includeIf "hasconfig:remote.*.url:https:/**/baz"]
2667 path = "$(pwd)/double-star-middle"
2668 [includeIf "hasconfig:remote.*.url:https:/**/nomatch"]
2669 path = "$(pwd)/no"
2670 [includeIf "hasconfig:remote.*.url:https://*/bar/baz"]
2671 path = "$(pwd)/single-star-middle"
2672 [includeIf "hasconfig:remote.*.url:https://*/baz"]
2673 path = "$(pwd)/no"
2674 EOF
2675
2676 git -C hasremoteurlTest config --get user.dss &&
2677 git -C hasremoteurlTest config --get user.dse &&
2678 git -C hasremoteurlTest config --get user.dsm &&
2679 git -C hasremoteurlTest config --get user.ssm &&
2680 test_must_fail git -C hasremoteurlTest config --get user.no
2681'
2682
2683test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' '
2684 git init hasremoteurlTest &&
2685 test_when_finished "rm -rf hasremoteurlTest" &&
2686
2687 cat >include-with-url <<-\EOF &&
2688 [remote "bar"]
2689 url = barurl
2690 EOF
2691 cat >>hasremoteurlTest/.git/config <<-EOF &&
2692 [includeIf "hasconfig:remote.*.url:foourl"]
2693 path = "$(pwd)/include-with-url"
2694 EOF
2695
2696 # test with any Git command
2697 test_must_fail git -C hasremoteurlTest status 2>err &&
2698 grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err
2699'
2700
942c1f53 2701test_done