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