builtin-config: Fix crash when using "-f <relative path>" from non-root dir
[git/gitweb.git] / t / t1300-repo-config.sh
blobc81ccf2e56659b41787b9da69acbb3bf9f44f984
1 #!/bin/sh
3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test git config in different settings'
8 . ./test-lib.sh
10 test -f .git/config && rm .git/config
12 git config core.penguin "little blue"
14 cat > expect << EOF
15 [core]
16 penguin = little blue
17 EOF
19 test_expect_success 'initial' 'cmp .git/config expect'
21 git config Core.Movie BadPhysics
23 cat > expect << EOF
24 [core]
25 penguin = little blue
26 Movie = BadPhysics
27 EOF
29 test_expect_success 'mixed case' 'cmp .git/config expect'
31 git config Cores.WhatEver Second
33 cat > expect << EOF
34 [core]
35 penguin = little blue
36 Movie = BadPhysics
37 [Cores]
38 WhatEver = Second
39 EOF
41 test_expect_success 'similar section' 'cmp .git/config expect'
43 git config CORE.UPPERCASE true
45 cat > expect << EOF
46 [core]
47 penguin = little blue
48 Movie = BadPhysics
49 UPPERCASE = true
50 [Cores]
51 WhatEver = Second
52 EOF
54 test_expect_success 'similar section' 'cmp .git/config expect'
56 test_expect_success 'replace with non-match' \
57 'git config core.penguin kingpin !blue'
59 test_expect_success 'replace with non-match (actually matching)' \
60 'git config core.penguin "very blue" !kingpin'
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
72 test_expect_success 'non-match result' 'cmp .git/config expect'
74 cat > .git/config <<\EOF
75 [alpha]
76 bar = foo
77 [beta]
78 baz = multiple \
79 lines
80 EOF
82 test_expect_success 'unset with cont. lines' \
83 'git config --unset beta.baz'
85 cat > expect <<\EOF
86 [alpha]
87 bar = foo
88 [beta]
89 EOF
91 test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
93 cat > .git/config << EOF
94 [beta] ; silly comment # another comment
95 noIndent= sillyValue ; 'nother silly comment
97 # empty line
98 ; comment
99 haha ="beta" # last silly comment
100 haha = hello
101 haha = bello
102 [nextSection] noNewline = ouch
105 cp .git/config .git/config2
107 test_expect_success 'multiple unset' \
108 'git config --unset-all beta.haha'
110 cat > expect << EOF
111 [beta] ; silly comment # another comment
112 noIndent= sillyValue ; 'nother silly comment
114 # empty line
115 ; comment
116 [nextSection] noNewline = ouch
119 test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
121 cp .git/config2 .git/config
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
128 rm .git/config2
130 test_expect_success '--replace-all' \
131 'git config --replace-all beta.haha gamma'
133 cat > expect << EOF
134 [beta] ; silly comment # another comment
135 noIndent= sillyValue ; 'nother silly comment
137 # empty line
138 ; comment
139 haha = gamma
140 [nextSection] noNewline = ouch
143 test_expect_success 'all replaced' 'cmp .git/config expect'
145 git config beta.haha alpha
147 cat > expect << EOF
148 [beta] ; silly comment # another comment
149 noIndent= sillyValue ; 'nother silly comment
151 # empty line
152 ; comment
153 haha = alpha
154 [nextSection] noNewline = ouch
157 test_expect_success 'really mean test' 'cmp .git/config expect'
159 git config nextsection.nonewline wow
161 cat > expect << EOF
162 [beta] ; silly comment # another comment
163 noIndent= sillyValue ; 'nother silly comment
165 # empty line
166 ; comment
167 haha = alpha
168 [nextSection]
169 nonewline = wow
172 test_expect_success 'really really mean test' 'cmp .git/config expect'
174 test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
175 git config --unset beta.haha
177 cat > expect << EOF
178 [beta] ; silly comment # another comment
179 noIndent= sillyValue ; 'nother silly comment
181 # empty line
182 ; comment
183 [nextSection]
184 nonewline = wow
187 test_expect_success 'unset' 'cmp .git/config expect'
189 git config nextsection.NoNewLine "wow2 for me" "for me$"
191 cat > expect << EOF
192 [beta] ; silly comment # another comment
193 noIndent= sillyValue ; 'nother silly comment
195 # empty line
196 ; comment
197 [nextSection]
198 nonewline = wow
199 NoNewLine = wow2 for me
202 test_expect_success 'multivar' 'cmp .git/config expect'
204 test_expect_success 'non-match' \
205 'git config --get nextsection.nonewline !for'
207 test_expect_success 'non-match value' \
208 'test wow = $(git config --get nextsection.nonewline !for)'
210 test_expect_success 'ambiguous get' '
211 test_must_fail git config --get nextsection.nonewline
214 test_expect_success 'get multivar' \
215 'git config --get-all nextsection.nonewline'
217 git config nextsection.nonewline "wow3" "wow$"
219 cat > expect << EOF
220 [beta] ; silly comment # another comment
221 noIndent= sillyValue ; 'nother silly comment
223 # empty line
224 ; comment
225 [nextSection]
226 nonewline = wow3
227 NoNewLine = wow2 for me
230 test_expect_success 'multivar replace' 'cmp .git/config expect'
232 test_expect_success 'ambiguous value' '
233 test_must_fail git config nextsection.nonewline
236 test_expect_success 'ambiguous unset' '
237 test_must_fail git config --unset nextsection.nonewline
240 test_expect_success 'invalid unset' '
241 test_must_fail git config --unset somesection.nonewline
244 git config --unset nextsection.nonewline "wow3$"
246 cat > expect << EOF
247 [beta] ; silly comment # another comment
248 noIndent= sillyValue ; 'nother silly comment
250 # empty line
251 ; comment
252 [nextSection]
253 NoNewLine = wow2 for me
256 test_expect_success 'multivar unset' 'cmp .git/config expect'
258 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
260 test_expect_success 'correct key' 'git config 123456.a123 987'
262 test_expect_success 'hierarchical section' \
263 'git config Version.1.2.3eX.Alpha beta'
265 cat > expect << EOF
266 [beta] ; silly comment # another comment
267 noIndent= sillyValue ; 'nother silly comment
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
279 test_expect_success 'hierarchical section value' 'cmp .git/config expect'
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
288 test_expect_success 'working --list' \
289 'git config --list > output && cmp output expect'
291 cat > expect << EOF
292 beta.noindent sillyValue
293 nextsection.nonewline wow2 for me
296 test_expect_success '--get-regexp' \
297 'git config --get-regexp in > output && cmp output expect'
299 git config --add nextsection.nonewline "wow4 for you"
301 cat > expect << EOF
302 wow2 for me
303 wow4 for you
306 test_expect_success '--add' \
307 'git config --get-all nextsection.nonewline > output && cmp output expect'
309 cat > .git/config << EOF
310 [novalue]
311 variable
312 [emptyvalue]
313 variable =
316 test_expect_success 'get variable with no value' \
317 'git config --get novalue.variable ^$'
319 test_expect_success 'get variable with empty value' \
320 'git config --get emptyvalue.variable ^$'
322 echo novalue.variable > expect
324 test_expect_success 'get-regexp variable with no value' \
325 'git config --get-regexp novalue > output &&
326 cmp output expect'
328 echo 'emptyvalue.variable ' > expect
330 test_expect_success 'get-regexp variable with empty value' \
331 'git config --get-regexp emptyvalue > output &&
332 cmp output expect'
334 echo true > expect
336 test_expect_success 'get bool variable with no value' \
337 'git config --bool novalue.variable > output &&
338 cmp output expect'
340 echo false > expect
342 test_expect_success 'get bool variable with empty value' \
343 'git config --bool emptyvalue.variable > output &&
344 cmp output expect'
346 test_expect_success 'no arguments, but no crash' '
347 test_must_fail git config >output 2>&1 &&
348 grep usage output
351 cat > .git/config << EOF
352 [a.b]
353 c = d
356 git config a.x y
358 cat > expect << EOF
359 [a.b]
360 c = d
362 x = y
365 test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
367 git config b.x y
368 git config a.b c
370 cat > expect << EOF
371 [a.b]
372 c = d
374 x = y
375 b = c
377 x = y
380 test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
382 test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
383 'test_must_fail git config --file non-existing-config -l'
385 cat > other-config << EOF
386 [ein]
387 bahn = strasse
390 cat > expect << EOF
391 ein.bahn=strasse
394 GIT_CONFIG=other-config git config -l > output
396 test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
398 test_expect_success 'alternative GIT_CONFIG (--file)' \
399 'git config --file other-config -l > output && cmp output expect'
401 test_expect_success 'refer config from subdirectory' '
402 mkdir x &&
404 cd x &&
405 echo strasse >expect
406 git config --get --file ../other-config ein.bahn >actual &&
407 test_cmp expect actual
412 GIT_CONFIG=other-config git config anwohner.park ausweis
414 cat > expect << EOF
415 [ein]
416 bahn = strasse
417 [anwohner]
418 park = ausweis
421 test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
423 cat > .git/config << EOF
424 # Hallo
425 #Bello
426 [branch "eins"]
427 x = 1
428 [branch.eins]
429 y = 1
430 [branch "1 234 blabl/a"]
431 weird
434 test_expect_success "rename section" \
435 "git config --rename-section branch.eins branch.zwei"
437 cat > expect << EOF
438 # Hallo
439 #Bello
440 [branch "zwei"]
441 x = 1
442 [branch "zwei"]
443 y = 1
444 [branch "1 234 blabl/a"]
445 weird
448 test_expect_success "rename succeeded" "test_cmp expect .git/config"
450 test_expect_success "rename non-existing section" '
451 test_must_fail git config --rename-section \
452 branch."world domination" branch.drei
455 test_expect_success "rename succeeded" "test_cmp expect .git/config"
457 test_expect_success "rename another section" \
458 'git config --rename-section branch."1 234 blabl/a" branch.drei'
460 cat > expect << EOF
461 # Hallo
462 #Bello
463 [branch "zwei"]
464 x = 1
465 [branch "zwei"]
466 y = 1
467 [branch "drei"]
468 weird
471 test_expect_success "rename succeeded" "test_cmp expect .git/config"
473 cat >> .git/config << EOF
474 [branch "zwei"] a = 1 [branch "vier"]
477 test_expect_success "remove section" "git config --remove-section branch.zwei"
479 cat > expect << EOF
480 # Hallo
481 #Bello
482 [branch "drei"]
483 weird
486 test_expect_success "section was removed properly" \
487 "test_cmp expect .git/config"
489 rm .git/config
491 cat > expect << EOF
492 [gitcvs]
493 enabled = true
494 dbname = %Ggitcvs2.%a.%m.sqlite
495 [gitcvs "ext"]
496 dbname = %Ggitcvs1.%a.%m.sqlite
499 test_expect_success 'section ending' '
501 git config gitcvs.enabled true &&
502 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
503 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
504 cmp .git/config expect
508 test_expect_success numbers '
510 git config kilo.gram 1k &&
511 git config mega.ton 1m &&
512 k=$(git config --int --get kilo.gram) &&
513 test z1024 = "z$k" &&
514 m=$(git config --int --get mega.ton) &&
515 test z1048576 = "z$m"
518 cat > expect <<EOF
519 fatal: bad config value for 'aninvalid.unit' in .git/config
522 test_expect_success 'invalid unit' '
524 git config aninvalid.unit "1auto" &&
525 s=$(git config aninvalid.unit) &&
526 test "z1auto" = "z$s" &&
527 if git config --int --get aninvalid.unit 2>actual
528 then
529 echo config should have failed
530 false
531 fi &&
532 cmp actual expect
535 cat > expect << EOF
536 true
537 false
538 true
539 false
540 true
541 false
542 true
543 false
546 test_expect_success bool '
548 git config bool.true1 01 &&
549 git config bool.true2 -1 &&
550 git config bool.true3 YeS &&
551 git config bool.true4 true &&
552 git config bool.false1 000 &&
553 git config bool.false2 "" &&
554 git config bool.false3 nO &&
555 git config bool.false4 FALSE &&
556 rm -f result &&
557 for i in 1 2 3 4
559 git config --bool --get bool.true$i >>result
560 git config --bool --get bool.false$i >>result
561 done &&
562 cmp expect result'
564 test_expect_success 'invalid bool (--get)' '
566 git config bool.nobool foobar &&
567 test_must_fail git config --bool --get bool.nobool'
569 test_expect_success 'invalid bool (set)' '
571 test_must_fail git config --bool bool.nobool foobar'
573 rm .git/config
575 cat > expect <<\EOF
576 [bool]
577 true1 = true
578 true2 = true
579 true3 = true
580 true4 = true
581 false1 = false
582 false2 = false
583 false3 = false
584 false4 = false
587 test_expect_success 'set --bool' '
589 git config --bool bool.true1 01 &&
590 git config --bool bool.true2 -1 &&
591 git config --bool bool.true3 YeS &&
592 git config --bool bool.true4 true &&
593 git config --bool bool.false1 000 &&
594 git config --bool bool.false2 "" &&
595 git config --bool bool.false3 nO &&
596 git config --bool bool.false4 FALSE &&
597 cmp expect .git/config'
599 rm .git/config
601 cat > expect <<\EOF
602 [int]
603 val1 = 1
604 val2 = -1
605 val3 = 5242880
608 test_expect_success 'set --int' '
610 git config --int int.val1 01 &&
611 git config --int int.val2 -1 &&
612 git config --int int.val3 5m &&
613 cmp expect .git/config'
615 rm .git/config
617 cat >expect <<\EOF
618 [bool]
619 true1 = true
620 true2 = true
621 false1 = false
622 false2 = false
623 [int]
624 int1 = 0
625 int2 = 1
626 int3 = -1
629 test_expect_success 'get --bool-or-int' '
631 echo "[bool]"
632 echo true1
633 echo true2 = true
634 echo false = false
635 echo "[int]"
636 echo int1 = 0
637 echo int2 = 1
638 echo int3 = -1
639 ) >>.git/config &&
640 test $(git config --bool-or-int bool.true1) = true &&
641 test $(git config --bool-or-int bool.true2) = true &&
642 test $(git config --bool-or-int bool.false) = false &&
643 test $(git config --bool-or-int int.int1) = 0 &&
644 test $(git config --bool-or-int int.int2) = 1 &&
645 test $(git config --bool-or-int int.int3) = -1
649 rm .git/config
650 cat >expect <<\EOF
651 [bool]
652 true1 = true
653 false1 = false
654 true2 = true
655 false2 = false
656 [int]
657 int1 = 0
658 int2 = 1
659 int3 = -1
662 test_expect_success 'set --bool-or-int' '
663 git config --bool-or-int bool.true1 true &&
664 git config --bool-or-int bool.false1 false &&
665 git config --bool-or-int bool.true2 yes &&
666 git config --bool-or-int bool.false2 no &&
667 git config --bool-or-int int.int1 0 &&
668 git config --bool-or-int int.int2 1 &&
669 git config --bool-or-int int.int3 -1 &&
670 test_cmp expect .git/config
673 rm .git/config
675 git config quote.leading " test"
676 git config quote.ending "test "
677 git config quote.semicolon "test;test"
678 git config quote.hash "test#test"
680 cat > expect << EOF
681 [quote]
682 leading = " test"
683 ending = "test "
684 semicolon = "test;test"
685 hash = "test#test"
688 test_expect_success 'quoting' 'cmp .git/config expect'
690 test_expect_success 'key with newline' '
691 test_must_fail git config "key.with
692 newline" 123'
694 test_expect_success 'value with newline' 'git config key.sub value.with\\\
695 newline'
697 cat > .git/config <<\EOF
698 [section]
699 ; comment \
700 continued = cont\
701 inued
702 noncont = not continued ; \
703 quotecont = "cont;\
704 inued"
707 cat > expect <<\EOF
708 section.continued=continued
709 section.noncont=not continued
710 section.quotecont=cont;inued
713 git config --list > result
715 test_expect_success 'value continued on next line' 'cmp result expect'
717 cat > .git/config <<\EOF
718 [section "sub=section"]
719 val1 = foo=bar
720 val2 = foo\nbar
721 val3 = \n\n
722 val4 =
723 val5
726 cat > expect <<\EOF
727 section.sub=section.val1
728 foo=barQsection.sub=section.val2
730 barQsection.sub=section.val3
733 Qsection.sub=section.val4
734 Qsection.sub=section.val5Q
737 git config --null --list | perl -pe 'y/\000/Q/' > result
738 echo >>result
740 test_expect_success '--null --list' 'cmp result expect'
742 git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
743 echo >>result
745 test_expect_success '--null --get-regexp' 'cmp result expect'
747 test_expect_success SYMLINKS 'symlinked configuration' '
749 ln -s notyet myconfig &&
750 GIT_CONFIG=myconfig git config test.frotz nitfol &&
751 test -h myconfig &&
752 test -f notyet &&
753 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
754 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
755 test -h myconfig &&
756 test -f notyet &&
757 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
758 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
762 test_expect_success 'check split_cmdline return' "
763 git config alias.split-cmdline-fix 'echo \"' &&
764 test_must_fail git split-cmdline-fix &&
765 echo foo > foo &&
766 git add foo &&
767 git commit -m 'initial commit' &&
768 git config branch.master.mergeoptions 'echo \"' &&
769 test_must_fail git merge master
772 test_done