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