]>
Commit | Line | Data |
---|---|---|
942c1f53 JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Johannes Schindelin | |
4 | # | |
5 | ||
5be60078 | 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 | ||
5be60078 | 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 | ||
5be60078 | 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 | ||
5be60078 | 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 | ||
5be60078 | 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' \ |
5be60078 | 57 | 'git config core.penguin kingpin !blue' |
f98d863d JS |
58 | |
59 | test_expect_success 'replace with non-match (actually matching)' \ | |
5be60078 | 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 | ||
7a31cc0f FL |
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 | ||
942c1f53 JS |
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 | |
4ddba79d JS |
100 | haha = hello |
101 | haha = bello | |
942c1f53 JS |
102 | [nextSection] noNewline = ouch |
103 | EOF | |
104 | ||
4ddba79d JS |
105 | cp .git/config .git/config2 |
106 | ||
107 | test_expect_success 'multiple unset' \ | |
5be60078 | 108 | 'git config --unset-all beta.haha' |
4ddba79d JS |
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 | ||
bf71b4b3 CR |
121 | cp .git/config2 .git/config |
122 | ||
123 | test_expect_success '--replace-all missing value' ' | |
124 | test_must_fail git config --replace-all beta.haha && | |
125 | test_cmp .git/config2 .git/config | |
126 | ' | |
127 | ||
128 | rm .git/config2 | |
4ddba79d JS |
129 | |
130 | test_expect_success '--replace-all' \ | |
5be60078 | 131 | 'git config --replace-all beta.haha gamma' |
4ddba79d JS |
132 | |
133 | cat > expect << EOF | |
134 | [beta] ; silly comment # another comment | |
135 | noIndent= sillyValue ; 'nother silly comment | |
136 | ||
137 | # empty line | |
138 | ; comment | |
139 | haha = gamma | |
140 | [nextSection] noNewline = ouch | |
141 | EOF | |
142 | ||
143 | test_expect_success 'all replaced' 'cmp .git/config expect' | |
144 | ||
5be60078 | 145 | git config beta.haha alpha |
942c1f53 JS |
146 | |
147 | cat > expect << EOF | |
148 | [beta] ; silly comment # another comment | |
149 | noIndent= sillyValue ; 'nother silly comment | |
150 | ||
151 | # empty line | |
152 | ; comment | |
153 | haha = alpha | |
154 | [nextSection] noNewline = ouch | |
155 | EOF | |
156 | ||
157 | test_expect_success 'really mean test' 'cmp .git/config expect' | |
158 | ||
5be60078 | 159 | git config nextsection.nonewline wow |
942c1f53 JS |
160 | |
161 | cat > expect << EOF | |
162 | [beta] ; silly comment # another comment | |
163 | noIndent= sillyValue ; 'nother silly comment | |
164 | ||
165 | # empty line | |
166 | ; comment | |
167 | haha = alpha | |
168 | [nextSection] | |
169 | nonewline = wow | |
170 | EOF | |
171 | ||
172 | test_expect_success 'really really mean test' 'cmp .git/config expect' | |
173 | ||
5be60078 JH |
174 | test_expect_success 'get value' 'test alpha = $(git config beta.haha)' |
175 | git config --unset beta.haha | |
942c1f53 JS |
176 | |
177 | cat > expect << EOF | |
178 | [beta] ; silly comment # another comment | |
179 | noIndent= sillyValue ; 'nother silly comment | |
180 | ||
181 | # empty line | |
182 | ; comment | |
183 | [nextSection] | |
184 | nonewline = wow | |
185 | EOF | |
186 | ||
187 | test_expect_success 'unset' 'cmp .git/config expect' | |
188 | ||
5be60078 | 189 | git config nextsection.NoNewLine "wow2 for me" "for me$" |
942c1f53 JS |
190 | |
191 | cat > expect << EOF | |
192 | [beta] ; silly comment # another comment | |
193 | noIndent= sillyValue ; 'nother silly comment | |
194 | ||
195 | # empty line | |
196 | ; comment | |
197 | [nextSection] | |
198 | nonewline = wow | |
199 | NoNewLine = wow2 for me | |
200 | EOF | |
201 | ||
202 | test_expect_success 'multivar' 'cmp .git/config expect' | |
203 | ||
f98d863d | 204 | test_expect_success 'non-match' \ |
5be60078 | 205 | 'git config --get nextsection.nonewline !for' |
f98d863d JS |
206 | |
207 | test_expect_success 'non-match value' \ | |
5be60078 | 208 | 'test wow = $(git config --get nextsection.nonewline !for)' |
f98d863d | 209 | |
41ac414e | 210 | test_expect_success 'ambiguous get' ' |
d492b31c | 211 | test_must_fail git config --get nextsection.nonewline |
41ac414e | 212 | ' |
4ddba79d JS |
213 | |
214 | test_expect_success 'get multivar' \ | |
5be60078 | 215 | 'git config --get-all nextsection.nonewline' |
4ddba79d | 216 | |
5be60078 | 217 | git config nextsection.nonewline "wow3" "wow$" |
942c1f53 JS |
218 | |
219 | cat > expect << EOF | |
220 | [beta] ; silly comment # another comment | |
221 | noIndent= sillyValue ; 'nother silly comment | |
222 | ||
223 | # empty line | |
224 | ; comment | |
225 | [nextSection] | |
226 | nonewline = wow3 | |
227 | NoNewLine = wow2 for me | |
228 | EOF | |
229 | ||
230 | test_expect_success 'multivar replace' 'cmp .git/config expect' | |
231 | ||
41ac414e | 232 | test_expect_success 'ambiguous value' ' |
d492b31c | 233 | test_must_fail git config nextsection.nonewline |
41ac414e | 234 | ' |
4ddba79d | 235 | |
41ac414e | 236 | test_expect_success 'ambiguous unset' ' |
d492b31c | 237 | test_must_fail git config --unset nextsection.nonewline |
41ac414e | 238 | ' |
942c1f53 | 239 | |
41ac414e | 240 | test_expect_success 'invalid unset' ' |
d492b31c | 241 | test_must_fail git config --unset somesection.nonewline |
41ac414e | 242 | ' |
942c1f53 | 243 | |
5be60078 | 244 | git config --unset nextsection.nonewline "wow3$" |
942c1f53 JS |
245 | |
246 | cat > expect << EOF | |
247 | [beta] ; silly comment # another comment | |
248 | noIndent= sillyValue ; 'nother silly comment | |
249 | ||
250 | # empty line | |
251 | ; comment | |
252 | [nextSection] | |
253 | NoNewLine = wow2 for me | |
254 | EOF | |
255 | ||
256 | test_expect_success 'multivar unset' 'cmp .git/config expect' | |
257 | ||
d492b31c | 258 | test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla' |
942c1f53 | 259 | |
5be60078 | 260 | test_expect_success 'correct key' 'git config 123456.a123 987' |
942c1f53 | 261 | |
b17e659d | 262 | test_expect_success 'hierarchical section' \ |
5be60078 | 263 | 'git config Version.1.2.3eX.Alpha beta' |
b17e659d JS |
264 | |
265 | cat > expect << EOF | |
266 | [beta] ; silly comment # another comment | |
267 | noIndent= sillyValue ; 'nother silly comment | |
268 | ||
269 | # empty line | |
270 | ; comment | |
271 | [nextSection] | |
272 | NoNewLine = wow2 for me | |
273 | [123456] | |
274 | a123 = 987 | |
d14f7764 LT |
275 | [Version "1.2.3eX"] |
276 | Alpha = beta | |
b17e659d JS |
277 | EOF |
278 | ||
279 | test_expect_success 'hierarchical section value' 'cmp .git/config expect' | |
280 | ||
2fa9a0fb JS |
281 | cat > expect << EOF |
282 | beta.noindent=sillyValue | |
283 | nextsection.nonewline=wow2 for me | |
284 | 123456.a123=987 | |
d55aaefa | 285 | version.1.2.3eX.alpha=beta |
2fa9a0fb JS |
286 | EOF |
287 | ||
288 | test_expect_success 'working --list' \ | |
5be60078 | 289 | 'git config --list > output && cmp output expect' |
2fa9a0fb JS |
290 | |
291 | cat > expect << EOF | |
292 | beta.noindent sillyValue | |
293 | nextsection.nonewline wow2 for me | |
294 | EOF | |
295 | ||
296 | test_expect_success '--get-regexp' \ | |
5be60078 | 297 | 'git config --get-regexp in > output && cmp output expect' |
2fa9a0fb | 298 | |
5be60078 | 299 | git config --add nextsection.nonewline "wow4 for you" |
89c4afe0 BG |
300 | |
301 | cat > expect << EOF | |
302 | wow2 for me | |
303 | wow4 for you | |
304 | EOF | |
305 | ||
306 | test_expect_success '--add' \ | |
5be60078 | 307 | 'git config --get-all nextsection.nonewline > output && cmp output expect' |
89c4afe0 | 308 | |
f067a137 JF |
309 | cat > .git/config << EOF |
310 | [novalue] | |
311 | variable | |
09bc098c CC |
312 | [emptyvalue] |
313 | variable = | |
f067a137 JF |
314 | EOF |
315 | ||
316 | test_expect_success 'get variable with no value' \ | |
5be60078 | 317 | 'git config --get novalue.variable ^$' |
f067a137 | 318 | |
09bc098c CC |
319 | test_expect_success 'get variable with empty value' \ |
320 | 'git config --get emptyvalue.variable ^$' | |
321 | ||
b69ba460 FL |
322 | echo novalue.variable > expect |
323 | ||
324 | test_expect_success 'get-regexp variable with no value' \ | |
5be60078 | 325 | 'git config --get-regexp novalue > output && |
b69ba460 FL |
326 | cmp output expect' |
327 | ||
09bc098c CC |
328 | echo 'emptyvalue.variable ' > expect |
329 | ||
330 | test_expect_success 'get-regexp variable with empty value' \ | |
331 | 'git config --get-regexp emptyvalue > output && | |
332 | cmp output expect' | |
333 | ||
334 | echo true > expect | |
335 | ||
336 | test_expect_success 'get bool variable with no value' \ | |
337 | 'git config --bool novalue.variable > output && | |
338 | cmp output expect' | |
339 | ||
340 | echo false > expect | |
341 | ||
342 | test_expect_success 'get bool variable with empty value' \ | |
343 | 'git config --bool emptyvalue.variable > output && | |
344 | cmp output expect' | |
345 | ||
003f69b2 JK |
346 | test_expect_success 'no arguments, but no crash' ' |
347 | test_must_fail git config >output 2>&1 && | |
348 | grep usage output | |
349 | ' | |
2fa9a0fb | 350 | |
bd886fd3 SE |
351 | cat > .git/config << EOF |
352 | [a.b] | |
353 | c = d | |
354 | EOF | |
355 | ||
5be60078 | 356 | git config a.x y |
bd886fd3 SE |
357 | |
358 | cat > expect << EOF | |
359 | [a.b] | |
360 | c = d | |
361 | [a] | |
362 | x = y | |
363 | EOF | |
364 | ||
365 | test_expect_success 'new section is partial match of another' 'cmp .git/config expect' | |
366 | ||
5be60078 JH |
367 | git config b.x y |
368 | git config a.b c | |
bd886fd3 SE |
369 | |
370 | cat > expect << EOF | |
371 | [a.b] | |
372 | c = d | |
373 | [a] | |
374 | x = y | |
375 | b = c | |
376 | [b] | |
377 | x = y | |
378 | EOF | |
379 | ||
380 | test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect' | |
381 | ||
773a69fb | 382 | test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \ |
003f69b2 | 383 | 'test_must_fail git config --file non-existing-config -l' |
773a69fb | 384 | |
9c3796fc JS |
385 | cat > other-config << EOF |
386 | [ein] | |
387 | bahn = strasse | |
388 | EOF | |
389 | ||
390 | cat > expect << EOF | |
391 | ein.bahn=strasse | |
392 | EOF | |
393 | ||
5be60078 | 394 | GIT_CONFIG=other-config git config -l > output |
9c3796fc JS |
395 | |
396 | test_expect_success 'alternative GIT_CONFIG' 'cmp output expect' | |
397 | ||
773a69fb AR |
398 | test_expect_success 'alternative GIT_CONFIG (--file)' \ |
399 | 'git config --file other-config -l > output && cmp output expect' | |
400 | ||
65807ee6 JH |
401 | test_expect_success 'refer config from subdirectory' ' |
402 | mkdir x && | |
403 | ( | |
404 | cd x && | |
405 | echo strasse >expect | |
406 | git config --get --file ../other-config ein.bahn >actual && | |
407 | test_cmp expect actual | |
408 | ) | |
409 | ||
410 | ' | |
411 | ||
5be60078 | 412 | GIT_CONFIG=other-config git config anwohner.park ausweis |
9c3796fc JS |
413 | |
414 | cat > expect << EOF | |
415 | [ein] | |
416 | bahn = strasse | |
417 | [anwohner] | |
418 | park = ausweis | |
419 | EOF | |
420 | ||
421 | test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect' | |
422 | ||
0667fcfb JS |
423 | cat > .git/config << EOF |
424 | # Hallo | |
425 | #Bello | |
426 | [branch "eins"] | |
427 | x = 1 | |
428 | [branch.eins] | |
429 | y = 1 | |
430 | [branch "1 234 blabl/a"] | |
431 | weird | |
432 | EOF | |
433 | ||
434 | test_expect_success "rename section" \ | |
5be60078 | 435 | "git config --rename-section branch.eins branch.zwei" |
0667fcfb JS |
436 | |
437 | cat > expect << EOF | |
438 | # Hallo | |
439 | #Bello | |
440 | [branch "zwei"] | |
441 | x = 1 | |
442 | [branch "zwei"] | |
443 | y = 1 | |
444 | [branch "1 234 blabl/a"] | |
445 | weird | |
446 | EOF | |
447 | ||
3af82863 | 448 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
0667fcfb | 449 | |
41ac414e | 450 | test_expect_success "rename non-existing section" ' |
d492b31c SB |
451 | test_must_fail git config --rename-section \ |
452 | branch."world domination" branch.drei | |
41ac414e | 453 | ' |
0667fcfb | 454 | |
3af82863 | 455 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
0667fcfb JS |
456 | |
457 | test_expect_success "rename another section" \ | |
5be60078 | 458 | 'git config --rename-section branch."1 234 blabl/a" branch.drei' |
0667fcfb JS |
459 | |
460 | cat > expect << EOF | |
461 | # Hallo | |
462 | #Bello | |
463 | [branch "zwei"] | |
464 | x = 1 | |
465 | [branch "zwei"] | |
466 | y = 1 | |
467 | [branch "drei"] | |
468 | weird | |
469 | EOF | |
470 | ||
3af82863 | 471 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
9a5abfc7 AV |
472 | |
473 | cat >> .git/config << EOF | |
474 | [branch "vier"] z = 1 | |
475 | EOF | |
476 | ||
477 | test_expect_success "rename a section with a var on the same line" \ | |
478 | 'git config --rename-section branch.vier branch.zwei' | |
479 | ||
480 | cat > expect << EOF | |
481 | # Hallo | |
482 | #Bello | |
483 | [branch "zwei"] | |
484 | x = 1 | |
485 | [branch "zwei"] | |
486 | y = 1 | |
487 | [branch "drei"] | |
488 | weird | |
489 | [branch "zwei"] | |
490 | z = 1 | |
491 | EOF | |
492 | ||
493 | test_expect_success "rename succeeded" "test_cmp expect .git/config" | |
0667fcfb | 494 | |
118f8b24 PB |
495 | cat >> .git/config << EOF |
496 | [branch "zwei"] a = 1 [branch "vier"] | |
497 | EOF | |
498 | ||
499 | test_expect_success "remove section" "git config --remove-section branch.zwei" | |
500 | ||
501 | cat > expect << EOF | |
502 | # Hallo | |
503 | #Bello | |
504 | [branch "drei"] | |
505 | weird | |
506 | EOF | |
507 | ||
508 | test_expect_success "section was removed properly" \ | |
3af82863 | 509 | "test_cmp expect .git/config" |
118f8b24 | 510 | |
b18a2be3 SP |
511 | rm .git/config |
512 | ||
513 | cat > expect << EOF | |
514 | [gitcvs] | |
515 | enabled = true | |
516 | dbname = %Ggitcvs2.%a.%m.sqlite | |
517 | [gitcvs "ext"] | |
518 | dbname = %Ggitcvs1.%a.%m.sqlite | |
519 | EOF | |
520 | ||
521 | test_expect_success 'section ending' ' | |
522 | ||
5be60078 JH |
523 | git config gitcvs.enabled true && |
524 | git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && | |
525 | git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && | |
b18a2be3 SP |
526 | cmp .git/config expect |
527 | ||
528 | ' | |
529 | ||
d77a64d3 SP |
530 | test_expect_success numbers ' |
531 | ||
5be60078 JH |
532 | git config kilo.gram 1k && |
533 | git config mega.ton 1m && | |
534 | k=$(git config --int --get kilo.gram) && | |
d77a64d3 | 535 | test z1024 = "z$k" && |
5be60078 | 536 | m=$(git config --int --get mega.ton) && |
d77a64d3 SP |
537 | test z1048576 = "z$m" |
538 | ' | |
539 | ||
c8deb5a1 SP |
540 | cat > expect <<EOF |
541 | fatal: bad config value for 'aninvalid.unit' in .git/config | |
542 | EOF | |
543 | ||
544 | test_expect_success 'invalid unit' ' | |
545 | ||
546 | git config aninvalid.unit "1auto" && | |
547 | s=$(git config aninvalid.unit) && | |
548 | test "z1auto" = "z$s" && | |
549 | if git config --int --get aninvalid.unit 2>actual | |
550 | then | |
551 | echo config should have failed | |
552 | false | |
553 | fi && | |
554 | cmp actual expect | |
555 | ' | |
556 | ||
cab333cb FL |
557 | cat > expect << EOF |
558 | true | |
559 | false | |
560 | true | |
561 | false | |
562 | true | |
563 | false | |
564 | true | |
565 | false | |
566 | EOF | |
567 | ||
568 | test_expect_success bool ' | |
569 | ||
5be60078 JH |
570 | git config bool.true1 01 && |
571 | git config bool.true2 -1 && | |
572 | git config bool.true3 YeS && | |
573 | git config bool.true4 true && | |
574 | git config bool.false1 000 && | |
575 | git config bool.false2 "" && | |
576 | git config bool.false3 nO && | |
577 | git config bool.false4 FALSE && | |
cab333cb FL |
578 | rm -f result && |
579 | for i in 1 2 3 4 | |
580 | do | |
5be60078 JH |
581 | git config --bool --get bool.true$i >>result |
582 | git config --bool --get bool.false$i >>result | |
cab333cb FL |
583 | done && |
584 | cmp expect result' | |
585 | ||
41ac414e | 586 | test_expect_success 'invalid bool (--get)' ' |
cab333cb | 587 | |
5be60078 | 588 | git config bool.nobool foobar && |
d492b31c | 589 | test_must_fail git config --bool --get bool.nobool' |
cab333cb | 590 | |
41ac414e | 591 | test_expect_success 'invalid bool (set)' ' |
db1696b8 | 592 | |
d492b31c | 593 | test_must_fail git config --bool bool.nobool foobar' |
db1696b8 FL |
594 | |
595 | rm .git/config | |
596 | ||
597 | cat > expect <<\EOF | |
598 | [bool] | |
599 | true1 = true | |
600 | true2 = true | |
601 | true3 = true | |
602 | true4 = true | |
603 | false1 = false | |
604 | false2 = false | |
605 | false3 = false | |
606 | false4 = false | |
607 | EOF | |
608 | ||
609 | test_expect_success 'set --bool' ' | |
610 | ||
5be60078 JH |
611 | git config --bool bool.true1 01 && |
612 | git config --bool bool.true2 -1 && | |
613 | git config --bool bool.true3 YeS && | |
614 | git config --bool bool.true4 true && | |
615 | git config --bool bool.false1 000 && | |
616 | git config --bool bool.false2 "" && | |
617 | git config --bool bool.false3 nO && | |
618 | git config --bool bool.false4 FALSE && | |
db1696b8 FL |
619 | cmp expect .git/config' |
620 | ||
621 | rm .git/config | |
622 | ||
623 | cat > expect <<\EOF | |
624 | [int] | |
625 | val1 = 1 | |
626 | val2 = -1 | |
627 | val3 = 5242880 | |
628 | EOF | |
629 | ||
630 | test_expect_success 'set --int' ' | |
631 | ||
5be60078 JH |
632 | git config --int int.val1 01 && |
633 | git config --int int.val2 -1 && | |
634 | git config --int int.val3 5m && | |
db1696b8 FL |
635 | cmp expect .git/config' |
636 | ||
cdd4fb15 BG |
637 | rm .git/config |
638 | ||
c35b0b58 JH |
639 | cat >expect <<\EOF |
640 | [bool] | |
641 | true1 = true | |
642 | true2 = true | |
643 | false1 = false | |
644 | false2 = false | |
645 | [int] | |
646 | int1 = 0 | |
647 | int2 = 1 | |
648 | int3 = -1 | |
649 | EOF | |
650 | ||
651 | test_expect_success 'get --bool-or-int' ' | |
652 | ( | |
653 | echo "[bool]" | |
654 | echo true1 | |
655 | echo true2 = true | |
656 | echo false = false | |
657 | echo "[int]" | |
658 | echo int1 = 0 | |
659 | echo int2 = 1 | |
660 | echo int3 = -1 | |
661 | ) >>.git/config && | |
662 | test $(git config --bool-or-int bool.true1) = true && | |
663 | test $(git config --bool-or-int bool.true2) = true && | |
664 | test $(git config --bool-or-int bool.false) = false && | |
665 | test $(git config --bool-or-int int.int1) = 0 && | |
666 | test $(git config --bool-or-int int.int2) = 1 && | |
667 | test $(git config --bool-or-int int.int3) = -1 | |
668 | ||
669 | ' | |
670 | ||
671 | rm .git/config | |
672 | cat >expect <<\EOF | |
673 | [bool] | |
674 | true1 = true | |
675 | false1 = false | |
676 | true2 = true | |
677 | false2 = false | |
678 | [int] | |
679 | int1 = 0 | |
680 | int2 = 1 | |
681 | int3 = -1 | |
682 | EOF | |
683 | ||
684 | test_expect_success 'set --bool-or-int' ' | |
685 | git config --bool-or-int bool.true1 true && | |
686 | git config --bool-or-int bool.false1 false && | |
687 | git config --bool-or-int bool.true2 yes && | |
688 | git config --bool-or-int bool.false2 no && | |
689 | git config --bool-or-int int.int1 0 && | |
690 | git config --bool-or-int int.int2 1 && | |
691 | git config --bool-or-int int.int3 -1 && | |
692 | test_cmp expect .git/config | |
693 | ' | |
694 | ||
695 | rm .git/config | |
696 | ||
1349484e MM |
697 | cat >expect <<\EOF |
698 | [path] | |
699 | home = ~/ | |
700 | normal = /dev/null | |
701 | trailingtilde = foo~ | |
702 | EOF | |
703 | ||
704 | test_expect_success 'set --path' ' | |
705 | git config --path path.home "~/" && | |
706 | git config --path path.normal "/dev/null" && | |
707 | git config --path path.trailingtilde "foo~" && | |
708 | test_cmp expect .git/config' | |
709 | ||
710 | cat >expect <<EOF | |
711 | $HOME/ | |
712 | /dev/null | |
713 | foo~ | |
714 | EOF | |
715 | ||
716 | test_expect_success 'get --path' ' | |
717 | git config --get --path path.home > result && | |
718 | git config --get --path path.normal >> result && | |
719 | git config --get --path path.trailingtilde >> result && | |
720 | test_cmp expect result | |
721 | ' | |
722 | ||
723 | rm .git/config | |
724 | ||
5be60078 JH |
725 | git config quote.leading " test" |
726 | git config quote.ending "test " | |
727 | git config quote.semicolon "test;test" | |
728 | git config quote.hash "test#test" | |
cdd4fb15 BG |
729 | |
730 | cat > expect << EOF | |
731 | [quote] | |
732 | leading = " test" | |
733 | ending = "test " | |
734 | semicolon = "test;test" | |
735 | hash = "test#test" | |
736 | EOF | |
737 | ||
738 | test_expect_success 'quoting' 'cmp .git/config expect' | |
739 | ||
41ac414e | 740 | test_expect_success 'key with newline' ' |
d492b31c | 741 | test_must_fail git config "key.with |
41ac414e | 742 | newline" 123' |
6f71686e | 743 | |
e0d10e1c | 744 | test_expect_success 'value with newline' 'git config key.sub value.with\\\ |
6f71686e JS |
745 | newline' |
746 | ||
83cd10a0 JN |
747 | cat > .git/config <<\EOF |
748 | [section] | |
749 | ; comment \ | |
750 | continued = cont\ | |
751 | inued | |
752 | noncont = not continued ; \ | |
753 | quotecont = "cont;\ | |
754 | inued" | |
755 | EOF | |
756 | ||
757 | cat > expect <<\EOF | |
758 | section.continued=continued | |
759 | section.noncont=not continued | |
760 | section.quotecont=cont;inued | |
761 | EOF | |
762 | ||
e0d10e1c | 763 | git config --list > result |
83cd10a0 JN |
764 | |
765 | test_expect_success 'value continued on next line' 'cmp result expect' | |
766 | ||
2275d502 FL |
767 | cat > .git/config <<\EOF |
768 | [section "sub=section"] | |
769 | val1 = foo=bar | |
770 | val2 = foo\nbar | |
771 | val3 = \n\n | |
772 | val4 = | |
773 | val5 | |
774 | EOF | |
775 | ||
776 | cat > expect <<\EOF | |
2b9a5020 AR |
777 | section.sub=section.val1 |
778 | foo=barQsection.sub=section.val2 | |
779 | foo | |
780 | barQsection.sub=section.val3 | |
2275d502 FL |
781 | |
782 | ||
2b9a5020 AR |
783 | Qsection.sub=section.val4 |
784 | Qsection.sub=section.val5Q | |
2275d502 FL |
785 | EOF |
786 | ||
e85fe4d8 | 787 | git config --null --list | perl -pe 'y/\000/Q/' > result |
2b9a5020 | 788 | echo >>result |
2275d502 FL |
789 | |
790 | test_expect_success '--null --list' 'cmp result expect' | |
791 | ||
e85fe4d8 | 792 | git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result |
2b9a5020 | 793 | echo >>result |
2275d502 FL |
794 | |
795 | test_expect_success '--null --get-regexp' 'cmp result expect' | |
796 | ||
ebdaae37 BS |
797 | test_expect_success 'inner whitespace kept verbatim' ' |
798 | git config section.val "foo bar" && | |
799 | test "z$(git config section.val)" = "zfoo bar" | |
800 | ' | |
801 | ||
704a3143 | 802 | test_expect_success SYMLINKS 'symlinked configuration' ' |
65a5a21d JH |
803 | |
804 | ln -s notyet myconfig && | |
805 | GIT_CONFIG=myconfig git config test.frotz nitfol && | |
806 | test -h myconfig && | |
807 | test -f notyet && | |
808 | test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && | |
809 | GIT_CONFIG=myconfig git config test.xyzzy rezrov && | |
810 | test -h myconfig && | |
811 | test -f notyet && | |
812 | test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && | |
813 | test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov | |
814 | ||
815 | ' | |
816 | ||
dc4179f9 DM |
817 | test_expect_success 'check split_cmdline return' " |
818 | git config alias.split-cmdline-fix 'echo \"' && | |
819 | test_must_fail git split-cmdline-fix && | |
820 | echo foo > foo && | |
821 | git add foo && | |
822 | git commit -m 'initial commit' && | |
823 | git config branch.master.mergeoptions 'echo \"' && | |
824 | test_must_fail git merge master | |
825 | " | |
826 | ||
8b1fa778 AR |
827 | test_expect_success 'git -c "key=value" support' ' |
828 | test "z$(git -c name=value config name)" = zvalue && | |
829 | test "z$(git -c core.name=value config core.name)" = zvalue && | |
830 | test "z$(git -c CamelCase=value config camelcase)" = zvalue && | |
831 | test "z$(git -c flag config --bool flag)" = ztrue && | |
832 | test_must_fail git -c core.name=value config name | |
833 | ' | |
834 | ||
942c1f53 | 835 | test_done |