]>
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 | ||
5a953fc5 JK |
10 | test_expect_success 'clear default config' ' |
11 | rm -f .git/config | |
12 | ' | |
942c1f53 JS |
13 | |
14 | cat > expect << EOF | |
942c1f53 JS |
15 | [core] |
16 | penguin = little blue | |
17 | EOF | |
5a953fc5 JK |
18 | test_expect_success 'initial' ' |
19 | git config core.penguin "little blue" && | |
20 | test_cmp expect .git/config | |
21 | ' | |
942c1f53 JS |
22 | |
23 | cat > expect << EOF | |
942c1f53 JS |
24 | [core] |
25 | penguin = little blue | |
26 | Movie = BadPhysics | |
27 | EOF | |
5a953fc5 JK |
28 | test_expect_success 'mixed case' ' |
29 | git config Core.Movie BadPhysics && | |
30 | test_cmp expect .git/config | |
31 | ' | |
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 | |
5a953fc5 JK |
40 | test_expect_success 'similar section' ' |
41 | git config Cores.WhatEver Second | |
42 | test_cmp expect .git/config | |
43 | ' | |
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 | |
5a953fc5 JK |
53 | test_expect_success 'uppercase section' ' |
54 | git config CORE.UPPERCASE true && | |
55 | test_cmp expect .git/config | |
56 | ' | |
942c1f53 | 57 | |
f98d863d | 58 | test_expect_success 'replace with non-match' \ |
5be60078 | 59 | 'git config core.penguin kingpin !blue' |
f98d863d JS |
60 | |
61 | test_expect_success 'replace with non-match (actually matching)' \ | |
5be60078 | 62 | 'git config core.penguin "very blue" !kingpin' |
f98d863d JS |
63 | |
64 | cat > expect << EOF | |
f98d863d JS |
65 | [core] |
66 | penguin = very blue | |
67 | Movie = BadPhysics | |
68 | UPPERCASE = true | |
69 | penguin = kingpin | |
70 | [Cores] | |
71 | WhatEver = Second | |
72 | EOF | |
73 | ||
5a953fc5 | 74 | test_expect_success 'non-match result' 'test_cmp expect .git/config' |
f98d863d | 75 | |
7a31cc0f FL |
76 | cat > .git/config <<\EOF |
77 | [alpha] | |
78 | bar = foo | |
79 | [beta] | |
80 | baz = multiple \ | |
81 | lines | |
82 | EOF | |
83 | ||
84 | test_expect_success 'unset with cont. lines' \ | |
85 | 'git config --unset beta.baz' | |
86 | ||
87 | cat > expect <<\EOF | |
88 | [alpha] | |
89 | bar = foo | |
90 | [beta] | |
91 | EOF | |
92 | ||
5a953fc5 | 93 | test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config' |
7a31cc0f | 94 | |
942c1f53 JS |
95 | cat > .git/config << EOF |
96 | [beta] ; silly comment # another comment | |
97 | noIndent= sillyValue ; 'nother silly comment | |
98 | ||
99 | # empty line | |
100 | ; comment | |
101 | haha ="beta" # last silly comment | |
4ddba79d JS |
102 | haha = hello |
103 | haha = bello | |
942c1f53 JS |
104 | [nextSection] noNewline = ouch |
105 | EOF | |
106 | ||
4ddba79d JS |
107 | cp .git/config .git/config2 |
108 | ||
109 | test_expect_success 'multiple unset' \ | |
5be60078 | 110 | 'git config --unset-all beta.haha' |
4ddba79d JS |
111 | |
112 | cat > expect << EOF | |
113 | [beta] ; silly comment # another comment | |
114 | noIndent= sillyValue ; 'nother silly comment | |
115 | ||
116 | # empty line | |
117 | ; comment | |
118 | [nextSection] noNewline = ouch | |
119 | EOF | |
120 | ||
5a953fc5 | 121 | test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config' |
4ddba79d | 122 | |
bf71b4b3 CR |
123 | cp .git/config2 .git/config |
124 | ||
125 | test_expect_success '--replace-all missing value' ' | |
126 | test_must_fail git config --replace-all beta.haha && | |
127 | test_cmp .git/config2 .git/config | |
128 | ' | |
129 | ||
130 | rm .git/config2 | |
4ddba79d JS |
131 | |
132 | test_expect_success '--replace-all' \ | |
5be60078 | 133 | 'git config --replace-all beta.haha gamma' |
4ddba79d 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 = gamma | |
142 | [nextSection] noNewline = ouch | |
143 | EOF | |
144 | ||
5a953fc5 | 145 | test_expect_success 'all replaced' 'test_cmp expect .git/config' |
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 | |
5a953fc5 JK |
156 | test_expect_success 'really mean test' ' |
157 | git config beta.haha alpha && | |
158 | test_cmp expect .git/config | |
159 | ' | |
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 | |
5a953fc5 JK |
171 | test_expect_success 'really really mean test' ' |
172 | git config nextsection.nonewline wow && | |
173 | test_cmp expect .git/config | |
174 | ' | |
942c1f53 | 175 | |
5be60078 | 176 | test_expect_success 'get value' 'test alpha = $(git config beta.haha)' |
942c1f53 JS |
177 | |
178 | cat > expect << EOF | |
179 | [beta] ; silly comment # another comment | |
180 | noIndent= sillyValue ; 'nother silly comment | |
181 | ||
182 | # empty line | |
183 | ; comment | |
184 | [nextSection] | |
185 | nonewline = wow | |
186 | EOF | |
5a953fc5 JK |
187 | test_expect_success 'unset' ' |
188 | git config --unset beta.haha && | |
189 | test_cmp expect .git/config | |
190 | ' | |
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 = wow | |
200 | NoNewLine = wow2 for me | |
201 | EOF | |
5a953fc5 JK |
202 | test_expect_success 'multivar' ' |
203 | git config nextsection.NoNewLine "wow2 for me" "for me$" && | |
204 | test_cmp expect .git/config | |
205 | ' | |
942c1f53 | 206 | |
f98d863d | 207 | test_expect_success 'non-match' \ |
5be60078 | 208 | 'git config --get nextsection.nonewline !for' |
f98d863d JS |
209 | |
210 | test_expect_success 'non-match value' \ | |
5be60078 | 211 | 'test wow = $(git config --get nextsection.nonewline !for)' |
f98d863d | 212 | |
41ac414e | 213 | test_expect_success 'ambiguous get' ' |
d492b31c | 214 | test_must_fail git config --get nextsection.nonewline |
41ac414e | 215 | ' |
4ddba79d JS |
216 | |
217 | test_expect_success 'get multivar' \ | |
5be60078 | 218 | 'git config --get-all nextsection.nonewline' |
4ddba79d | 219 | |
942c1f53 JS |
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 = wow3 | |
228 | NoNewLine = wow2 for me | |
229 | EOF | |
5a953fc5 JK |
230 | test_expect_success 'multivar replace' ' |
231 | git config nextsection.nonewline "wow3" "wow$" && | |
232 | test_cmp expect .git/config | |
233 | ' | |
942c1f53 | 234 | |
41ac414e | 235 | test_expect_success 'ambiguous value' ' |
d492b31c | 236 | test_must_fail git config nextsection.nonewline |
41ac414e | 237 | ' |
4ddba79d | 238 | |
41ac414e | 239 | test_expect_success 'ambiguous unset' ' |
d492b31c | 240 | test_must_fail git config --unset nextsection.nonewline |
41ac414e | 241 | ' |
942c1f53 | 242 | |
41ac414e | 243 | test_expect_success 'invalid unset' ' |
d492b31c | 244 | test_must_fail git config --unset somesection.nonewline |
41ac414e | 245 | ' |
942c1f53 | 246 | |
942c1f53 JS |
247 | cat > expect << EOF |
248 | [beta] ; silly comment # another comment | |
249 | noIndent= sillyValue ; 'nother silly comment | |
250 | ||
251 | # empty line | |
252 | ; comment | |
253 | [nextSection] | |
254 | NoNewLine = wow2 for me | |
255 | EOF | |
256 | ||
5a953fc5 JK |
257 | test_expect_success 'multivar unset' ' |
258 | git config --unset nextsection.nonewline "wow3$" && | |
259 | test_cmp expect .git/config | |
260 | ' | |
942c1f53 | 261 | |
d492b31c | 262 | test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla' |
942c1f53 | 263 | |
5be60078 | 264 | test_expect_success 'correct key' 'git config 123456.a123 987' |
942c1f53 | 265 | |
b17e659d | 266 | test_expect_success 'hierarchical section' \ |
5be60078 | 267 | 'git config Version.1.2.3eX.Alpha beta' |
b17e659d JS |
268 | |
269 | cat > expect << EOF | |
270 | [beta] ; silly comment # another comment | |
271 | noIndent= sillyValue ; 'nother silly comment | |
272 | ||
273 | # empty line | |
274 | ; comment | |
275 | [nextSection] | |
276 | NoNewLine = wow2 for me | |
277 | [123456] | |
278 | a123 = 987 | |
d14f7764 LT |
279 | [Version "1.2.3eX"] |
280 | Alpha = beta | |
b17e659d JS |
281 | EOF |
282 | ||
5a953fc5 | 283 | test_expect_success 'hierarchical section value' 'test_cmp expect .git/config' |
b17e659d | 284 | |
2fa9a0fb JS |
285 | cat > expect << EOF |
286 | beta.noindent=sillyValue | |
287 | nextsection.nonewline=wow2 for me | |
288 | 123456.a123=987 | |
d55aaefa | 289 | version.1.2.3eX.alpha=beta |
2fa9a0fb JS |
290 | EOF |
291 | ||
292 | test_expect_success 'working --list' \ | |
5be60078 | 293 | 'git config --list > output && cmp output expect' |
2fa9a0fb | 294 | |
1f2baa78 JK |
295 | cat > expect << EOF |
296 | EOF | |
297 | ||
298 | test_expect_success '--list without repo produces empty output' ' | |
299 | git --git-dir=nonexistent config --list >output && | |
300 | test_cmp expect output | |
301 | ' | |
302 | ||
2fa9a0fb JS |
303 | cat > expect << EOF |
304 | beta.noindent sillyValue | |
305 | nextsection.nonewline wow2 for me | |
306 | EOF | |
307 | ||
308 | test_expect_success '--get-regexp' \ | |
5be60078 | 309 | 'git config --get-regexp in > output && cmp output expect' |
2fa9a0fb | 310 | |
89c4afe0 BG |
311 | cat > expect << EOF |
312 | wow2 for me | |
313 | wow4 for you | |
314 | EOF | |
315 | ||
5a953fc5 JK |
316 | test_expect_success '--add' ' |
317 | git config --add nextsection.nonewline "wow4 for you" && | |
318 | git config --get-all nextsection.nonewline > output && | |
319 | test_cmp expect output | |
320 | ' | |
89c4afe0 | 321 | |
f067a137 JF |
322 | cat > .git/config << EOF |
323 | [novalue] | |
324 | variable | |
09bc098c CC |
325 | [emptyvalue] |
326 | variable = | |
f067a137 JF |
327 | EOF |
328 | ||
329 | test_expect_success 'get variable with no value' \ | |
5be60078 | 330 | 'git config --get novalue.variable ^$' |
f067a137 | 331 | |
09bc098c CC |
332 | test_expect_success 'get variable with empty value' \ |
333 | 'git config --get emptyvalue.variable ^$' | |
334 | ||
b69ba460 FL |
335 | echo novalue.variable > expect |
336 | ||
337 | test_expect_success 'get-regexp variable with no value' \ | |
5be60078 | 338 | 'git config --get-regexp novalue > output && |
b69ba460 FL |
339 | cmp output expect' |
340 | ||
09bc098c CC |
341 | echo 'emptyvalue.variable ' > expect |
342 | ||
343 | test_expect_success 'get-regexp variable with empty value' \ | |
344 | 'git config --get-regexp emptyvalue > output && | |
345 | cmp output expect' | |
346 | ||
347 | echo true > expect | |
348 | ||
349 | test_expect_success 'get bool variable with no value' \ | |
350 | 'git config --bool novalue.variable > output && | |
351 | cmp output expect' | |
352 | ||
353 | echo false > expect | |
354 | ||
355 | test_expect_success 'get bool variable with empty value' \ | |
356 | 'git config --bool emptyvalue.variable > output && | |
357 | cmp output expect' | |
358 | ||
003f69b2 JK |
359 | test_expect_success 'no arguments, but no crash' ' |
360 | test_must_fail git config >output 2>&1 && | |
361 | grep usage output | |
362 | ' | |
2fa9a0fb | 363 | |
bd886fd3 SE |
364 | cat > .git/config << EOF |
365 | [a.b] | |
366 | c = d | |
367 | EOF | |
368 | ||
bd886fd3 SE |
369 | cat > expect << EOF |
370 | [a.b] | |
371 | c = d | |
372 | [a] | |
373 | x = y | |
374 | EOF | |
375 | ||
5a953fc5 JK |
376 | test_expect_success 'new section is partial match of another' ' |
377 | git config a.x y && | |
378 | test_cmp expect .git/config | |
379 | ' | |
bd886fd3 SE |
380 | |
381 | cat > expect << EOF | |
382 | [a.b] | |
383 | c = d | |
384 | [a] | |
385 | x = y | |
386 | b = c | |
387 | [b] | |
388 | x = y | |
389 | EOF | |
390 | ||
5a953fc5 JK |
391 | test_expect_success 'new variable inserts into proper section' ' |
392 | git config b.x y && | |
393 | git config a.b c && | |
394 | test_cmp expect .git/config | |
395 | ' | |
bd886fd3 | 396 | |
773a69fb | 397 | test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \ |
003f69b2 | 398 | 'test_must_fail git config --file non-existing-config -l' |
773a69fb | 399 | |
9c3796fc JS |
400 | cat > other-config << EOF |
401 | [ein] | |
402 | bahn = strasse | |
403 | EOF | |
404 | ||
405 | cat > expect << EOF | |
406 | ein.bahn=strasse | |
407 | EOF | |
408 | ||
5a953fc5 JK |
409 | test_expect_success 'alternative GIT_CONFIG' ' |
410 | GIT_CONFIG=other-config git config -l >output && | |
411 | test_cmp expect output | |
412 | ' | |
9c3796fc | 413 | |
773a69fb AR |
414 | test_expect_success 'alternative GIT_CONFIG (--file)' \ |
415 | 'git config --file other-config -l > output && cmp output expect' | |
416 | ||
65807ee6 JH |
417 | test_expect_success 'refer config from subdirectory' ' |
418 | mkdir x && | |
419 | ( | |
420 | cd x && | |
421 | echo strasse >expect | |
422 | git config --get --file ../other-config ein.bahn >actual && | |
423 | test_cmp expect actual | |
424 | ) | |
425 | ||
426 | ' | |
427 | ||
9c3796fc JS |
428 | cat > expect << EOF |
429 | [ein] | |
430 | bahn = strasse | |
431 | [anwohner] | |
432 | park = ausweis | |
433 | EOF | |
434 | ||
5a953fc5 JK |
435 | test_expect_success '--set in alternative GIT_CONFIG' ' |
436 | GIT_CONFIG=other-config git config anwohner.park ausweis && | |
437 | test_cmp expect other-config | |
438 | ' | |
9c3796fc | 439 | |
0667fcfb JS |
440 | cat > .git/config << EOF |
441 | # Hallo | |
442 | #Bello | |
443 | [branch "eins"] | |
444 | x = 1 | |
445 | [branch.eins] | |
446 | y = 1 | |
447 | [branch "1 234 blabl/a"] | |
448 | weird | |
449 | EOF | |
450 | ||
451 | test_expect_success "rename section" \ | |
5be60078 | 452 | "git config --rename-section branch.eins branch.zwei" |
0667fcfb JS |
453 | |
454 | cat > expect << EOF | |
455 | # Hallo | |
456 | #Bello | |
457 | [branch "zwei"] | |
458 | x = 1 | |
459 | [branch "zwei"] | |
460 | y = 1 | |
461 | [branch "1 234 blabl/a"] | |
462 | weird | |
463 | EOF | |
464 | ||
3af82863 | 465 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
0667fcfb | 466 | |
41ac414e | 467 | test_expect_success "rename non-existing section" ' |
d492b31c SB |
468 | test_must_fail git config --rename-section \ |
469 | branch."world domination" branch.drei | |
41ac414e | 470 | ' |
0667fcfb | 471 | |
3af82863 | 472 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
0667fcfb JS |
473 | |
474 | test_expect_success "rename another section" \ | |
5be60078 | 475 | 'git config --rename-section branch."1 234 blabl/a" branch.drei' |
0667fcfb JS |
476 | |
477 | cat > expect << EOF | |
478 | # Hallo | |
479 | #Bello | |
480 | [branch "zwei"] | |
481 | x = 1 | |
482 | [branch "zwei"] | |
483 | y = 1 | |
484 | [branch "drei"] | |
485 | weird | |
486 | EOF | |
487 | ||
3af82863 | 488 | test_expect_success "rename succeeded" "test_cmp expect .git/config" |
9a5abfc7 AV |
489 | |
490 | cat >> .git/config << EOF | |
491 | [branch "vier"] z = 1 | |
492 | EOF | |
493 | ||
494 | test_expect_success "rename a section with a var on the same line" \ | |
495 | 'git config --rename-section branch.vier branch.zwei' | |
496 | ||
497 | cat > expect << EOF | |
498 | # Hallo | |
499 | #Bello | |
500 | [branch "zwei"] | |
501 | x = 1 | |
502 | [branch "zwei"] | |
503 | y = 1 | |
504 | [branch "drei"] | |
505 | weird | |
506 | [branch "zwei"] | |
507 | z = 1 | |
508 | EOF | |
509 | ||
510 | test_expect_success "rename succeeded" "test_cmp expect .git/config" | |
0667fcfb | 511 | |
118f8b24 PB |
512 | cat >> .git/config << EOF |
513 | [branch "zwei"] a = 1 [branch "vier"] | |
514 | EOF | |
515 | ||
516 | test_expect_success "remove section" "git config --remove-section branch.zwei" | |
517 | ||
518 | cat > expect << EOF | |
519 | # Hallo | |
520 | #Bello | |
521 | [branch "drei"] | |
522 | weird | |
523 | EOF | |
524 | ||
525 | test_expect_success "section was removed properly" \ | |
3af82863 | 526 | "test_cmp expect .git/config" |
118f8b24 | 527 | |
b18a2be3 SP |
528 | rm .git/config |
529 | ||
530 | cat > expect << EOF | |
531 | [gitcvs] | |
532 | enabled = true | |
533 | dbname = %Ggitcvs2.%a.%m.sqlite | |
534 | [gitcvs "ext"] | |
535 | dbname = %Ggitcvs1.%a.%m.sqlite | |
536 | EOF | |
537 | ||
538 | test_expect_success 'section ending' ' | |
539 | ||
5be60078 JH |
540 | git config gitcvs.enabled true && |
541 | git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && | |
542 | git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && | |
5a953fc5 | 543 | test_cmp expect .git/config |
b18a2be3 SP |
544 | |
545 | ' | |
546 | ||
d77a64d3 SP |
547 | test_expect_success numbers ' |
548 | ||
5be60078 JH |
549 | git config kilo.gram 1k && |
550 | git config mega.ton 1m && | |
551 | k=$(git config --int --get kilo.gram) && | |
d77a64d3 | 552 | test z1024 = "z$k" && |
5be60078 | 553 | m=$(git config --int --get mega.ton) && |
d77a64d3 SP |
554 | test z1048576 = "z$m" |
555 | ' | |
556 | ||
c8deb5a1 SP |
557 | cat > expect <<EOF |
558 | fatal: bad config value for 'aninvalid.unit' in .git/config | |
559 | EOF | |
560 | ||
561 | test_expect_success 'invalid unit' ' | |
562 | ||
563 | git config aninvalid.unit "1auto" && | |
564 | s=$(git config aninvalid.unit) && | |
565 | test "z1auto" = "z$s" && | |
566 | if git config --int --get aninvalid.unit 2>actual | |
567 | then | |
568 | echo config should have failed | |
569 | false | |
570 | fi && | |
571 | cmp actual expect | |
572 | ' | |
573 | ||
cab333cb FL |
574 | cat > expect << EOF |
575 | true | |
576 | false | |
577 | true | |
578 | false | |
579 | true | |
580 | false | |
581 | true | |
582 | false | |
583 | EOF | |
584 | ||
585 | test_expect_success bool ' | |
586 | ||
5be60078 JH |
587 | git config bool.true1 01 && |
588 | git config bool.true2 -1 && | |
589 | git config bool.true3 YeS && | |
590 | git config bool.true4 true && | |
591 | git config bool.false1 000 && | |
592 | git config bool.false2 "" && | |
593 | git config bool.false3 nO && | |
594 | git config bool.false4 FALSE && | |
cab333cb FL |
595 | rm -f result && |
596 | for i in 1 2 3 4 | |
597 | do | |
5be60078 JH |
598 | git config --bool --get bool.true$i >>result |
599 | git config --bool --get bool.false$i >>result | |
cab333cb FL |
600 | done && |
601 | cmp expect result' | |
602 | ||
41ac414e | 603 | test_expect_success 'invalid bool (--get)' ' |
cab333cb | 604 | |
5be60078 | 605 | git config bool.nobool foobar && |
d492b31c | 606 | test_must_fail git config --bool --get bool.nobool' |
cab333cb | 607 | |
41ac414e | 608 | test_expect_success 'invalid bool (set)' ' |
db1696b8 | 609 | |
d492b31c | 610 | test_must_fail git config --bool bool.nobool foobar' |
db1696b8 FL |
611 | |
612 | rm .git/config | |
613 | ||
614 | cat > expect <<\EOF | |
615 | [bool] | |
616 | true1 = true | |
617 | true2 = true | |
618 | true3 = true | |
619 | true4 = true | |
620 | false1 = false | |
621 | false2 = false | |
622 | false3 = false | |
623 | false4 = false | |
624 | EOF | |
625 | ||
626 | test_expect_success 'set --bool' ' | |
627 | ||
5be60078 JH |
628 | git config --bool bool.true1 01 && |
629 | git config --bool bool.true2 -1 && | |
630 | git config --bool bool.true3 YeS && | |
631 | git config --bool bool.true4 true && | |
632 | git config --bool bool.false1 000 && | |
633 | git config --bool bool.false2 "" && | |
634 | git config --bool bool.false3 nO && | |
635 | git config --bool bool.false4 FALSE && | |
db1696b8 FL |
636 | cmp expect .git/config' |
637 | ||
638 | rm .git/config | |
639 | ||
640 | cat > expect <<\EOF | |
641 | [int] | |
642 | val1 = 1 | |
643 | val2 = -1 | |
644 | val3 = 5242880 | |
645 | EOF | |
646 | ||
647 | test_expect_success 'set --int' ' | |
648 | ||
5be60078 JH |
649 | git config --int int.val1 01 && |
650 | git config --int int.val2 -1 && | |
651 | git config --int int.val3 5m && | |
db1696b8 FL |
652 | cmp expect .git/config' |
653 | ||
cdd4fb15 BG |
654 | rm .git/config |
655 | ||
c35b0b58 JH |
656 | cat >expect <<\EOF |
657 | [bool] | |
658 | true1 = true | |
659 | true2 = true | |
660 | false1 = false | |
661 | false2 = false | |
662 | [int] | |
663 | int1 = 0 | |
664 | int2 = 1 | |
665 | int3 = -1 | |
666 | EOF | |
667 | ||
668 | test_expect_success 'get --bool-or-int' ' | |
669 | ( | |
670 | echo "[bool]" | |
671 | echo true1 | |
672 | echo true2 = true | |
673 | echo false = false | |
674 | echo "[int]" | |
675 | echo int1 = 0 | |
676 | echo int2 = 1 | |
677 | echo int3 = -1 | |
678 | ) >>.git/config && | |
679 | test $(git config --bool-or-int bool.true1) = true && | |
680 | test $(git config --bool-or-int bool.true2) = true && | |
681 | test $(git config --bool-or-int bool.false) = false && | |
682 | test $(git config --bool-or-int int.int1) = 0 && | |
683 | test $(git config --bool-or-int int.int2) = 1 && | |
684 | test $(git config --bool-or-int int.int3) = -1 | |
685 | ||
686 | ' | |
687 | ||
688 | rm .git/config | |
689 | cat >expect <<\EOF | |
690 | [bool] | |
691 | true1 = true | |
692 | false1 = false | |
693 | true2 = true | |
694 | false2 = false | |
695 | [int] | |
696 | int1 = 0 | |
697 | int2 = 1 | |
698 | int3 = -1 | |
699 | EOF | |
700 | ||
701 | test_expect_success 'set --bool-or-int' ' | |
702 | git config --bool-or-int bool.true1 true && | |
703 | git config --bool-or-int bool.false1 false && | |
704 | git config --bool-or-int bool.true2 yes && | |
705 | git config --bool-or-int bool.false2 no && | |
706 | git config --bool-or-int int.int1 0 && | |
707 | git config --bool-or-int int.int2 1 && | |
708 | git config --bool-or-int int.int3 -1 && | |
709 | test_cmp expect .git/config | |
710 | ' | |
711 | ||
712 | rm .git/config | |
713 | ||
1349484e MM |
714 | cat >expect <<\EOF |
715 | [path] | |
716 | home = ~/ | |
717 | normal = /dev/null | |
718 | trailingtilde = foo~ | |
719 | EOF | |
720 | ||
3ba9ba8f | 721 | test_expect_success NOT_MINGW 'set --path' ' |
1349484e MM |
722 | git config --path path.home "~/" && |
723 | git config --path path.normal "/dev/null" && | |
724 | git config --path path.trailingtilde "foo~" && | |
725 | test_cmp expect .git/config' | |
726 | ||
3ba9ba8f | 727 | if test_have_prereq NOT_MINGW && test "${HOME+set}" |
79bf1490 JN |
728 | then |
729 | test_set_prereq HOMEVAR | |
730 | fi | |
731 | ||
1349484e MM |
732 | cat >expect <<EOF |
733 | $HOME/ | |
734 | /dev/null | |
735 | foo~ | |
736 | EOF | |
737 | ||
79bf1490 | 738 | test_expect_success HOMEVAR 'get --path' ' |
1349484e MM |
739 | git config --get --path path.home > result && |
740 | git config --get --path path.normal >> result && | |
741 | git config --get --path path.trailingtilde >> result && | |
742 | test_cmp expect result | |
743 | ' | |
744 | ||
79bf1490 JN |
745 | cat >expect <<\EOF |
746 | /dev/null | |
747 | foo~ | |
748 | EOF | |
749 | ||
3ba9ba8f | 750 | test_expect_success NOT_MINGW 'get --path copes with unset $HOME' ' |
79bf1490 JN |
751 | ( |
752 | unset HOME; | |
753 | test_must_fail git config --get --path path.home \ | |
754 | >result 2>msg && | |
755 | git config --get --path path.normal >>result && | |
756 | git config --get --path path.trailingtilde >>result | |
757 | ) && | |
758 | grep "[Ff]ailed to expand.*~/" msg && | |
759 | test_cmp expect result | |
760 | ' | |
761 | ||
cdd4fb15 BG |
762 | cat > expect << EOF |
763 | [quote] | |
764 | leading = " test" | |
765 | ending = "test " | |
766 | semicolon = "test;test" | |
767 | hash = "test#test" | |
768 | EOF | |
5a953fc5 JK |
769 | test_expect_success 'quoting' ' |
770 | rm .git/config && | |
771 | git config quote.leading " test" && | |
772 | git config quote.ending "test " && | |
773 | git config quote.semicolon "test;test" && | |
774 | git config quote.hash "test#test" && | |
775 | test_cmp expect .git/config | |
776 | ' | |
cdd4fb15 | 777 | |
41ac414e | 778 | test_expect_success 'key with newline' ' |
d492b31c | 779 | test_must_fail git config "key.with |
41ac414e | 780 | newline" 123' |
6f71686e | 781 | |
e0d10e1c | 782 | test_expect_success 'value with newline' 'git config key.sub value.with\\\ |
6f71686e JS |
783 | newline' |
784 | ||
83cd10a0 JN |
785 | cat > .git/config <<\EOF |
786 | [section] | |
787 | ; comment \ | |
788 | continued = cont\ | |
789 | inued | |
790 | noncont = not continued ; \ | |
791 | quotecont = "cont;\ | |
792 | inued" | |
793 | EOF | |
794 | ||
795 | cat > expect <<\EOF | |
796 | section.continued=continued | |
797 | section.noncont=not continued | |
798 | section.quotecont=cont;inued | |
799 | EOF | |
800 | ||
5a953fc5 JK |
801 | test_expect_success 'value continued on next line' ' |
802 | git config --list > result && | |
803 | cmp result expect | |
804 | ' | |
83cd10a0 | 805 | |
2275d502 FL |
806 | cat > .git/config <<\EOF |
807 | [section "sub=section"] | |
808 | val1 = foo=bar | |
809 | val2 = foo\nbar | |
810 | val3 = \n\n | |
811 | val4 = | |
812 | val5 | |
813 | EOF | |
814 | ||
815 | cat > expect <<\EOF | |
2b9a5020 AR |
816 | section.sub=section.val1 |
817 | foo=barQsection.sub=section.val2 | |
818 | foo | |
819 | barQsection.sub=section.val3 | |
2275d502 FL |
820 | |
821 | ||
2b9a5020 AR |
822 | Qsection.sub=section.val4 |
823 | Qsection.sub=section.val5Q | |
2275d502 | 824 | EOF |
5a953fc5 JK |
825 | test_expect_success '--null --list' ' |
826 | git config --null --list | nul_to_q >result && | |
827 | echo >>result && | |
828 | test_cmp expect result | |
829 | ' | |
2275d502 | 830 | |
5a953fc5 JK |
831 | test_expect_success '--null --get-regexp' ' |
832 | git config --null --get-regexp "val[0-9]" | nul_to_q >result && | |
833 | echo >>result && | |
834 | test_cmp expect result | |
835 | ' | |
2275d502 | 836 | |
ebdaae37 BS |
837 | test_expect_success 'inner whitespace kept verbatim' ' |
838 | git config section.val "foo bar" && | |
839 | test "z$(git config section.val)" = "zfoo bar" | |
840 | ' | |
841 | ||
704a3143 | 842 | test_expect_success SYMLINKS 'symlinked configuration' ' |
65a5a21d JH |
843 | |
844 | ln -s notyet myconfig && | |
845 | GIT_CONFIG=myconfig git config test.frotz nitfol && | |
846 | test -h myconfig && | |
847 | test -f notyet && | |
848 | test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && | |
849 | GIT_CONFIG=myconfig git config test.xyzzy rezrov && | |
850 | test -h myconfig && | |
851 | test -f notyet && | |
852 | test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && | |
853 | test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov | |
854 | ||
855 | ' | |
856 | ||
1f2baa78 JK |
857 | test_expect_success 'nonexistent configuration' ' |
858 | ( | |
859 | GIT_CONFIG=doesnotexist && | |
860 | export GIT_CONFIG && | |
861 | test_must_fail git config --list && | |
862 | test_must_fail git config test.xyzzy | |
863 | ) | |
864 | ' | |
865 | ||
866 | test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' | |
867 | ln -s doesnotexist linktonada && | |
868 | ln -s linktonada linktolinktonada && | |
869 | ( | |
870 | GIT_CONFIG=linktonada && | |
871 | export GIT_CONFIG && | |
872 | test_must_fail git config --list && | |
873 | GIT_CONFIG=linktolinktonada && | |
874 | test_must_fail git config --list | |
875 | ) | |
876 | ' | |
877 | ||
dc4179f9 DM |
878 | test_expect_success 'check split_cmdline return' " |
879 | git config alias.split-cmdline-fix 'echo \"' && | |
880 | test_must_fail git split-cmdline-fix && | |
881 | echo foo > foo && | |
882 | git add foo && | |
883 | git commit -m 'initial commit' && | |
884 | git config branch.master.mergeoptions 'echo \"' && | |
885 | test_must_fail git merge master | |
886 | " | |
887 | ||
8b1fa778 | 888 | test_expect_success 'git -c "key=value" support' ' |
8b1fa778 | 889 | test "z$(git -c core.name=value config core.name)" = zvalue && |
b09c53a3 LP |
890 | test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue && |
891 | test "z$(git -c foo.flag config --bool foo.flag)" = ztrue && | |
892 | test_must_fail git -c name=value config core.name | |
893 | ' | |
894 | ||
895 | test_expect_success 'key sanity-checking' ' | |
896 | test_must_fail git config foo=bar && | |
897 | test_must_fail git config foo=.bar && | |
898 | test_must_fail git config foo.ba=r && | |
899 | test_must_fail git config foo.1bar && | |
900 | test_must_fail git config foo."ba | |
901 | z".bar && | |
2169ddc0 LP |
902 | test_must_fail git config . false && |
903 | test_must_fail git config .foo false && | |
904 | test_must_fail git config foo. false && | |
905 | test_must_fail git config .foo. false && | |
b09c53a3 LP |
906 | git config foo.bar true && |
907 | git config foo."ba =z".bar false | |
8b1fa778 AR |
908 | ' |
909 | ||
73546c08 | 910 | test_expect_success 'git -c works with aliases of builtins' ' |
06eb708f JK |
911 | git config alias.checkconfig "-c foo.check=bar config foo.check" && |
912 | echo bar >expect && | |
913 | git checkconfig >actual && | |
914 | test_cmp expect actual | |
915 | ' | |
916 | ||
5bf6529a JK |
917 | test_expect_success 'git -c does not split values on equals' ' |
918 | echo "value with = in it" >expect && | |
919 | git -c core.foo="value with = in it" config core.foo >actual && | |
920 | test_cmp expect actual | |
921 | ' | |
922 | ||
1c2c9bee JK |
923 | test_expect_success 'git -c dies on bogus config' ' |
924 | test_must_fail git -c core.bare=foo rev-parse | |
925 | ' | |
926 | ||
927 | test_expect_success 'git -c complains about empty key' ' | |
928 | test_must_fail git -c "=foo" rev-parse | |
929 | ' | |
930 | ||
c5d6350b JK |
931 | test_expect_success 'git -c complains about empty key and value' ' |
932 | test_must_fail git -c "" rev-parse | |
933 | ' | |
934 | ||
942c1f53 | 935 | test_done |