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