]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1300-repo-config.sh
Merge branch 'maint' of git://repo.or.cz/git-gui into maint
[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 mv .git/config2 .git/config
122
123 test_expect_success '--replace-all' \
124 'git config --replace-all beta.haha gamma'
125
126 cat > expect << EOF
127 [beta] ; silly comment # another comment
128 noIndent= sillyValue ; 'nother silly comment
129
130 # empty line
131 ; comment
132 haha = gamma
133 [nextSection] noNewline = ouch
134 EOF
135
136 test_expect_success 'all replaced' 'cmp .git/config expect'
137
138 git config beta.haha alpha
139
140 cat > expect << EOF
141 [beta] ; silly comment # another comment
142 noIndent= sillyValue ; 'nother silly comment
143
144 # empty line
145 ; comment
146 haha = alpha
147 [nextSection] noNewline = ouch
148 EOF
149
150 test_expect_success 'really mean test' 'cmp .git/config expect'
151
152 git config nextsection.nonewline wow
153
154 cat > expect << EOF
155 [beta] ; silly comment # another comment
156 noIndent= sillyValue ; 'nother silly comment
157
158 # empty line
159 ; comment
160 haha = alpha
161 [nextSection]
162 nonewline = wow
163 EOF
164
165 test_expect_success 'really really mean test' 'cmp .git/config expect'
166
167 test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
168 git config --unset beta.haha
169
170 cat > expect << EOF
171 [beta] ; silly comment # another comment
172 noIndent= sillyValue ; 'nother silly comment
173
174 # empty line
175 ; comment
176 [nextSection]
177 nonewline = wow
178 EOF
179
180 test_expect_success 'unset' 'cmp .git/config expect'
181
182 git config nextsection.NoNewLine "wow2 for me" "for me$"
183
184 cat > expect << EOF
185 [beta] ; silly comment # another comment
186 noIndent= sillyValue ; 'nother silly comment
187
188 # empty line
189 ; comment
190 [nextSection]
191 nonewline = wow
192 NoNewLine = wow2 for me
193 EOF
194
195 test_expect_success 'multivar' 'cmp .git/config expect'
196
197 test_expect_success 'non-match' \
198 'git config --get nextsection.nonewline !for'
199
200 test_expect_success 'non-match value' \
201 'test wow = $(git config --get nextsection.nonewline !for)'
202
203 test_expect_failure 'ambiguous get' \
204 'git config --get nextsection.nonewline'
205
206 test_expect_success 'get multivar' \
207 'git config --get-all nextsection.nonewline'
208
209 git config nextsection.nonewline "wow3" "wow$"
210
211 cat > expect << EOF
212 [beta] ; silly comment # another comment
213 noIndent= sillyValue ; 'nother silly comment
214
215 # empty line
216 ; comment
217 [nextSection]
218 nonewline = wow3
219 NoNewLine = wow2 for me
220 EOF
221
222 test_expect_success 'multivar replace' 'cmp .git/config expect'
223
224 test_expect_failure 'ambiguous value' 'git config nextsection.nonewline'
225
226 test_expect_failure 'ambiguous unset' \
227 'git config --unset nextsection.nonewline'
228
229 test_expect_failure 'invalid unset' \
230 'git config --unset somesection.nonewline'
231
232 git config --unset nextsection.nonewline "wow3$"
233
234 cat > expect << EOF
235 [beta] ; silly comment # another comment
236 noIndent= sillyValue ; 'nother silly comment
237
238 # empty line
239 ; comment
240 [nextSection]
241 NoNewLine = wow2 for me
242 EOF
243
244 test_expect_success 'multivar unset' 'cmp .git/config expect'
245
246 test_expect_failure 'invalid key' 'git config inval.2key blabla'
247
248 test_expect_success 'correct key' 'git config 123456.a123 987'
249
250 test_expect_success 'hierarchical section' \
251 'git config Version.1.2.3eX.Alpha beta'
252
253 cat > expect << EOF
254 [beta] ; silly comment # another comment
255 noIndent= sillyValue ; 'nother silly comment
256
257 # empty line
258 ; comment
259 [nextSection]
260 NoNewLine = wow2 for me
261 [123456]
262 a123 = 987
263 [Version "1.2.3eX"]
264 Alpha = beta
265 EOF
266
267 test_expect_success 'hierarchical section value' 'cmp .git/config expect'
268
269 cat > expect << EOF
270 beta.noindent=sillyValue
271 nextsection.nonewline=wow2 for me
272 123456.a123=987
273 version.1.2.3eX.alpha=beta
274 EOF
275
276 test_expect_success 'working --list' \
277 'git config --list > output && cmp output expect'
278
279 cat > expect << EOF
280 beta.noindent sillyValue
281 nextsection.nonewline wow2 for me
282 EOF
283
284 test_expect_success '--get-regexp' \
285 'git config --get-regexp in > output && cmp output expect'
286
287 git config --add nextsection.nonewline "wow4 for you"
288
289 cat > expect << EOF
290 wow2 for me
291 wow4 for you
292 EOF
293
294 test_expect_success '--add' \
295 'git config --get-all nextsection.nonewline > output && cmp output expect'
296
297 cat > .git/config << EOF
298 [novalue]
299 variable
300 [emptyvalue]
301 variable =
302 EOF
303
304 test_expect_success 'get variable with no value' \
305 'git config --get novalue.variable ^$'
306
307 test_expect_success 'get variable with empty value' \
308 'git config --get emptyvalue.variable ^$'
309
310 echo novalue.variable > expect
311
312 test_expect_success 'get-regexp variable with no value' \
313 'git config --get-regexp novalue > output &&
314 cmp output expect'
315
316 echo 'emptyvalue.variable ' > expect
317
318 test_expect_success 'get-regexp variable with empty value' \
319 'git config --get-regexp emptyvalue > output &&
320 cmp output expect'
321
322 echo true > expect
323
324 test_expect_success 'get bool variable with no value' \
325 'git config --bool novalue.variable > output &&
326 cmp output expect'
327
328 echo false > expect
329
330 test_expect_success 'get bool variable with empty value' \
331 'git config --bool emptyvalue.variable > output &&
332 cmp output expect'
333
334 git config > output 2>&1
335
336 test_expect_success 'no arguments, but no crash' \
337 "test $? = 129 && grep usage output"
338
339 cat > .git/config << EOF
340 [a.b]
341 c = d
342 EOF
343
344 git config a.x y
345
346 cat > expect << EOF
347 [a.b]
348 c = d
349 [a]
350 x = y
351 EOF
352
353 test_expect_success 'new section is partial match of another' 'cmp .git/config expect'
354
355 git config b.x y
356 git config a.b c
357
358 cat > expect << EOF
359 [a.b]
360 c = d
361 [a]
362 x = y
363 b = c
364 [b]
365 x = y
366 EOF
367
368 test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
369
370 test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
371 'git config --file non-existing-config -l; test $? != 0'
372
373 cat > other-config << EOF
374 [ein]
375 bahn = strasse
376 EOF
377
378 cat > expect << EOF
379 ein.bahn=strasse
380 EOF
381
382 GIT_CONFIG=other-config git config -l > output
383
384 test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
385
386 test_expect_success 'alternative GIT_CONFIG (--file)' \
387 'git config --file other-config -l > output && cmp output expect'
388
389 GIT_CONFIG=other-config git config anwohner.park ausweis
390
391 cat > expect << EOF
392 [ein]
393 bahn = strasse
394 [anwohner]
395 park = ausweis
396 EOF
397
398 test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
399
400 cat > .git/config << EOF
401 # Hallo
402 #Bello
403 [branch "eins"]
404 x = 1
405 [branch.eins]
406 y = 1
407 [branch "1 234 blabl/a"]
408 weird
409 EOF
410
411 test_expect_success "rename section" \
412 "git config --rename-section branch.eins branch.zwei"
413
414 cat > expect << EOF
415 # Hallo
416 #Bello
417 [branch "zwei"]
418 x = 1
419 [branch "zwei"]
420 y = 1
421 [branch "1 234 blabl/a"]
422 weird
423 EOF
424
425 test_expect_success "rename succeeded" "git diff expect .git/config"
426
427 test_expect_failure "rename non-existing section" \
428 'git config --rename-section branch."world domination" branch.drei'
429
430 test_expect_success "rename succeeded" "git diff expect .git/config"
431
432 test_expect_success "rename another section" \
433 'git config --rename-section branch."1 234 blabl/a" branch.drei'
434
435 cat > expect << EOF
436 # Hallo
437 #Bello
438 [branch "zwei"]
439 x = 1
440 [branch "zwei"]
441 y = 1
442 [branch "drei"]
443 weird
444 EOF
445
446 test_expect_success "rename succeeded" "git diff expect .git/config"
447
448 cat >> .git/config << EOF
449 [branch "zwei"] a = 1 [branch "vier"]
450 EOF
451
452 test_expect_success "remove section" "git config --remove-section branch.zwei"
453
454 cat > expect << EOF
455 # Hallo
456 #Bello
457 [branch "drei"]
458 weird
459 EOF
460
461 test_expect_success "section was removed properly" \
462 "git diff -u expect .git/config"
463
464 rm .git/config
465
466 cat > expect << EOF
467 [gitcvs]
468 enabled = true
469 dbname = %Ggitcvs2.%a.%m.sqlite
470 [gitcvs "ext"]
471 dbname = %Ggitcvs1.%a.%m.sqlite
472 EOF
473
474 test_expect_success 'section ending' '
475
476 git config gitcvs.enabled true &&
477 git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
478 git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
479 cmp .git/config expect
480
481 '
482
483 test_expect_success numbers '
484
485 git config kilo.gram 1k &&
486 git config mega.ton 1m &&
487 k=$(git config --int --get kilo.gram) &&
488 test z1024 = "z$k" &&
489 m=$(git config --int --get mega.ton) &&
490 test z1048576 = "z$m"
491 '
492
493 cat > expect <<EOF
494 fatal: bad config value for 'aninvalid.unit' in .git/config
495 EOF
496
497 test_expect_success 'invalid unit' '
498
499 git config aninvalid.unit "1auto" &&
500 s=$(git config aninvalid.unit) &&
501 test "z1auto" = "z$s" &&
502 if git config --int --get aninvalid.unit 2>actual
503 then
504 echo config should have failed
505 false
506 fi &&
507 cmp actual expect
508 '
509
510 cat > expect << EOF
511 true
512 false
513 true
514 false
515 true
516 false
517 true
518 false
519 EOF
520
521 test_expect_success bool '
522
523 git config bool.true1 01 &&
524 git config bool.true2 -1 &&
525 git config bool.true3 YeS &&
526 git config bool.true4 true &&
527 git config bool.false1 000 &&
528 git config bool.false2 "" &&
529 git config bool.false3 nO &&
530 git config bool.false4 FALSE &&
531 rm -f result &&
532 for i in 1 2 3 4
533 do
534 git config --bool --get bool.true$i >>result
535 git config --bool --get bool.false$i >>result
536 done &&
537 cmp expect result'
538
539 test_expect_failure 'invalid bool (--get)' '
540
541 git config bool.nobool foobar &&
542 git config --bool --get bool.nobool'
543
544 test_expect_failure 'invalid bool (set)' '
545
546 git config --bool bool.nobool foobar'
547
548 rm .git/config
549
550 cat > expect <<\EOF
551 [bool]
552 true1 = true
553 true2 = true
554 true3 = true
555 true4 = true
556 false1 = false
557 false2 = false
558 false3 = false
559 false4 = false
560 EOF
561
562 test_expect_success 'set --bool' '
563
564 git config --bool bool.true1 01 &&
565 git config --bool bool.true2 -1 &&
566 git config --bool bool.true3 YeS &&
567 git config --bool bool.true4 true &&
568 git config --bool bool.false1 000 &&
569 git config --bool bool.false2 "" &&
570 git config --bool bool.false3 nO &&
571 git config --bool bool.false4 FALSE &&
572 cmp expect .git/config'
573
574 rm .git/config
575
576 cat > expect <<\EOF
577 [int]
578 val1 = 1
579 val2 = -1
580 val3 = 5242880
581 EOF
582
583 test_expect_success 'set --int' '
584
585 git config --int int.val1 01 &&
586 git config --int int.val2 -1 &&
587 git config --int int.val3 5m &&
588 cmp expect .git/config'
589
590 rm .git/config
591
592 git config quote.leading " test"
593 git config quote.ending "test "
594 git config quote.semicolon "test;test"
595 git config quote.hash "test#test"
596
597 cat > expect << EOF
598 [quote]
599 leading = " test"
600 ending = "test "
601 semicolon = "test;test"
602 hash = "test#test"
603 EOF
604
605 test_expect_success 'quoting' 'cmp .git/config expect'
606
607 test_expect_failure 'key with newline' 'git config key.with\\\
608 newline 123'
609
610 test_expect_success 'value with newline' 'git config key.sub value.with\\\
611 newline'
612
613 cat > .git/config <<\EOF
614 [section]
615 ; comment \
616 continued = cont\
617 inued
618 noncont = not continued ; \
619 quotecont = "cont;\
620 inued"
621 EOF
622
623 cat > expect <<\EOF
624 section.continued=continued
625 section.noncont=not continued
626 section.quotecont=cont;inued
627 EOF
628
629 git config --list > result
630
631 test_expect_success 'value continued on next line' 'cmp result expect'
632
633 cat > .git/config <<\EOF
634 [section "sub=section"]
635 val1 = foo=bar
636 val2 = foo\nbar
637 val3 = \n\n
638 val4 =
639 val5
640 EOF
641
642 cat > expect <<\EOF
643 section.sub=section.val1
644 foo=barQsection.sub=section.val2
645 foo
646 barQsection.sub=section.val3
647
648
649 Qsection.sub=section.val4
650 Qsection.sub=section.val5Q
651 EOF
652
653 git config --null --list | tr '\000' 'Q' > result
654 echo >>result
655
656 test_expect_success '--null --list' 'cmp result expect'
657
658 git config --null --get-regexp 'val[0-9]' | tr '\000' 'Q' > result
659 echo >>result
660
661 test_expect_success '--null --get-regexp' 'cmp result expect'
662
663 test_expect_success 'symlinked configuration' '
664
665 ln -s notyet myconfig &&
666 GIT_CONFIG=myconfig git config test.frotz nitfol &&
667 test -h myconfig &&
668 test -f notyet &&
669 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
670 GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
671 test -h myconfig &&
672 test -f notyet &&
673 test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol &&
674 test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov
675
676 '
677
678 test_done