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