t1300: attempting to remove a non-existent .git/config is not an error
[git/jnareb-git.git] / t / t1300-repo-config.sh
blob39e2244c1ff48f3a7929ba321484826428ce39ac
1 #!/bin/sh
3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test git config in different settings'
8 . ./test-lib.sh
10 test_expect_success 'clear default config' '
11 rm -f .git/config
14 cat > expect << EOF
15 [core]
16 penguin = little blue
17 EOF
18 test_expect_success 'initial' '
19 git config core.penguin "little blue" &&
20 test_cmp expect .git/config
23 cat > expect << EOF
24 [core]
25 penguin = little blue
26 Movie = BadPhysics
27 EOF
28 test_expect_success 'mixed case' '
29 git config Core.Movie BadPhysics &&
30 test_cmp expect .git/config
33 cat > expect << EOF
34 [core]
35 penguin = little blue
36 Movie = BadPhysics
37 [Cores]
38 WhatEver = Second
39 EOF
40 test_expect_success 'similar section' '
41 git config Cores.WhatEver Second
42 test_cmp expect .git/config
45 cat > expect << EOF
46 [core]
47 penguin = little blue
48 Movie = BadPhysics
49 UPPERCASE = true
50 [Cores]
51 WhatEver = Second
52 EOF
53 test_expect_success 'uppercase section' '
54 git config CORE.UPPERCASE true &&
55 test_cmp expect .git/config
58 test_expect_success 'replace with non-match' \
59 'git config core.penguin kingpin !blue'
61 test_expect_success 'replace with non-match (actually matching)' \
62 'git config core.penguin "very blue" !kingpin'
64 cat > expect << EOF
65 [core]
66 penguin = very blue
67 Movie = BadPhysics
68 UPPERCASE = true
69 penguin = kingpin
70 [Cores]
71 WhatEver = Second
72 EOF
74 test_expect_success 'non-match result' 'test_cmp expect .git/config'
76 test_expect_success 'find mixed-case key by canonical name' '
77 echo Second >expect &&
78 git config cores.whatever >actual &&
79 test_cmp expect actual
82 test_expect_success 'find mixed-case key by non-canonical name' '
83 echo Second >expect &&
84 git config CoReS.WhAtEvEr >actual &&
85 test_cmp expect actual
88 test_expect_success 'subsections are not canonicalized by git-config' '
89 cat >>.git/config <<-\EOF &&
90 [section.SubSection]
91 key = one
92 [section "SubSection"]
93 key = two
94 EOF
95 echo one >expect &&
96 git config section.subsection.key >actual &&
97 test_cmp expect actual &&
98 echo two >expect &&
99 git config section.SubSection.key >actual &&
100 test_cmp expect actual
103 cat > .git/config <<\EOF
104 [alpha]
105 bar = foo
106 [beta]
107 baz = multiple \
108 lines
111 test_expect_success 'unset with cont. lines' \
112 'git config --unset beta.baz'
114 cat > expect <<\EOF
115 [alpha]
116 bar = foo
117 [beta]
120 test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'
122 cat > .git/config << EOF
123 [beta] ; silly comment # another comment
124 noIndent= sillyValue ; 'nother silly comment
126 # empty line
127 ; comment
128 haha ="beta" # last silly comment
129 haha = hello
130 haha = bello
131 [nextSection] noNewline = ouch
134 cp .git/config .git/config2
136 test_expect_success 'multiple unset' \
137 'git config --unset-all beta.haha'
139 cat > expect << EOF
140 [beta] ; silly comment # another comment
141 noIndent= sillyValue ; 'nother silly comment
143 # empty line
144 ; comment
145 [nextSection] noNewline = ouch
148 test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config'
150 cp .git/config2 .git/config
152 test_expect_success '--replace-all missing value' '
153 test_must_fail git config --replace-all beta.haha &&
154 test_cmp .git/config2 .git/config
157 rm .git/config2
159 test_expect_success '--replace-all' \
160 'git config --replace-all beta.haha gamma'
162 cat > expect << EOF
163 [beta] ; silly comment # another comment
164 noIndent= sillyValue ; 'nother silly comment
166 # empty line
167 ; comment
168 haha = gamma
169 [nextSection] noNewline = ouch
172 test_expect_success 'all replaced' 'test_cmp expect .git/config'
174 cat > expect << EOF
175 [beta] ; silly comment # another comment
176 noIndent= sillyValue ; 'nother silly comment
178 # empty line
179 ; comment
180 haha = alpha
181 [nextSection] noNewline = ouch
183 test_expect_success 'really mean test' '
184 git config beta.haha alpha &&
185 test_cmp expect .git/config
188 cat > expect << EOF
189 [beta] ; silly comment # another comment
190 noIndent= sillyValue ; 'nother silly comment
192 # empty line
193 ; comment
194 haha = alpha
195 [nextSection]
196 nonewline = wow
198 test_expect_success 'really really mean test' '
199 git config nextsection.nonewline wow &&
200 test_cmp expect .git/config
203 test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
205 cat > expect << EOF
206 [beta] ; silly comment # another comment
207 noIndent= sillyValue ; 'nother silly comment
209 # empty line
210 ; comment
211 [nextSection]
212 nonewline = wow
214 test_expect_success 'unset' '
215 git config --unset beta.haha &&
216 test_cmp expect .git/config
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 = wow
227 NoNewLine = wow2 for me
229 test_expect_success 'multivar' '
230 git config nextsection.NoNewLine "wow2 for me" "for me$" &&
231 test_cmp expect .git/config
234 test_expect_success 'non-match' \
235 'git config --get nextsection.nonewline !for'
237 test_expect_success 'non-match value' \
238 'test wow = $(git config --get nextsection.nonewline !for)'
240 test_expect_success 'ambiguous get' '
241 test_must_fail git config --get nextsection.nonewline
244 test_expect_success 'get multivar' \
245 'git config --get-all nextsection.nonewline'
247 cat > expect << EOF
248 [beta] ; silly comment # another comment
249 noIndent= sillyValue ; 'nother silly comment
251 # empty line
252 ; comment
253 [nextSection]
254 nonewline = wow3
255 NoNewLine = wow2 for me
257 test_expect_success 'multivar replace' '
258 git config nextsection.nonewline "wow3" "wow$" &&
259 test_cmp expect .git/config
262 test_expect_success 'ambiguous value' '
263 test_must_fail git config nextsection.nonewline
266 test_expect_success 'ambiguous unset' '
267 test_must_fail git config --unset nextsection.nonewline
270 test_expect_success 'invalid unset' '
271 test_must_fail git config --unset somesection.nonewline
274 cat > expect << EOF
275 [beta] ; silly comment # another comment
276 noIndent= sillyValue ; 'nother silly comment
278 # empty line
279 ; comment
280 [nextSection]
281 NoNewLine = wow2 for me
284 test_expect_success 'multivar unset' '
285 git config --unset nextsection.nonewline "wow3$" &&
286 test_cmp expect .git/config
289 test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
291 test_expect_success 'correct key' 'git config 123456.a123 987'
293 test_expect_success 'hierarchical section' \
294 'git config Version.1.2.3eX.Alpha beta'
296 cat > expect << EOF
297 [beta] ; silly comment # another comment
298 noIndent= sillyValue ; 'nother silly comment
300 # empty line
301 ; comment
302 [nextSection]
303 NoNewLine = wow2 for me
304 [123456]
305 a123 = 987
306 [Version "1.2.3eX"]
307 Alpha = beta
310 test_expect_success 'hierarchical section value' 'test_cmp expect .git/config'
312 cat > expect << EOF
313 beta.noindent=sillyValue
314 nextsection.nonewline=wow2 for me
315 123456.a123=987
316 version.1.2.3eX.alpha=beta
319 test_expect_success 'working --list' \
320 'git config --list > output && cmp output expect'
322 cat > expect << EOF
325 test_expect_success '--list without repo produces empty output' '
326 git --git-dir=nonexistent config --list >output &&
327 test_cmp expect output
330 cat > expect << EOF
331 beta.noindent sillyValue
332 nextsection.nonewline wow2 for me
335 test_expect_success '--get-regexp' \
336 'git config --get-regexp in > output && cmp output expect'
338 cat > expect << EOF
339 wow2 for me
340 wow4 for you
343 test_expect_success '--add' '
344 git config --add nextsection.nonewline "wow4 for you" &&
345 git config --get-all nextsection.nonewline > output &&
346 test_cmp expect output
349 cat > .git/config << EOF
350 [novalue]
351 variable
352 [emptyvalue]
353 variable =
356 test_expect_success 'get variable with no value' \
357 'git config --get novalue.variable ^$'
359 test_expect_success 'get variable with empty value' \
360 'git config --get emptyvalue.variable ^$'
362 echo novalue.variable > expect
364 test_expect_success 'get-regexp variable with no value' \
365 'git config --get-regexp novalue > output &&
366 cmp output expect'
368 echo 'emptyvalue.variable ' > expect
370 test_expect_success 'get-regexp variable with empty value' \
371 'git config --get-regexp emptyvalue > output &&
372 cmp output expect'
374 echo true > expect
376 test_expect_success 'get bool variable with no value' \
377 'git config --bool novalue.variable > output &&
378 cmp output expect'
380 echo false > expect
382 test_expect_success 'get bool variable with empty value' \
383 'git config --bool emptyvalue.variable > output &&
384 cmp output expect'
386 test_expect_success 'no arguments, but no crash' '
387 test_must_fail git config >output 2>&1 &&
388 grep usage output
391 cat > .git/config << EOF
392 [a.b]
393 c = d
396 cat > expect << EOF
397 [a.b]
398 c = d
400 x = y
403 test_expect_success 'new section is partial match of another' '
404 git config a.x y &&
405 test_cmp expect .git/config
408 cat > expect << EOF
409 [a.b]
410 c = d
412 x = y
413 b = c
415 x = y
418 test_expect_success 'new variable inserts into proper section' '
419 git config b.x y &&
420 git config a.b c &&
421 test_cmp expect .git/config
424 test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
425 'test_must_fail git config --file non-existing-config -l'
427 cat > other-config << EOF
428 [ein]
429 bahn = strasse
432 cat > expect << EOF
433 ein.bahn=strasse
436 test_expect_success 'alternative GIT_CONFIG' '
437 GIT_CONFIG=other-config git config -l >output &&
438 test_cmp expect output
441 test_expect_success 'alternative GIT_CONFIG (--file)' \
442 'git config --file other-config -l > output && cmp output expect'
444 test_expect_success 'refer config from subdirectory' '
445 mkdir x &&
447 cd x &&
448 echo strasse >expect
449 git config --get --file ../other-config ein.bahn >actual &&
450 test_cmp expect actual
455 cat > expect << EOF
456 [ein]
457 bahn = strasse
458 [anwohner]
459 park = ausweis
462 test_expect_success '--set in alternative GIT_CONFIG' '
463 GIT_CONFIG=other-config git config anwohner.park ausweis &&
464 test_cmp expect other-config
467 cat > .git/config << EOF
468 # Hallo
469 #Bello
470 [branch "eins"]
471 x = 1
472 [branch.eins]
473 y = 1
474 [branch "1 234 blabl/a"]
475 weird
478 test_expect_success "rename section" \
479 "git config --rename-section branch.eins branch.zwei"
481 cat > expect << EOF
482 # Hallo
483 #Bello
484 [branch "zwei"]
485 x = 1
486 [branch "zwei"]
487 y = 1
488 [branch "1 234 blabl/a"]
489 weird
492 test_expect_success "rename succeeded" "test_cmp expect .git/config"
494 test_expect_success "rename non-existing section" '
495 test_must_fail git config --rename-section \
496 branch."world domination" branch.drei
499 test_expect_success "rename succeeded" "test_cmp expect .git/config"
501 test_expect_success "rename another section" \
502 'git config --rename-section branch."1 234 blabl/a" branch.drei'
504 cat > expect << EOF
505 # Hallo
506 #Bello
507 [branch "zwei"]
508 x = 1
509 [branch "zwei"]
510 y = 1
511 [branch "drei"]
512 weird
515 test_expect_success "rename succeeded" "test_cmp expect .git/config"
517 cat >> .git/config << EOF
518 [branch "vier"] z = 1
521 test_expect_success "rename a section with a var on the same line" \
522 'git config --rename-section branch.vier branch.zwei'
524 cat > expect << EOF
525 # Hallo
526 #Bello
527 [branch "zwei"]
528 x = 1
529 [branch "zwei"]
530 y = 1
531 [branch "drei"]
532 weird
533 [branch "zwei"]
534 z = 1
537 test_expect_success "rename succeeded" "test_cmp expect .git/config"
539 cat >> .git/config << EOF
540 [branch "zwei"] a = 1 [branch "vier"]
543 test_expect_success "remove section" "git config --remove-section branch.zwei"
545 cat > expect << EOF
546 # Hallo
547 #Bello
548 [branch "drei"]
549 weird
552 test_expect_success "section was removed properly" \
553 "test_cmp expect .git/config"
555 cat > expect << EOF
556 [gitcvs]
557 enabled = true
558 dbname = %Ggitcvs2.%a.%m.sqlite
559 [gitcvs "ext"]
560 dbname = %Ggitcvs1.%a.%m.sqlite
563 test_expect_success 'section ending' '
565 rm -f .git/config &&
566 git config gitcvs.enabled true &&
567 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
568 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
569 test_cmp expect .git/config
573 test_expect_success numbers '
575 git config kilo.gram 1k &&
576 git config mega.ton 1m &&
577 k=$(git config --int --get kilo.gram) &&
578 test z1024 = "z$k" &&
579 m=$(git config --int --get mega.ton) &&
580 test z1048576 = "z$m"
583 cat > expect <<EOF
584 fatal: bad config value for 'aninvalid.unit' in .git/config
587 test_expect_success 'invalid unit' '
589 git config aninvalid.unit "1auto" &&
590 s=$(git config aninvalid.unit) &&
591 test "z1auto" = "z$s" &&
592 if git config --int --get aninvalid.unit 2>actual
593 then
594 echo config should have failed
595 false
596 fi &&
597 cmp actual expect
600 cat > expect << EOF
601 true
602 false
603 true
604 false
605 true
606 false
607 true
608 false
611 test_expect_success bool '
613 git config bool.true1 01 &&
614 git config bool.true2 -1 &&
615 git config bool.true3 YeS &&
616 git config bool.true4 true &&
617 git config bool.false1 000 &&
618 git config bool.false2 "" &&
619 git config bool.false3 nO &&
620 git config bool.false4 FALSE &&
621 rm -f result &&
622 for i in 1 2 3 4
624 git config --bool --get bool.true$i >>result
625 git config --bool --get bool.false$i >>result
626 done &&
627 cmp expect result'
629 test_expect_success 'invalid bool (--get)' '
631 git config bool.nobool foobar &&
632 test_must_fail git config --bool --get bool.nobool'
634 test_expect_success 'invalid bool (set)' '
636 test_must_fail git config --bool bool.nobool foobar'
638 cat > expect <<\EOF
639 [bool]
640 true1 = true
641 true2 = true
642 true3 = true
643 true4 = true
644 false1 = false
645 false2 = false
646 false3 = false
647 false4 = false
650 test_expect_success 'set --bool' '
652 rm -f .git/config &&
653 git config --bool bool.true1 01 &&
654 git config --bool bool.true2 -1 &&
655 git config --bool bool.true3 YeS &&
656 git config --bool bool.true4 true &&
657 git config --bool bool.false1 000 &&
658 git config --bool bool.false2 "" &&
659 git config --bool bool.false3 nO &&
660 git config --bool bool.false4 FALSE &&
661 cmp expect .git/config'
663 cat > expect <<\EOF
664 [int]
665 val1 = 1
666 val2 = -1
667 val3 = 5242880
670 test_expect_success 'set --int' '
672 rm -f .git/config &&
673 git config --int int.val1 01 &&
674 git config --int int.val2 -1 &&
675 git config --int int.val3 5m &&
676 cmp expect .git/config'
678 cat >expect <<\EOF
679 [bool]
680 true1 = true
681 true2 = true
682 false1 = false
683 false2 = false
684 [int]
685 int1 = 0
686 int2 = 1
687 int3 = -1
690 test_expect_success 'get --bool-or-int' '
691 rm -f .git/config &&
693 echo "[bool]"
694 echo true1
695 echo true2 = true
696 echo false = false
697 echo "[int]"
698 echo int1 = 0
699 echo int2 = 1
700 echo int3 = -1
701 ) >>.git/config &&
702 test $(git config --bool-or-int bool.true1) = true &&
703 test $(git config --bool-or-int bool.true2) = true &&
704 test $(git config --bool-or-int bool.false) = false &&
705 test $(git config --bool-or-int int.int1) = 0 &&
706 test $(git config --bool-or-int int.int2) = 1 &&
707 test $(git config --bool-or-int int.int3) = -1
711 cat >expect <<\EOF
712 [bool]
713 true1 = true
714 false1 = false
715 true2 = true
716 false2 = false
717 [int]
718 int1 = 0
719 int2 = 1
720 int3 = -1
723 test_expect_success 'set --bool-or-int' '
724 rm -f .git/config &&
725 git config --bool-or-int bool.true1 true &&
726 git config --bool-or-int bool.false1 false &&
727 git config --bool-or-int bool.true2 yes &&
728 git config --bool-or-int bool.false2 no &&
729 git config --bool-or-int int.int1 0 &&
730 git config --bool-or-int int.int2 1 &&
731 git config --bool-or-int int.int3 -1 &&
732 test_cmp expect .git/config
735 cat >expect <<\EOF
736 [path]
737 home = ~/
738 normal = /dev/null
739 trailingtilde = foo~
742 test_expect_success NOT_MINGW 'set --path' '
743 rm -f .git/config &&
744 git config --path path.home "~/" &&
745 git config --path path.normal "/dev/null" &&
746 git config --path path.trailingtilde "foo~" &&
747 test_cmp expect .git/config'
749 if test_have_prereq NOT_MINGW && test "${HOME+set}"
750 then
751 test_set_prereq HOMEVAR
754 cat >expect <<EOF
755 $HOME/
756 /dev/null
757 foo~
760 test_expect_success HOMEVAR 'get --path' '
761 git config --get --path path.home > result &&
762 git config --get --path path.normal >> result &&
763 git config --get --path path.trailingtilde >> result &&
764 test_cmp expect result
767 cat >expect <<\EOF
768 /dev/null
769 foo~
772 test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
774 unset HOME;
775 test_must_fail git config --get --path path.home \
776 >result 2>msg &&
777 git config --get --path path.normal >>result &&
778 git config --get --path path.trailingtilde >>result
779 ) &&
780 grep "[Ff]ailed to expand.*~/" msg &&
781 test_cmp expect result
784 cat > expect << EOF
785 [quote]
786 leading = " test"
787 ending = "test "
788 semicolon = "test;test"
789 hash = "test#test"
791 test_expect_success 'quoting' '
792 rm -f .git/config &&
793 git config quote.leading " test" &&
794 git config quote.ending "test " &&
795 git config quote.semicolon "test;test" &&
796 git config quote.hash "test#test" &&
797 test_cmp expect .git/config
800 test_expect_success 'key with newline' '
801 test_must_fail git config "key.with
802 newline" 123'
804 test_expect_success 'value with newline' 'git config key.sub value.with\\\
805 newline'
807 cat > .git/config <<\EOF
808 [section]
809 ; comment \
810 continued = cont\
811 inued
812 noncont = not continued ; \
813 quotecont = "cont;\
814 inued"
817 cat > expect <<\EOF
818 section.continued=continued
819 section.noncont=not continued
820 section.quotecont=cont;inued
823 test_expect_success 'value continued on next line' '
824 git config --list > result &&
825 cmp result expect
828 cat > .git/config <<\EOF
829 [section "sub=section"]
830 val1 = foo=bar
831 val2 = foo\nbar
832 val3 = \n\n
833 val4 =
834 val5
837 cat > expect <<\EOF
838 section.sub=section.val1
839 foo=barQsection.sub=section.val2
841 barQsection.sub=section.val3
844 Qsection.sub=section.val4
845 Qsection.sub=section.val5Q
847 test_expect_success '--null --list' '
848 git config --null --list | nul_to_q >result &&
849 echo >>result &&
850 test_cmp expect result
853 test_expect_success '--null --get-regexp' '
854 git config --null --get-regexp "val[0-9]" | nul_to_q >result &&
855 echo >>result &&
856 test_cmp expect result
859 test_expect_success 'inner whitespace kept verbatim' '
860 git config section.val "foo bar" &&
861 test "z$(git config section.val)" = "zfoo bar"
864 test_expect_success SYMLINKS 'symlinked configuration' '
866 ln -s notyet myconfig &&
867 GIT_CONFIG=myconfig git config test.frotz nitfol &&
868 test -h myconfig &&
869 test -f notyet &&
870 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
871 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
872 test -h myconfig &&
873 test -f notyet &&
874 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
875 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
879 test_expect_success 'nonexistent configuration' '
881 GIT_CONFIG=doesnotexist &&
882 export GIT_CONFIG &&
883 test_must_fail git config --list &&
884 test_must_fail git config test.xyzzy
888 test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
889 ln -s doesnotexist linktonada &&
890 ln -s linktonada linktolinktonada &&
892 GIT_CONFIG=linktonada &&
893 export GIT_CONFIG &&
894 test_must_fail git config --list &&
895 GIT_CONFIG=linktolinktonada &&
896 test_must_fail git config --list
900 test_expect_success 'check split_cmdline return' "
901 git config alias.split-cmdline-fix 'echo \"' &&
902 test_must_fail git split-cmdline-fix &&
903 echo foo > foo &&
904 git add foo &&
905 git commit -m 'initial commit' &&
906 git config branch.master.mergeoptions 'echo \"' &&
907 test_must_fail git merge master
910 test_expect_success 'git -c "key=value" support' '
911 test "z$(git -c core.name=value config core.name)" = zvalue &&
912 test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue &&
913 test "z$(git -c foo.flag config --bool foo.flag)" = ztrue &&
914 test_must_fail git -c name=value config core.name
917 test_expect_success 'key sanity-checking' '
918 test_must_fail git config foo=bar &&
919 test_must_fail git config foo=.bar &&
920 test_must_fail git config foo.ba=r &&
921 test_must_fail git config foo.1bar &&
922 test_must_fail git config foo."ba
923 z".bar &&
924 test_must_fail git config . false &&
925 test_must_fail git config .foo false &&
926 test_must_fail git config foo. false &&
927 test_must_fail git config .foo. false &&
928 git config foo.bar true &&
929 git config foo."ba =z".bar false
932 test_expect_success 'git -c works with aliases of builtins' '
933 git config alias.checkconfig "-c foo.check=bar config foo.check" &&
934 echo bar >expect &&
935 git checkconfig >actual &&
936 test_cmp expect actual
939 test_expect_success 'git -c does not split values on equals' '
940 echo "value with = in it" >expect &&
941 git -c core.foo="value with = in it" config core.foo >actual &&
942 test_cmp expect actual
945 test_expect_success 'git -c dies on bogus config' '
946 test_must_fail git -c core.bare=foo rev-parse
949 test_expect_success 'git -c complains about empty key' '
950 test_must_fail git -c "=foo" rev-parse
953 test_expect_success 'git -c complains about empty key and value' '
954 test_must_fail git -c "" rev-parse
957 test_done