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