]>
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 | 290 | |
1f2baa78 JK |
291 | cat > expect << EOF |
292 | EOF | |
293 | ||
294 | test_expect_success '--list without repo produces empty output' ' | |
295 | git --git-dir=nonexistent config --list >output && | |
296 | test_cmp expect output | |
297 | ' | |
298 | ||
2fa9a0fb JS |
299 | cat > expect << EOF |
300 | beta.noindent sillyValue | |
301 | nextsection.nonewline wow2 for me | |
302 | EOF | |
303 | ||
304 | test_expect_success '--get-regexp' \ | |
5be60078 | 305 | 'git config --get-regexp in > output && cmp output expect' |
2fa9a0fb | 306 | |
5be60078 | 307 | git config --add nextsection.nonewline "wow4 for you" |
89c4afe0 BG |
308 | |
309 | cat > expect << EOF | |
310 | wow2 for me | |
311 | wow4 for you | |
312 | EOF | |
313 | ||
314 | test_expect_success '--add' \ | |
5be60078 | 315 | 'git config --get-all nextsection.nonewline > output && cmp output expect' |
89c4afe0 | 316 | |
f067a137 JF |
317 | cat > .git/config << EOF |
318 | [novalue] | |
319 | variable | |
09bc098c CC |
320 | [emptyvalue] |
321 | variable = | |
f067a137 JF |
322 | EOF |
323 | ||
324 | test_expect_success 'get variable with no value' \ | |
5be60078 | 325 | 'git config --get novalue.variable ^$' |
f067a137 | 326 | |
09bc098c CC |
327 | test_expect_success 'get variable with empty value' \ |
328 | 'git config --get emptyvalue.variable ^$' | |
329 | ||
b69ba460 FL |
330 | echo novalue.variable > expect |
331 | ||
332 | test_expect_success 'get-regexp variable with no value' \ | |
5be60078 | 333 | 'git config --get-regexp novalue > output && |
b69ba460 FL |
334 | cmp output expect' |
335 | ||
09bc098c CC |
336 | echo 'emptyvalue.variable ' > expect |
337 | ||
338 | test_expect_success 'get-regexp variable with empty value' \ | |
339 | 'git config --get-regexp emptyvalue > output && | |
340 | cmp output expect' | |
341 | ||
342 | echo true > expect | |
343 | ||
344 | test_expect_success 'get bool variable with no value' \ | |
345 | 'git config --bool novalue.variable > output && | |
346 | cmp output expect' | |
347 | ||
348 | echo false > expect | |
349 | ||
350 | test_expect_success 'get bool variable with empty value' \ | |
351 | 'git config --bool emptyvalue.variable > output && | |
352 | cmp output expect' | |
353 | ||
003f69b2 JK |
354 | test_expect_success 'no arguments, but no crash' ' |
355 | test_must_fail git config >output 2>&1 && | |
356 | grep usage output | |
357 | ' | |
2fa9a0fb | 358 | |
bd886fd3 SE |
359 | cat > .git/config << EOF |
360 | [a.b] | |
361 | c = d | |
362 | EOF | |
363 | ||
5be60078 | 364 | git config a.x y |
bd886fd3 SE |
365 | |
366 | cat > expect << EOF | |
367 | [a.b] | |
368 | c = d | |
369 | [a] | |
370 | x = y | |
371 | EOF | |
372 | ||
373 | test_expect_success 'new section is partial match of another' 'cmp .git/config expect' | |
374 | ||
5be60078 JH |
375 | git config b.x y |
376 | git config a.b c | |
bd886fd3 SE |
377 | |
378 | cat > expect << EOF | |
379 | [a.b] | |
380 | c = d | |
381 | [a] | |
382 | x = y | |
383 | b = c | |
384 | [b] | |
385 | x = y | |
386 | EOF | |
387 | ||
388 | test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect' | |
389 | ||
773a69fb | 390 | test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \ |
003f69b2 | 391 | 'test_must_fail git config --file non-existing-config -l' |
773a69fb | 392 | |
9c3796fc JS |
393 | cat > other-config << EOF |
394 | [ein] | |
395 | bahn = strasse | |
396 | EOF | |
397 | ||
398 | cat > expect << EOF | |
399 | ein.bahn=strasse | |
400 | EOF | |
401 | ||
5be60078 | 402 | GIT_CONFIG=other-config git config -l > output |
9c3796fc JS |
403 | |
404 | test_expect_success 'alternative GIT_CONFIG' 'cmp output expect' | |
405 | ||
773a69fb AR |
406 | test_expect_success 'alternative GIT_CONFIG (--file)' \ |
407 | 'git config --file other-config -l > output && cmp output expect' | |
408 | ||
65807ee6 JH |
409 | test_expect_success 'refer config from subdirectory' ' |
410 | mkdir x && | |
411 | ( | |
412 | cd x && | |
413 | echo strasse >expect | |
414 | git config --get --file ../other-config ein.bahn >actual && | |
415 | test_cmp expect actual | |
416 | ) | |
417 | ||
418 | ' | |
419 | ||
5be60078 | 420 | GIT_CONFIG=other-config git config anwohner.park ausweis |
9c3796fc JS |
421 | |
422 | cat > expect << EOF | |
423 | [ein] | |
424 | bahn = strasse | |
425 | [anwohner] | |
426 | park = ausweis | |
427 | EOF | |
428 | ||
429 | test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect' | |
430 | ||
0667fcfb JS |
431 | cat > .git/config << EOF |
432 | # Hallo | |
433 | #Bello | |
434 | [branch "eins"] | |
435 | x = 1 | |
436 | [branch.eins] | |
437 | y = 1 | |
438 | [branch "1 234 blabl/a"] | |
439 | weird | |
440 | EOF | |
441 | ||
442 | test_expect_success "rename section" \ | |
5be60078 | 443 | "git config --rename-section branch.eins branch.zwei" |
0667fcfb JS |
444 | |
445 | cat > expect << EOF | |
446 | # Hallo | |
447 | #Bello | |
448 | [branch "zwei"] | |
449 | x = 1 | |
450 | [branch "zwei"] | |
451 | y = 1 | |
452 | [branch "1 234 blabl/a"] | |
453 | weird | |
454 | EOF | |
455 | ||
3af82863 | 456 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
0667fcfb | 457 | |
41ac414e | 458 | test_expect_success "rename non-existing section" ' |
d492b31c SB |
459 | test_must_fail git config --rename-section \ |
460 | branch."world domination" branch.drei | |
41ac414e | 461 | ' |
0667fcfb | 462 | |
3af82863 | 463 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
0667fcfb JS |
464 | |
465 | test_expect_success "rename another section" \ | |
5be60078 | 466 | 'git config --rename-section branch."1 234 blabl/a" branch.drei' |
0667fcfb JS |
467 | |
468 | cat > expect << EOF | |
469 | # Hallo | |
470 | #Bello | |
471 | [branch "zwei"] | |
472 | x = 1 | |
473 | [branch "zwei"] | |
474 | y = 1 | |
475 | [branch "drei"] | |
476 | weird | |
477 | EOF | |
478 | ||
3af82863 | 479 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
9a5abfc7 AV |
480 | |
481 | cat >> .git/config << EOF | |
482 | [branch "vier"] z = 1 | |
483 | EOF | |
484 | ||
485 | test_expect_success "rename a section with a var on the same line" \ | |
486 | 'git config --rename-section branch.vier branch.zwei' | |
487 | ||
488 | cat > expect << EOF | |
489 | # Hallo | |
490 | #Bello | |
491 | [branch "zwei"] | |
492 | x = 1 | |
493 | [branch "zwei"] | |
494 | y = 1 | |
495 | [branch "drei"] | |
496 | weird | |
497 | [branch "zwei"] | |
498 | z = 1 | |
499 | EOF | |
500 | ||
501 | test_expect_success "rename succeeded" "test_cmp expect .git/config" | |
0667fcfb | 502 | |
118f8b24 PB |
503 | cat >> .git/config << EOF |
504 | [branch "zwei"] a = 1 [branch "vier"] | |
505 | EOF | |
506 | ||
507 | test_expect_success "remove section" "git config --remove-section branch.zwei" | |
508 | ||
509 | cat > expect << EOF | |
510 | # Hallo | |
511 | #Bello | |
512 | [branch "drei"] | |
513 | weird | |
514 | EOF | |
515 | ||
516 | test_expect_success "section was removed properly" \ | |
3af82863 | 517 | "test_cmp expect .git/config" |
118f8b24 | 518 | |
b18a2be3 SP |
519 | rm .git/config |
520 | ||
521 | cat > expect << EOF | |
522 | [gitcvs] | |
523 | enabled = true | |
524 | dbname = %Ggitcvs2.%a.%m.sqlite | |
525 | [gitcvs "ext"] | |
526 | dbname = %Ggitcvs1.%a.%m.sqlite | |
527 | EOF | |
528 | ||
529 | test_expect_success 'section ending' ' | |
530 | ||
5be60078 JH |
531 | git config gitcvs.enabled true && |
532 | git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && | |
533 | git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && | |
b18a2be3 SP |
534 | cmp .git/config expect |
535 | ||
536 | ' | |
537 | ||
d77a64d3 SP |
538 | test_expect_success numbers ' |
539 | ||
5be60078 JH |
540 | git config kilo.gram 1k && |
541 | git config mega.ton 1m && | |
542 | k=$(git config --int --get kilo.gram) && | |
d77a64d3 | 543 | test z1024 = "z$k" && |
5be60078 | 544 | m=$(git config --int --get mega.ton) && |
d77a64d3 SP |
545 | test z1048576 = "z$m" |
546 | ' | |
547 | ||
c8deb5a1 SP |
548 | cat > expect <<EOF |
549 | fatal: bad config value for 'aninvalid.unit' in .git/config | |
550 | EOF | |
551 | ||
552 | test_expect_success 'invalid unit' ' | |
553 | ||
554 | git config aninvalid.unit "1auto" && | |
555 | s=$(git config aninvalid.unit) && | |
556 | test "z1auto" = "z$s" && | |
557 | if git config --int --get aninvalid.unit 2>actual | |
558 | then | |
559 | echo config should have failed | |
560 | false | |
561 | fi && | |
562 | cmp actual expect | |
563 | ' | |
564 | ||
cab333cb FL |
565 | cat > expect << EOF |
566 | true | |
567 | false | |
568 | true | |
569 | false | |
570 | true | |
571 | false | |
572 | true | |
573 | false | |
574 | EOF | |
575 | ||
576 | test_expect_success bool ' | |
577 | ||
5be60078 JH |
578 | git config bool.true1 01 && |
579 | git config bool.true2 -1 && | |
580 | git config bool.true3 YeS && | |
581 | git config bool.true4 true && | |
582 | git config bool.false1 000 && | |
583 | git config bool.false2 "" && | |
584 | git config bool.false3 nO && | |
585 | git config bool.false4 FALSE && | |
cab333cb FL |
586 | rm -f result && |
587 | for i in 1 2 3 4 | |
588 | do | |
5be60078 JH |
589 | git config --bool --get bool.true$i >>result |
590 | git config --bool --get bool.false$i >>result | |
cab333cb FL |
591 | done && |
592 | cmp expect result' | |
593 | ||
41ac414e | 594 | test_expect_success 'invalid bool (--get)' ' |
cab333cb | 595 | |
5be60078 | 596 | git config bool.nobool foobar && |
d492b31c | 597 | test_must_fail git config --bool --get bool.nobool' |
cab333cb | 598 | |
41ac414e | 599 | test_expect_success 'invalid bool (set)' ' |
db1696b8 | 600 | |
d492b31c | 601 | test_must_fail git config --bool bool.nobool foobar' |
db1696b8 FL |
602 | |
603 | rm .git/config | |
604 | ||
605 | cat > expect <<\EOF | |
606 | [bool] | |
607 | true1 = true | |
608 | true2 = true | |
609 | true3 = true | |
610 | true4 = true | |
611 | false1 = false | |
612 | false2 = false | |
613 | false3 = false | |
614 | false4 = false | |
615 | EOF | |
616 | ||
617 | test_expect_success 'set --bool' ' | |
618 | ||
5be60078 JH |
619 | git config --bool bool.true1 01 && |
620 | git config --bool bool.true2 -1 && | |
621 | git config --bool bool.true3 YeS && | |
622 | git config --bool bool.true4 true && | |
623 | git config --bool bool.false1 000 && | |
624 | git config --bool bool.false2 "" && | |
625 | git config --bool bool.false3 nO && | |
626 | git config --bool bool.false4 FALSE && | |
db1696b8 FL |
627 | cmp expect .git/config' |
628 | ||
629 | rm .git/config | |
630 | ||
631 | cat > expect <<\EOF | |
632 | [int] | |
633 | val1 = 1 | |
634 | val2 = -1 | |
635 | val3 = 5242880 | |
636 | EOF | |
637 | ||
638 | test_expect_success 'set --int' ' | |
639 | ||
5be60078 JH |
640 | git config --int int.val1 01 && |
641 | git config --int int.val2 -1 && | |
642 | git config --int int.val3 5m && | |
db1696b8 FL |
643 | cmp expect .git/config' |
644 | ||
cdd4fb15 BG |
645 | rm .git/config |
646 | ||
c35b0b58 JH |
647 | cat >expect <<\EOF |
648 | [bool] | |
649 | true1 = true | |
650 | true2 = true | |
651 | false1 = false | |
652 | false2 = false | |
653 | [int] | |
654 | int1 = 0 | |
655 | int2 = 1 | |
656 | int3 = -1 | |
657 | EOF | |
658 | ||
659 | test_expect_success 'get --bool-or-int' ' | |
660 | ( | |
661 | echo "[bool]" | |
662 | echo true1 | |
663 | echo true2 = true | |
664 | echo false = false | |
665 | echo "[int]" | |
666 | echo int1 = 0 | |
667 | echo int2 = 1 | |
668 | echo int3 = -1 | |
669 | ) >>.git/config && | |
670 | test $(git config --bool-or-int bool.true1) = true && | |
671 | test $(git config --bool-or-int bool.true2) = true && | |
672 | test $(git config --bool-or-int bool.false) = false && | |
673 | test $(git config --bool-or-int int.int1) = 0 && | |
674 | test $(git config --bool-or-int int.int2) = 1 && | |
675 | test $(git config --bool-or-int int.int3) = -1 | |
676 | ||
677 | ' | |
678 | ||
679 | rm .git/config | |
680 | cat >expect <<\EOF | |
681 | [bool] | |
682 | true1 = true | |
683 | false1 = false | |
684 | true2 = true | |
685 | false2 = false | |
686 | [int] | |
687 | int1 = 0 | |
688 | int2 = 1 | |
689 | int3 = -1 | |
690 | EOF | |
691 | ||
692 | test_expect_success 'set --bool-or-int' ' | |
693 | git config --bool-or-int bool.true1 true && | |
694 | git config --bool-or-int bool.false1 false && | |
695 | git config --bool-or-int bool.true2 yes && | |
696 | git config --bool-or-int bool.false2 no && | |
697 | git config --bool-or-int int.int1 0 && | |
698 | git config --bool-or-int int.int2 1 && | |
699 | git config --bool-or-int int.int3 -1 && | |
700 | test_cmp expect .git/config | |
701 | ' | |
702 | ||
703 | rm .git/config | |
704 | ||
1349484e MM |
705 | cat >expect <<\EOF |
706 | [path] | |
707 | home = ~/ | |
708 | normal = /dev/null | |
709 | trailingtilde = foo~ | |
710 | EOF | |
711 | ||
3ba9ba8f | 712 | test_expect_success NOT_MINGW 'set --path' ' |
1349484e MM |
713 | git config --path path.home "~/" && |
714 | git config --path path.normal "/dev/null" && | |
715 | git config --path path.trailingtilde "foo~" && | |
716 | test_cmp expect .git/config' | |
717 | ||
3ba9ba8f | 718 | if test_have_prereq NOT_MINGW && test "${HOME+set}" |
79bf1490 JN |
719 | then |
720 | test_set_prereq HOMEVAR | |
721 | fi | |
722 | ||
1349484e MM |
723 | cat >expect <<EOF |
724 | $HOME/ | |
725 | /dev/null | |
726 | foo~ | |
727 | EOF | |
728 | ||
79bf1490 | 729 | test_expect_success HOMEVAR 'get --path' ' |
1349484e MM |
730 | git config --get --path path.home > result && |
731 | git config --get --path path.normal >> result && | |
732 | git config --get --path path.trailingtilde >> result && | |
733 | test_cmp expect result | |
734 | ' | |
735 | ||
79bf1490 JN |
736 | cat >expect <<\EOF |
737 | /dev/null | |
738 | foo~ | |
739 | EOF | |
740 | ||
3ba9ba8f | 741 | test_expect_success NOT_MINGW 'get --path copes with unset $HOME' ' |
79bf1490 JN |
742 | ( |
743 | unset HOME; | |
744 | test_must_fail git config --get --path path.home \ | |
745 | >result 2>msg && | |
746 | git config --get --path path.normal >>result && | |
747 | git config --get --path path.trailingtilde >>result | |
748 | ) && | |
749 | grep "[Ff]ailed to expand.*~/" msg && | |
750 | test_cmp expect result | |
751 | ' | |
752 | ||
1349484e MM |
753 | rm .git/config |
754 | ||
5be60078 JH |
755 | git config quote.leading " test" |
756 | git config quote.ending "test " | |
757 | git config quote.semicolon "test;test" | |
758 | git config quote.hash "test#test" | |
cdd4fb15 BG |
759 | |
760 | cat > expect << EOF | |
761 | [quote] | |
762 | leading = " test" | |
763 | ending = "test " | |
764 | semicolon = "test;test" | |
765 | hash = "test#test" | |
766 | EOF | |
767 | ||
768 | test_expect_success 'quoting' 'cmp .git/config expect' | |
769 | ||
41ac414e | 770 | test_expect_success 'key with newline' ' |
d492b31c | 771 | test_must_fail git config "key.with |
41ac414e | 772 | newline" 123' |
6f71686e | 773 | |
e0d10e1c | 774 | test_expect_success 'value with newline' 'git config key.sub value.with\\\ |
6f71686e JS |
775 | newline' |
776 | ||
83cd10a0 JN |
777 | cat > .git/config <<\EOF |
778 | [section] | |
779 | ; comment \ | |
780 | continued = cont\ | |
781 | inued | |
782 | noncont = not continued ; \ | |
783 | quotecont = "cont;\ | |
784 | inued" | |
785 | EOF | |
786 | ||
787 | cat > expect <<\EOF | |
788 | section.continued=continued | |
789 | section.noncont=not continued | |
790 | section.quotecont=cont;inued | |
791 | EOF | |
792 | ||
e0d10e1c | 793 | git config --list > result |
83cd10a0 JN |
794 | |
795 | test_expect_success 'value continued on next line' 'cmp result expect' | |
796 | ||
2275d502 FL |
797 | cat > .git/config <<\EOF |
798 | [section "sub=section"] | |
799 | val1 = foo=bar | |
800 | val2 = foo\nbar | |
801 | val3 = \n\n | |
802 | val4 = | |
803 | val5 | |
804 | EOF | |
805 | ||
806 | cat > expect <<\EOF | |
2b9a5020 AR |
807 | section.sub=section.val1 |
808 | foo=barQsection.sub=section.val2 | |
809 | foo | |
810 | barQsection.sub=section.val3 | |
2275d502 FL |
811 | |
812 | ||
2b9a5020 AR |
813 | Qsection.sub=section.val4 |
814 | Qsection.sub=section.val5Q | |
2275d502 FL |
815 | EOF |
816 | ||
e85fe4d8 | 817 | git config --null --list | perl -pe 'y/\000/Q/' > result |
2b9a5020 | 818 | echo >>result |
2275d502 FL |
819 | |
820 | test_expect_success '--null --list' 'cmp result expect' | |
821 | ||
e85fe4d8 | 822 | git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result |
2b9a5020 | 823 | echo >>result |
2275d502 FL |
824 | |
825 | test_expect_success '--null --get-regexp' 'cmp result expect' | |
826 | ||
ebdaae37 BS |
827 | test_expect_success 'inner whitespace kept verbatim' ' |
828 | git config section.val "foo bar" && | |
829 | test "z$(git config section.val)" = "zfoo bar" | |
830 | ' | |
831 | ||
704a3143 | 832 | test_expect_success SYMLINKS 'symlinked configuration' ' |
65a5a21d JH |
833 | |
834 | ln -s notyet myconfig && | |
835 | GIT_CONFIG=myconfig git config test.frotz nitfol && | |
836 | test -h myconfig && | |
837 | test -f notyet && | |
838 | test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && | |
839 | GIT_CONFIG=myconfig git config test.xyzzy rezrov && | |
840 | test -h myconfig && | |
841 | test -f notyet && | |
842 | test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && | |
843 | test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov | |
844 | ||
845 | ' | |
846 | ||
1f2baa78 JK |
847 | test_expect_success 'nonexistent configuration' ' |
848 | ( | |
849 | GIT_CONFIG=doesnotexist && | |
850 | export GIT_CONFIG && | |
851 | test_must_fail git config --list && | |
852 | test_must_fail git config test.xyzzy | |
853 | ) | |
854 | ' | |
855 | ||
856 | test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' | |
857 | ln -s doesnotexist linktonada && | |
858 | ln -s linktonada linktolinktonada && | |
859 | ( | |
860 | GIT_CONFIG=linktonada && | |
861 | export GIT_CONFIG && | |
862 | test_must_fail git config --list && | |
863 | GIT_CONFIG=linktolinktonada && | |
864 | test_must_fail git config --list | |
865 | ) | |
866 | ' | |
867 | ||
dc4179f9 DM |
868 | test_expect_success 'check split_cmdline return' " |
869 | git config alias.split-cmdline-fix 'echo \"' && | |
870 | test_must_fail git split-cmdline-fix && | |
871 | echo foo > foo && | |
872 | git add foo && | |
873 | git commit -m 'initial commit' && | |
874 | git config branch.master.mergeoptions 'echo \"' && | |
875 | test_must_fail git merge master | |
876 | " | |
877 | ||
8b1fa778 AR |
878 | test_expect_success 'git -c "key=value" support' ' |
879 | test "z$(git -c name=value config name)" = zvalue && | |
880 | test "z$(git -c core.name=value config core.name)" = zvalue && | |
881 | test "z$(git -c CamelCase=value config camelcase)" = zvalue && | |
882 | test "z$(git -c flag config --bool flag)" = ztrue && | |
883 | test_must_fail git -c core.name=value config name | |
884 | ' | |
885 | ||
942c1f53 | 886 | test_done |