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