]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1300-repo-config.sh
Git 1.6.6
[thirdparty/git.git] / t / t1300-repo-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
10test -f .git/config && rm .git/config
11
5be60078 12git config core.penguin "little blue"
942c1f53
JS
13
14cat > expect << EOF
942c1f53
JS
15[core]
16 penguin = little blue
17EOF
18
19test_expect_success 'initial' 'cmp .git/config expect'
20
5be60078 21git config Core.Movie BadPhysics
942c1f53
JS
22
23cat > expect << EOF
942c1f53
JS
24[core]
25 penguin = little blue
26 Movie = BadPhysics
27EOF
28
29test_expect_success 'mixed case' 'cmp .git/config expect'
30
5be60078 31git config Cores.WhatEver Second
942c1f53
JS
32
33cat > expect << EOF
942c1f53
JS
34[core]
35 penguin = little blue
36 Movie = BadPhysics
37[Cores]
38 WhatEver = Second
39EOF
40
41test_expect_success 'similar section' 'cmp .git/config expect'
42
5be60078 43git config CORE.UPPERCASE true
942c1f53
JS
44
45cat > expect << EOF
942c1f53
JS
46[core]
47 penguin = little blue
48 Movie = BadPhysics
49 UPPERCASE = true
50[Cores]
51 WhatEver = Second
52EOF
53
54test_expect_success 'similar section' 'cmp .git/config expect'
55
f98d863d 56test_expect_success 'replace with non-match' \
5be60078 57 'git config core.penguin kingpin !blue'
f98d863d
JS
58
59test_expect_success 'replace with non-match (actually matching)' \
5be60078 60 'git config core.penguin "very blue" !kingpin'
f98d863d
JS
61
62cat > expect << EOF
f98d863d
JS
63[core]
64 penguin = very blue
65 Movie = BadPhysics
66 UPPERCASE = true
67 penguin = kingpin
68[Cores]
69 WhatEver = Second
70EOF
71
72test_expect_success 'non-match result' 'cmp .git/config expect'
73
7a31cc0f
FL
74cat > .git/config <<\EOF
75[alpha]
76bar = foo
77[beta]
78baz = multiple \
79lines
80EOF
81
82test_expect_success 'unset with cont. lines' \
83 'git config --unset beta.baz'
84
85cat > expect <<\EOF
86[alpha]
87bar = foo
88[beta]
89EOF
90
91test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
92
942c1f53
JS
93cat > .git/config << EOF
94[beta] ; silly comment # another comment
95noIndent= sillyValue ; 'nother silly comment
96
97# empty line
98 ; comment
99 haha ="beta" # last silly comment
4ddba79d
JS
100haha = hello
101 haha = bello
942c1f53
JS
102[nextSection] noNewline = ouch
103EOF
104
4ddba79d
JS
105cp .git/config .git/config2
106
107test_expect_success 'multiple unset' \
5be60078 108 'git config --unset-all beta.haha'
4ddba79d
JS
109
110cat > expect << EOF
111[beta] ; silly comment # another comment
112noIndent= sillyValue ; 'nother silly comment
113
114# empty line
115 ; comment
116[nextSection] noNewline = ouch
117EOF
118
119test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
120
bf71b4b3
CR
121cp .git/config2 .git/config
122
123test_expect_success '--replace-all missing value' '
124 test_must_fail git config --replace-all beta.haha &&
125 test_cmp .git/config2 .git/config
126'
127
128rm .git/config2
4ddba79d
JS
129
130test_expect_success '--replace-all' \
5be60078 131 'git config --replace-all beta.haha gamma'
4ddba79d
JS
132
133cat > expect << EOF
134[beta] ; silly comment # another comment
135noIndent= sillyValue ; 'nother silly comment
136
137# empty line
138 ; comment
139 haha = gamma
140[nextSection] noNewline = ouch
141EOF
142
143test_expect_success 'all replaced' 'cmp .git/config expect'
144
5be60078 145git config beta.haha alpha
942c1f53
JS
146
147cat > expect << EOF
148[beta] ; silly comment # another comment
149noIndent= sillyValue ; 'nother silly comment
150
151# empty line
152 ; comment
153 haha = alpha
154[nextSection] noNewline = ouch
155EOF
156
157test_expect_success 'really mean test' 'cmp .git/config expect'
158
5be60078 159git config nextsection.nonewline wow
942c1f53
JS
160
161cat > expect << EOF
162[beta] ; silly comment # another comment
163noIndent= sillyValue ; 'nother silly comment
164
165# empty line
166 ; comment
167 haha = alpha
168[nextSection]
169 nonewline = wow
170EOF
171
172test_expect_success 'really really mean test' 'cmp .git/config expect'
173
5be60078
JH
174test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
175git config --unset beta.haha
942c1f53
JS
176
177cat > expect << EOF
178[beta] ; silly comment # another comment
179noIndent= sillyValue ; 'nother silly comment
180
181# empty line
182 ; comment
183[nextSection]
184 nonewline = wow
185EOF
186
187test_expect_success 'unset' 'cmp .git/config expect'
188
5be60078 189git config nextsection.NoNewLine "wow2 for me" "for me$"
942c1f53
JS
190
191cat > expect << EOF
192[beta] ; silly comment # another comment
193noIndent= sillyValue ; 'nother silly comment
194
195# empty line
196 ; comment
197[nextSection]
198 nonewline = wow
199 NoNewLine = wow2 for me
200EOF
201
202test_expect_success 'multivar' 'cmp .git/config expect'
203
f98d863d 204test_expect_success 'non-match' \
5be60078 205 'git config --get nextsection.nonewline !for'
f98d863d
JS
206
207test_expect_success 'non-match value' \
5be60078 208 'test wow = $(git config --get nextsection.nonewline !for)'
f98d863d 209
41ac414e 210test_expect_success 'ambiguous get' '
d492b31c 211 test_must_fail git config --get nextsection.nonewline
41ac414e 212'
4ddba79d
JS
213
214test_expect_success 'get multivar' \
5be60078 215 'git config --get-all nextsection.nonewline'
4ddba79d 216
5be60078 217git config nextsection.nonewline "wow3" "wow$"
942c1f53
JS
218
219cat > expect << EOF
220[beta] ; silly comment # another comment
221noIndent= sillyValue ; 'nother silly comment
222
223# empty line
224 ; comment
225[nextSection]
226 nonewline = wow3
227 NoNewLine = wow2 for me
228EOF
229
230test_expect_success 'multivar replace' 'cmp .git/config expect'
231
41ac414e 232test_expect_success 'ambiguous value' '
d492b31c 233 test_must_fail git config nextsection.nonewline
41ac414e 234'
4ddba79d 235
41ac414e 236test_expect_success 'ambiguous unset' '
d492b31c 237 test_must_fail git config --unset nextsection.nonewline
41ac414e 238'
942c1f53 239
41ac414e 240test_expect_success 'invalid unset' '
d492b31c 241 test_must_fail git config --unset somesection.nonewline
41ac414e 242'
942c1f53 243
5be60078 244git config --unset nextsection.nonewline "wow3$"
942c1f53
JS
245
246cat > expect << EOF
247[beta] ; silly comment # another comment
248noIndent= sillyValue ; 'nother silly comment
249
250# empty line
251 ; comment
252[nextSection]
253 NoNewLine = wow2 for me
254EOF
255
256test_expect_success 'multivar unset' 'cmp .git/config expect'
257
d492b31c 258test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
942c1f53 259
5be60078 260test_expect_success 'correct key' 'git config 123456.a123 987'
942c1f53 261
b17e659d 262test_expect_success 'hierarchical section' \
5be60078 263 'git config Version.1.2.3eX.Alpha beta'
b17e659d
JS
264
265cat > expect << EOF
266[beta] ; silly comment # another comment
267noIndent= sillyValue ; 'nother silly comment
268
269# empty line
270 ; comment
271[nextSection]
272 NoNewLine = wow2 for me
273[123456]
274 a123 = 987
d14f7764
LT
275[Version "1.2.3eX"]
276 Alpha = beta
b17e659d
JS
277EOF
278
279test_expect_success 'hierarchical section value' 'cmp .git/config expect'
280
2fa9a0fb
JS
281cat > expect << EOF
282beta.noindent=sillyValue
283nextsection.nonewline=wow2 for me
284123456.a123=987
d55aaefa 285version.1.2.3eX.alpha=beta
2fa9a0fb
JS
286EOF
287
288test_expect_success 'working --list' \
5be60078 289 'git config --list > output && cmp output expect'
2fa9a0fb
JS
290
291cat > expect << EOF
292beta.noindent sillyValue
293nextsection.nonewline wow2 for me
294EOF
295
296test_expect_success '--get-regexp' \
5be60078 297 'git config --get-regexp in > output && cmp output expect'
2fa9a0fb 298
5be60078 299git config --add nextsection.nonewline "wow4 for you"
89c4afe0
BG
300
301cat > expect << EOF
302wow2 for me
303wow4 for you
304EOF
305
306test_expect_success '--add' \
5be60078 307 'git config --get-all nextsection.nonewline > output && cmp output expect'
89c4afe0 308
f067a137
JF
309cat > .git/config << EOF
310[novalue]
311 variable
09bc098c
CC
312[emptyvalue]
313 variable =
f067a137
JF
314EOF
315
316test_expect_success 'get variable with no value' \
5be60078 317 'git config --get novalue.variable ^$'
f067a137 318
09bc098c
CC
319test_expect_success 'get variable with empty value' \
320 'git config --get emptyvalue.variable ^$'
321
b69ba460
FL
322echo novalue.variable > expect
323
324test_expect_success 'get-regexp variable with no value' \
5be60078 325 'git config --get-regexp novalue > output &&
b69ba460
FL
326 cmp output expect'
327
09bc098c
CC
328echo 'emptyvalue.variable ' > expect
329
330test_expect_success 'get-regexp variable with empty value' \
331 'git config --get-regexp emptyvalue > output &&
332 cmp output expect'
333
334echo true > expect
335
336test_expect_success 'get bool variable with no value' \
337 'git config --bool novalue.variable > output &&
338 cmp output expect'
339
340echo false > expect
341
342test_expect_success 'get bool variable with empty value' \
343 'git config --bool emptyvalue.variable > output &&
344 cmp output expect'
345
003f69b2
JK
346test_expect_success 'no arguments, but no crash' '
347 test_must_fail git config >output 2>&1 &&
348 grep usage output
349'
2fa9a0fb 350
bd886fd3
SE
351cat > .git/config << EOF
352[a.b]
353 c = d
354EOF
355
5be60078 356git config a.x y
bd886fd3
SE
357
358cat > expect << EOF
359[a.b]
360 c = d
361[a]
362 x = y
363EOF
364
365test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
366
5be60078
JH
367git config b.x y
368git config a.b c
bd886fd3
SE
369
370cat > expect << EOF
371[a.b]
372 c = d
373[a]
374 x = y
375 b = c
376[b]
377 x = y
378EOF
379
380test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
381
773a69fb 382test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
003f69b2 383 'test_must_fail git config --file non-existing-config -l'
773a69fb 384
9c3796fc
JS
385cat > other-config << EOF
386[ein]
387 bahn = strasse
388EOF
389
390cat > expect << EOF
391ein.bahn=strasse
392EOF
393
5be60078 394GIT_CONFIG=other-config git config -l > output
9c3796fc
JS
395
396test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
397
773a69fb
AR
398test_expect_success 'alternative GIT_CONFIG (--file)' \
399 'git config --file other-config -l > output && cmp output expect'
400
5be60078 401GIT_CONFIG=other-config git config anwohner.park ausweis
9c3796fc
JS
402
403cat > expect << EOF
404[ein]
405 bahn = strasse
406[anwohner]
407 park = ausweis
408EOF
409
410test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
411
0667fcfb
JS
412cat > .git/config << EOF
413# Hallo
414 #Bello
415[branch "eins"]
416 x = 1
417[branch.eins]
418 y = 1
419 [branch "1 234 blabl/a"]
420weird
421EOF
422
423test_expect_success "rename section" \
5be60078 424 "git config --rename-section branch.eins branch.zwei"
0667fcfb
JS
425
426cat > expect << EOF
427# Hallo
428 #Bello
429[branch "zwei"]
430 x = 1
431[branch "zwei"]
432 y = 1
433 [branch "1 234 blabl/a"]
434weird
435EOF
436
3af82863 437test_expect_success "rename succeeded" "test_cmp expect .git/config"
0667fcfb 438
41ac414e 439test_expect_success "rename non-existing section" '
d492b31c
SB
440 test_must_fail git config --rename-section \
441 branch."world domination" branch.drei
41ac414e 442'
0667fcfb 443
3af82863 444test_expect_success "rename succeeded" "test_cmp expect .git/config"
0667fcfb
JS
445
446test_expect_success "rename another section" \
5be60078 447 'git config --rename-section branch."1 234 blabl/a" branch.drei'
0667fcfb
JS
448
449cat > expect << EOF
450# Hallo
451 #Bello
452[branch "zwei"]
453 x = 1
454[branch "zwei"]
455 y = 1
456[branch "drei"]
457weird
458EOF
459
3af82863 460test_expect_success "rename succeeded" "test_cmp expect .git/config"
9a5abfc7
AV
461
462cat >> .git/config << EOF
463[branch "vier"] z = 1
464EOF
465
466test_expect_success "rename a section with a var on the same line" \
467 'git config --rename-section branch.vier branch.zwei'
468
469cat > expect << EOF
470# Hallo
471 #Bello
472[branch "zwei"]
473 x = 1
474[branch "zwei"]
475 y = 1
476[branch "drei"]
477weird
478[branch "zwei"]
479 z = 1
480EOF
481
482test_expect_success "rename succeeded" "test_cmp expect .git/config"
0667fcfb 483
118f8b24
PB
484cat >> .git/config << EOF
485 [branch "zwei"] a = 1 [branch "vier"]
486EOF
487
488test_expect_success "remove section" "git config --remove-section branch.zwei"
489
490cat > expect << EOF
491# Hallo
492 #Bello
493[branch "drei"]
494weird
495EOF
496
497test_expect_success "section was removed properly" \
3af82863 498 "test_cmp expect .git/config"
118f8b24 499
b18a2be3
SP
500rm .git/config
501
502cat > expect << EOF
503[gitcvs]
504 enabled = true
505 dbname = %Ggitcvs2.%a.%m.sqlite
506[gitcvs "ext"]
507 dbname = %Ggitcvs1.%a.%m.sqlite
508EOF
509
510test_expect_success 'section ending' '
511
5be60078
JH
512 git config gitcvs.enabled true &&
513 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
514 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
b18a2be3
SP
515 cmp .git/config expect
516
517'
518
d77a64d3
SP
519test_expect_success numbers '
520
5be60078
JH
521 git config kilo.gram 1k &&
522 git config mega.ton 1m &&
523 k=$(git config --int --get kilo.gram) &&
d77a64d3 524 test z1024 = "z$k" &&
5be60078 525 m=$(git config --int --get mega.ton) &&
d77a64d3
SP
526 test z1048576 = "z$m"
527'
528
c8deb5a1
SP
529cat > expect <<EOF
530fatal: bad config value for 'aninvalid.unit' in .git/config
531EOF
532
533test_expect_success 'invalid unit' '
534
535 git config aninvalid.unit "1auto" &&
536 s=$(git config aninvalid.unit) &&
537 test "z1auto" = "z$s" &&
538 if git config --int --get aninvalid.unit 2>actual
539 then
540 echo config should have failed
541 false
542 fi &&
543 cmp actual expect
544'
545
cab333cb
FL
546cat > expect << EOF
547true
548false
549true
550false
551true
552false
553true
554false
555EOF
556
557test_expect_success bool '
558
5be60078
JH
559 git config bool.true1 01 &&
560 git config bool.true2 -1 &&
561 git config bool.true3 YeS &&
562 git config bool.true4 true &&
563 git config bool.false1 000 &&
564 git config bool.false2 "" &&
565 git config bool.false3 nO &&
566 git config bool.false4 FALSE &&
cab333cb
FL
567 rm -f result &&
568 for i in 1 2 3 4
569 do
5be60078
JH
570 git config --bool --get bool.true$i >>result
571 git config --bool --get bool.false$i >>result
cab333cb
FL
572 done &&
573 cmp expect result'
574
41ac414e 575test_expect_success 'invalid bool (--get)' '
cab333cb 576
5be60078 577 git config bool.nobool foobar &&
d492b31c 578 test_must_fail git config --bool --get bool.nobool'
cab333cb 579
41ac414e 580test_expect_success 'invalid bool (set)' '
db1696b8 581
d492b31c 582 test_must_fail git config --bool bool.nobool foobar'
db1696b8
FL
583
584rm .git/config
585
586cat > expect <<\EOF
587[bool]
588 true1 = true
589 true2 = true
590 true3 = true
591 true4 = true
592 false1 = false
593 false2 = false
594 false3 = false
595 false4 = false
596EOF
597
598test_expect_success 'set --bool' '
599
5be60078
JH
600 git config --bool bool.true1 01 &&
601 git config --bool bool.true2 -1 &&
602 git config --bool bool.true3 YeS &&
603 git config --bool bool.true4 true &&
604 git config --bool bool.false1 000 &&
605 git config --bool bool.false2 "" &&
606 git config --bool bool.false3 nO &&
607 git config --bool bool.false4 FALSE &&
db1696b8
FL
608 cmp expect .git/config'
609
610rm .git/config
611
612cat > expect <<\EOF
613[int]
614 val1 = 1
615 val2 = -1
616 val3 = 5242880
617EOF
618
619test_expect_success 'set --int' '
620
5be60078
JH
621 git config --int int.val1 01 &&
622 git config --int int.val2 -1 &&
623 git config --int int.val3 5m &&
db1696b8
FL
624 cmp expect .git/config'
625
cdd4fb15
BG
626rm .git/config
627
c35b0b58
JH
628cat >expect <<\EOF
629[bool]
630 true1 = true
631 true2 = true
632 false1 = false
633 false2 = false
634[int]
635 int1 = 0
636 int2 = 1
637 int3 = -1
638EOF
639
640test_expect_success 'get --bool-or-int' '
641 (
642 echo "[bool]"
643 echo true1
644 echo true2 = true
645 echo false = false
646 echo "[int]"
647 echo int1 = 0
648 echo int2 = 1
649 echo int3 = -1
650 ) >>.git/config &&
651 test $(git config --bool-or-int bool.true1) = true &&
652 test $(git config --bool-or-int bool.true2) = true &&
653 test $(git config --bool-or-int bool.false) = false &&
654 test $(git config --bool-or-int int.int1) = 0 &&
655 test $(git config --bool-or-int int.int2) = 1 &&
656 test $(git config --bool-or-int int.int3) = -1
657
658'
659
660rm .git/config
661cat >expect <<\EOF
662[bool]
663 true1 = true
664 false1 = false
665 true2 = true
666 false2 = false
667[int]
668 int1 = 0
669 int2 = 1
670 int3 = -1
671EOF
672
673test_expect_success 'set --bool-or-int' '
674 git config --bool-or-int bool.true1 true &&
675 git config --bool-or-int bool.false1 false &&
676 git config --bool-or-int bool.true2 yes &&
677 git config --bool-or-int bool.false2 no &&
678 git config --bool-or-int int.int1 0 &&
679 git config --bool-or-int int.int2 1 &&
680 git config --bool-or-int int.int3 -1 &&
681 test_cmp expect .git/config
682'
683
684rm .git/config
685
5be60078
JH
686git config quote.leading " test"
687git config quote.ending "test "
688git config quote.semicolon "test;test"
689git config quote.hash "test#test"
cdd4fb15
BG
690
691cat > expect << EOF
692[quote]
693 leading = " test"
694 ending = "test "
695 semicolon = "test;test"
696 hash = "test#test"
697EOF
698
699test_expect_success 'quoting' 'cmp .git/config expect'
700
41ac414e 701test_expect_success 'key with newline' '
d492b31c 702 test_must_fail git config "key.with
41ac414e 703newline" 123'
6f71686e 704
e0d10e1c 705test_expect_success 'value with newline' 'git config key.sub value.with\\\
6f71686e
JS
706newline'
707
83cd10a0
JN
708cat > .git/config <<\EOF
709[section]
710 ; comment \
711 continued = cont\
712inued
713 noncont = not continued ; \
714 quotecont = "cont;\
715inued"
716EOF
717
718cat > expect <<\EOF
719section.continued=continued
720section.noncont=not continued
721section.quotecont=cont;inued
722EOF
723
e0d10e1c 724git config --list > result
83cd10a0
JN
725
726test_expect_success 'value continued on next line' 'cmp result expect'
727
2275d502
FL
728cat > .git/config <<\EOF
729[section "sub=section"]
730 val1 = foo=bar
731 val2 = foo\nbar
732 val3 = \n\n
733 val4 =
734 val5
735EOF
736
737cat > expect <<\EOF
2b9a5020
AR
738section.sub=section.val1
739foo=barQsection.sub=section.val2
740foo
741barQsection.sub=section.val3
2275d502
FL
742
743
2b9a5020
AR
744Qsection.sub=section.val4
745Qsection.sub=section.val5Q
2275d502
FL
746EOF
747
e85fe4d8 748git config --null --list | perl -pe 'y/\000/Q/' > result
2b9a5020 749echo >>result
2275d502
FL
750
751test_expect_success '--null --list' 'cmp result expect'
752
e85fe4d8 753git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
2b9a5020 754echo >>result
2275d502
FL
755
756test_expect_success '--null --get-regexp' 'cmp result expect'
757
ebdaae37
BS
758test_expect_success 'inner whitespace kept verbatim' '
759 git config section.val "foo bar" &&
760 test "z$(git config section.val)" = "zfoo bar"
761'
762
704a3143 763test_expect_success SYMLINKS 'symlinked configuration' '
65a5a21d
JH
764
765 ln -s notyet myconfig &&
766 GIT_CONFIG=myconfig git config test.frotz nitfol &&
767 test -h myconfig &&
768 test -f notyet &&
769 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
770 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
771 test -h myconfig &&
772 test -f notyet &&
773 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
774 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
775
776'
777
dc4179f9
DM
778test_expect_success 'check split_cmdline return' "
779 git config alias.split-cmdline-fix 'echo \"' &&
780 test_must_fail git split-cmdline-fix &&
781 echo foo > foo &&
782 git add foo &&
783 git commit -m 'initial commit' &&
784 git config branch.master.mergeoptions 'echo \"' &&
785 test_must_fail git merge master
786 "
787
942c1f53 788test_done