]>
Commit | Line | Data |
---|---|---|
942c1f53 JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Johannes Schindelin | |
4 | # | |
5 | ||
e0d10e1c | 6 | test_description='Test git-config in different settings' |
942c1f53 JS |
7 | |
8 | . ./test-lib.sh | |
9 | ||
10 | test -f .git/config && rm .git/config | |
11 | ||
e0d10e1c | 12 | git-config core.penguin "little blue" |
942c1f53 JS |
13 | |
14 | cat > expect << EOF | |
942c1f53 JS |
15 | [core] |
16 | penguin = little blue | |
17 | EOF | |
18 | ||
19 | test_expect_success 'initial' 'cmp .git/config expect' | |
20 | ||
e0d10e1c | 21 | git-config Core.Movie BadPhysics |
942c1f53 JS |
22 | |
23 | cat > expect << EOF | |
942c1f53 JS |
24 | [core] |
25 | penguin = little blue | |
26 | Movie = BadPhysics | |
27 | EOF | |
28 | ||
29 | test_expect_success 'mixed case' 'cmp .git/config expect' | |
30 | ||
e0d10e1c | 31 | git-config Cores.WhatEver Second |
942c1f53 JS |
32 | |
33 | cat > expect << EOF | |
942c1f53 JS |
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 | ||
e0d10e1c | 43 | git-config CORE.UPPERCASE true |
942c1f53 JS |
44 | |
45 | cat > expect << EOF | |
942c1f53 JS |
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 | ||
f98d863d | 56 | test_expect_success 'replace with non-match' \ |
e0d10e1c | 57 | 'git-config core.penguin kingpin !blue' |
f98d863d JS |
58 | |
59 | test_expect_success 'replace with non-match (actually matching)' \ | |
e0d10e1c | 60 | 'git-config core.penguin "very blue" !kingpin' |
f98d863d JS |
61 | |
62 | cat > expect << EOF | |
f98d863d JS |
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 | ||
942c1f53 JS |
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 | |
4ddba79d JS |
81 | haha = hello |
82 | haha = bello | |
942c1f53 JS |
83 | [nextSection] noNewline = ouch |
84 | EOF | |
85 | ||
4ddba79d JS |
86 | cp .git/config .git/config2 |
87 | ||
88 | test_expect_success 'multiple unset' \ | |
e0d10e1c | 89 | 'git-config --unset-all beta.haha' |
4ddba79d JS |
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' \ | |
e0d10e1c | 105 | 'git-config --replace-all beta.haha gamma' |
4ddba79d JS |
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 | ||
e0d10e1c | 119 | git-config beta.haha alpha |
942c1f53 JS |
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 | ||
e0d10e1c | 133 | git-config nextsection.nonewline wow |
942c1f53 JS |
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 | ||
e0d10e1c TP |
148 | test_expect_success 'get value' 'test alpha = $(git-config beta.haha)' |
149 | git-config --unset beta.haha | |
942c1f53 JS |
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 | ||
e0d10e1c | 163 | git-config nextsection.NoNewLine "wow2 for me" "for me$" |
942c1f53 JS |
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 | ||
f98d863d | 178 | test_expect_success 'non-match' \ |
e0d10e1c | 179 | 'git-config --get nextsection.nonewline !for' |
f98d863d JS |
180 | |
181 | test_expect_success 'non-match value' \ | |
e0d10e1c | 182 | 'test wow = $(git-config --get nextsection.nonewline !for)' |
f98d863d | 183 | |
4ddba79d | 184 | test_expect_failure 'ambiguous get' \ |
e0d10e1c | 185 | 'git-config --get nextsection.nonewline' |
4ddba79d JS |
186 | |
187 | test_expect_success 'get multivar' \ | |
e0d10e1c | 188 | 'git-config --get-all nextsection.nonewline' |
4ddba79d | 189 | |
e0d10e1c | 190 | git-config nextsection.nonewline "wow3" "wow$" |
942c1f53 JS |
191 | |
192 | cat > expect << EOF | |
193 | [beta] ; silly comment # another comment | |
194 | noIndent= sillyValue ; 'nother silly comment | |
195 | ||
196 | # empty line | |
197 | ; comment | |
198 | [nextSection] | |
199 | nonewline = wow3 | |
200 | NoNewLine = wow2 for me | |
201 | EOF | |
202 | ||
203 | test_expect_success 'multivar replace' 'cmp .git/config expect' | |
204 | ||
e0d10e1c | 205 | test_expect_failure 'ambiguous value' 'git-config nextsection.nonewline' |
4ddba79d | 206 | |
942c1f53 | 207 | test_expect_failure 'ambiguous unset' \ |
e0d10e1c | 208 | 'git-config --unset nextsection.nonewline' |
942c1f53 JS |
209 | |
210 | test_expect_failure 'invalid unset' \ | |
e0d10e1c | 211 | 'git-config --unset somesection.nonewline' |
942c1f53 | 212 | |
e0d10e1c | 213 | git-config --unset nextsection.nonewline "wow3$" |
942c1f53 JS |
214 | |
215 | cat > expect << EOF | |
216 | [beta] ; silly comment # another comment | |
217 | noIndent= sillyValue ; 'nother silly comment | |
218 | ||
219 | # empty line | |
220 | ; comment | |
221 | [nextSection] | |
222 | NoNewLine = wow2 for me | |
223 | EOF | |
224 | ||
225 | test_expect_success 'multivar unset' 'cmp .git/config expect' | |
226 | ||
e0d10e1c | 227 | test_expect_failure 'invalid key' 'git-config inval.2key blabla' |
942c1f53 | 228 | |
e0d10e1c | 229 | test_expect_success 'correct key' 'git-config 123456.a123 987' |
942c1f53 | 230 | |
b17e659d | 231 | test_expect_success 'hierarchical section' \ |
e0d10e1c | 232 | 'git-config Version.1.2.3eX.Alpha beta' |
b17e659d JS |
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 | [123456] | |
243 | a123 = 987 | |
d14f7764 LT |
244 | [Version "1.2.3eX"] |
245 | Alpha = beta | |
b17e659d JS |
246 | EOF |
247 | ||
248 | test_expect_success 'hierarchical section value' 'cmp .git/config expect' | |
249 | ||
2fa9a0fb JS |
250 | cat > expect << EOF |
251 | beta.noindent=sillyValue | |
252 | nextsection.nonewline=wow2 for me | |
253 | 123456.a123=987 | |
d55aaefa | 254 | version.1.2.3eX.alpha=beta |
2fa9a0fb JS |
255 | EOF |
256 | ||
257 | test_expect_success 'working --list' \ | |
e0d10e1c | 258 | 'git-config --list > output && cmp output expect' |
2fa9a0fb JS |
259 | |
260 | cat > expect << EOF | |
261 | beta.noindent sillyValue | |
262 | nextsection.nonewline wow2 for me | |
263 | EOF | |
264 | ||
265 | test_expect_success '--get-regexp' \ | |
e0d10e1c | 266 | 'git-config --get-regexp in > output && cmp output expect' |
2fa9a0fb | 267 | |
e0d10e1c | 268 | git-config --add nextsection.nonewline "wow4 for you" |
89c4afe0 BG |
269 | |
270 | cat > expect << EOF | |
271 | wow2 for me | |
272 | wow4 for you | |
273 | EOF | |
274 | ||
275 | test_expect_success '--add' \ | |
e0d10e1c | 276 | 'git-config --get-all nextsection.nonewline > output && cmp output expect' |
89c4afe0 | 277 | |
f067a137 JF |
278 | cat > .git/config << EOF |
279 | [novalue] | |
280 | variable | |
281 | EOF | |
282 | ||
283 | test_expect_success 'get variable with no value' \ | |
e0d10e1c | 284 | 'git-config --get novalue.variable ^$' |
f067a137 | 285 | |
b69ba460 FL |
286 | echo novalue.variable > expect |
287 | ||
288 | test_expect_success 'get-regexp variable with no value' \ | |
289 | 'git-config --get-regexp novalue > output && | |
290 | cmp output expect' | |
291 | ||
e0d10e1c | 292 | git-config > output 2>&1 |
2fa9a0fb JS |
293 | |
294 | test_expect_success 'no arguments, but no crash' \ | |
295 | "test $? = 129 && grep usage output" | |
296 | ||
bd886fd3 SE |
297 | cat > .git/config << EOF |
298 | [a.b] | |
299 | c = d | |
300 | EOF | |
301 | ||
e0d10e1c | 302 | git-config a.x y |
bd886fd3 SE |
303 | |
304 | cat > expect << EOF | |
305 | [a.b] | |
306 | c = d | |
307 | [a] | |
308 | x = y | |
309 | EOF | |
310 | ||
311 | test_expect_success 'new section is partial match of another' 'cmp .git/config expect' | |
312 | ||
e0d10e1c TP |
313 | git-config b.x y |
314 | git-config a.b c | |
bd886fd3 SE |
315 | |
316 | cat > expect << EOF | |
317 | [a.b] | |
318 | c = d | |
319 | [a] | |
320 | x = y | |
321 | b = c | |
322 | [b] | |
323 | x = y | |
324 | EOF | |
325 | ||
326 | test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect' | |
327 | ||
9c3796fc JS |
328 | cat > other-config << EOF |
329 | [ein] | |
330 | bahn = strasse | |
331 | EOF | |
332 | ||
333 | cat > expect << EOF | |
334 | ein.bahn=strasse | |
335 | EOF | |
336 | ||
e0d10e1c | 337 | GIT_CONFIG=other-config git-config -l > output |
9c3796fc JS |
338 | |
339 | test_expect_success 'alternative GIT_CONFIG' 'cmp output expect' | |
340 | ||
e0d10e1c | 341 | GIT_CONFIG=other-config git-config anwohner.park ausweis |
9c3796fc JS |
342 | |
343 | cat > expect << EOF | |
344 | [ein] | |
345 | bahn = strasse | |
346 | [anwohner] | |
347 | park = ausweis | |
348 | EOF | |
349 | ||
350 | test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect' | |
351 | ||
0667fcfb JS |
352 | cat > .git/config << EOF |
353 | # Hallo | |
354 | #Bello | |
355 | [branch "eins"] | |
356 | x = 1 | |
357 | [branch.eins] | |
358 | y = 1 | |
359 | [branch "1 234 blabl/a"] | |
360 | weird | |
361 | EOF | |
362 | ||
363 | test_expect_success "rename section" \ | |
e0d10e1c | 364 | "git-config --rename-section branch.eins branch.zwei" |
0667fcfb JS |
365 | |
366 | cat > expect << EOF | |
367 | # Hallo | |
368 | #Bello | |
369 | [branch "zwei"] | |
370 | x = 1 | |
371 | [branch "zwei"] | |
372 | y = 1 | |
373 | [branch "1 234 blabl/a"] | |
374 | weird | |
375 | EOF | |
376 | ||
5bd74506 | 377 | test_expect_success "rename succeeded" "git diff expect .git/config" |
0667fcfb JS |
378 | |
379 | test_expect_failure "rename non-existing section" \ | |
e0d10e1c | 380 | 'git-config --rename-section branch."world domination" branch.drei' |
0667fcfb | 381 | |
5bd74506 | 382 | test_expect_success "rename succeeded" "git diff expect .git/config" |
0667fcfb JS |
383 | |
384 | test_expect_success "rename another section" \ | |
e0d10e1c | 385 | 'git-config --rename-section branch."1 234 blabl/a" branch.drei' |
0667fcfb JS |
386 | |
387 | cat > expect << EOF | |
388 | # Hallo | |
389 | #Bello | |
390 | [branch "zwei"] | |
391 | x = 1 | |
392 | [branch "zwei"] | |
393 | y = 1 | |
394 | [branch "drei"] | |
395 | weird | |
396 | EOF | |
397 | ||
5bd74506 | 398 | test_expect_success "rename succeeded" "git diff expect .git/config" |
0667fcfb | 399 | |
118f8b24 PB |
400 | cat >> .git/config << EOF |
401 | [branch "zwei"] a = 1 [branch "vier"] | |
402 | EOF | |
403 | ||
404 | test_expect_success "remove section" "git config --remove-section branch.zwei" | |
405 | ||
406 | cat > expect << EOF | |
407 | # Hallo | |
408 | #Bello | |
409 | [branch "drei"] | |
410 | weird | |
411 | EOF | |
412 | ||
413 | test_expect_success "section was removed properly" \ | |
cf6981d4 | 414 | "git diff -u expect .git/config" |
118f8b24 | 415 | |
b18a2be3 SP |
416 | rm .git/config |
417 | ||
418 | cat > expect << EOF | |
419 | [gitcvs] | |
420 | enabled = true | |
421 | dbname = %Ggitcvs2.%a.%m.sqlite | |
422 | [gitcvs "ext"] | |
423 | dbname = %Ggitcvs1.%a.%m.sqlite | |
424 | EOF | |
425 | ||
426 | test_expect_success 'section ending' ' | |
427 | ||
428 | git-config gitcvs.enabled true && | |
429 | git-config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && | |
430 | git-config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && | |
431 | cmp .git/config expect | |
432 | ||
433 | ' | |
434 | ||
d77a64d3 SP |
435 | test_expect_success numbers ' |
436 | ||
e0d10e1c TP |
437 | git-config kilo.gram 1k && |
438 | git-config mega.ton 1m && | |
439 | k=$(git-config --int --get kilo.gram) && | |
d77a64d3 | 440 | test z1024 = "z$k" && |
e0d10e1c | 441 | m=$(git-config --int --get mega.ton) && |
d77a64d3 SP |
442 | test z1048576 = "z$m" |
443 | ' | |
444 | ||
cab333cb FL |
445 | cat > expect << EOF |
446 | true | |
447 | false | |
448 | true | |
449 | false | |
450 | true | |
451 | false | |
452 | true | |
453 | false | |
454 | EOF | |
455 | ||
456 | test_expect_success bool ' | |
457 | ||
458 | git-config bool.true1 01 && | |
459 | git-config bool.true2 -1 && | |
460 | git-config bool.true3 YeS && | |
461 | git-config bool.true4 true && | |
462 | git-config bool.false1 000 && | |
463 | git-config bool.false2 "" && | |
464 | git-config bool.false3 nO && | |
465 | git-config bool.false4 FALSE && | |
466 | rm -f result && | |
467 | for i in 1 2 3 4 | |
468 | do | |
469 | git-config --bool --get bool.true$i >>result | |
470 | git-config --bool --get bool.false$i >>result | |
471 | done && | |
472 | cmp expect result' | |
473 | ||
474 | test_expect_failure 'invalid bool' ' | |
475 | ||
476 | git-config bool.nobool foobar && | |
477 | git-config --bool --get bool.nobool' | |
478 | ||
cdd4fb15 BG |
479 | rm .git/config |
480 | ||
e0d10e1c TP |
481 | git-config quote.leading " test" |
482 | git-config quote.ending "test " | |
483 | git-config quote.semicolon "test;test" | |
484 | git-config quote.hash "test#test" | |
cdd4fb15 BG |
485 | |
486 | cat > expect << EOF | |
487 | [quote] | |
488 | leading = " test" | |
489 | ending = "test " | |
490 | semicolon = "test;test" | |
491 | hash = "test#test" | |
492 | EOF | |
493 | ||
494 | test_expect_success 'quoting' 'cmp .git/config expect' | |
495 | ||
e0d10e1c | 496 | test_expect_failure 'key with newline' 'git config key.with\\\ |
6f71686e JS |
497 | newline 123' |
498 | ||
e0d10e1c | 499 | test_expect_success 'value with newline' 'git config key.sub value.with\\\ |
6f71686e JS |
500 | newline' |
501 | ||
83cd10a0 JN |
502 | cat > .git/config <<\EOF |
503 | [section] | |
504 | ; comment \ | |
505 | continued = cont\ | |
506 | inued | |
507 | noncont = not continued ; \ | |
508 | quotecont = "cont;\ | |
509 | inued" | |
510 | EOF | |
511 | ||
512 | cat > expect <<\EOF | |
513 | section.continued=continued | |
514 | section.noncont=not continued | |
515 | section.quotecont=cont;inued | |
516 | EOF | |
517 | ||
e0d10e1c | 518 | git config --list > result |
83cd10a0 JN |
519 | |
520 | test_expect_success 'value continued on next line' 'cmp result expect' | |
521 | ||
2275d502 FL |
522 | cat > .git/config <<\EOF |
523 | [section "sub=section"] | |
524 | val1 = foo=bar | |
525 | val2 = foo\nbar | |
526 | val3 = \n\n | |
527 | val4 = | |
528 | val5 | |
529 | EOF | |
530 | ||
531 | cat > expect <<\EOF | |
532 | Key: section.sub=section.val1 | |
533 | Value: foo=bar | |
534 | Key: section.sub=section.val2 | |
535 | Value: foo | |
536 | bar | |
537 | Key: section.sub=section.val3 | |
538 | Value: | |
539 | ||
540 | ||
541 | Key: section.sub=section.val4 | |
542 | Value: | |
543 | Key: section.sub=section.val5 | |
544 | EOF | |
545 | ||
546 | git config --null --list | perl -0ne 'chop;($key,$value)=split(/\n/,$_,2);print "Key: $key\n";print "Value: $value\n" if defined($value)' > result | |
547 | ||
548 | test_expect_success '--null --list' 'cmp result expect' | |
549 | ||
550 | git config --null --get-regexp 'val[0-9]' | perl -0ne 'chop;($key,$value)=split(/\n/,$_,2);print "Key: $key\n";print "Value: $value\n" if defined($value)' > result | |
551 | ||
552 | test_expect_success '--null --get-regexp' 'cmp result expect' | |
553 | ||
942c1f53 | 554 | test_done |