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