]>
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 | |
ed838e66 JK |
58 | test_expect_success 'replace with non-match' ' |
59 | git config core.penguin kingpin !blue | |
60 | ' | |
f98d863d | 61 | |
ed838e66 JK |
62 | test_expect_success 'replace with non-match (actually matching)' ' |
63 | git config core.penguin "very blue" !kingpin | |
64 | ' | |
f98d863d JS |
65 | |
66 | cat > expect << EOF | |
f98d863d JS |
67 | [core] |
68 | penguin = very blue | |
69 | Movie = BadPhysics | |
70 | UPPERCASE = true | |
71 | penguin = kingpin | |
72 | [Cores] | |
73 | WhatEver = Second | |
74 | EOF | |
75 | ||
5a953fc5 | 76 | test_expect_success 'non-match result' 'test_cmp expect .git/config' |
f98d863d | 77 | |
88d42af8 | 78 | test_expect_success 'find mixed-case key by canonical name' ' |
a5db0b77 | 79 | test_cmp_config Second cores.whatever |
88d42af8 JK |
80 | ' |
81 | ||
82 | test_expect_success 'find mixed-case key by non-canonical name' ' | |
a5db0b77 | 83 | test_cmp_config Second CoReS.WhAtEvEr |
88d42af8 JK |
84 | ' |
85 | ||
86 | test_expect_success 'subsections are not canonicalized by git-config' ' | |
87 | cat >>.git/config <<-\EOF && | |
88 | [section.SubSection] | |
89 | key = one | |
90 | [section "SubSection"] | |
91 | key = two | |
92 | EOF | |
a5db0b77 NTND |
93 | test_cmp_config one section.subsection.key && |
94 | test_cmp_config two section.SubSection.key | |
88d42af8 | 95 | ' |
f98d863d | 96 | |
7a31cc0f FL |
97 | cat > .git/config <<\EOF |
98 | [alpha] | |
99 | bar = foo | |
100 | [beta] | |
101 | baz = multiple \ | |
102 | lines | |
85bf5d61 | 103 | foo = bar |
7a31cc0f FL |
104 | EOF |
105 | ||
ed838e66 JK |
106 | test_expect_success 'unset with cont. lines' ' |
107 | git config --unset beta.baz | |
108 | ' | |
7a31cc0f FL |
109 | |
110 | cat > expect <<\EOF | |
111 | [alpha] | |
112 | bar = foo | |
113 | [beta] | |
85bf5d61 | 114 | foo = bar |
7a31cc0f FL |
115 | EOF |
116 | ||
5a953fc5 | 117 | test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config' |
7a31cc0f | 118 | |
942c1f53 JS |
119 | cat > .git/config << EOF |
120 | [beta] ; silly comment # another comment | |
121 | noIndent= sillyValue ; 'nother silly comment | |
122 | ||
123 | # empty line | |
124 | ; comment | |
125 | haha ="beta" # last silly comment | |
4ddba79d JS |
126 | haha = hello |
127 | haha = bello | |
942c1f53 JS |
128 | [nextSection] noNewline = ouch |
129 | EOF | |
130 | ||
4ddba79d JS |
131 | cp .git/config .git/config2 |
132 | ||
ed838e66 JK |
133 | test_expect_success 'multiple unset' ' |
134 | git config --unset-all beta.haha | |
135 | ' | |
4ddba79d JS |
136 | |
137 | cat > expect << EOF | |
138 | [beta] ; silly comment # another comment | |
139 | noIndent= sillyValue ; 'nother silly comment | |
140 | ||
141 | # empty line | |
142 | ; comment | |
143 | [nextSection] noNewline = ouch | |
144 | EOF | |
145 | ||
ed838e66 JK |
146 | test_expect_success 'multiple unset is correct' ' |
147 | test_cmp expect .git/config | |
148 | ' | |
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 | 158 | |
ed838e66 JK |
159 | test_expect_success '--replace-all' ' |
160 | git config --replace-all beta.haha gamma | |
161 | ' | |
4ddba79d JS |
162 | |
163 | cat > expect << EOF | |
164 | [beta] ; silly comment # another comment | |
165 | noIndent= sillyValue ; 'nother silly comment | |
166 | ||
167 | # empty line | |
168 | ; comment | |
169 | haha = gamma | |
170 | [nextSection] noNewline = ouch | |
171 | EOF | |
172 | ||
ed838e66 JK |
173 | test_expect_success 'all replaced' ' |
174 | test_cmp expect .git/config | |
175 | ' | |
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 | haha = alpha | |
184 | [nextSection] noNewline = ouch | |
185 | EOF | |
5a953fc5 JK |
186 | test_expect_success 'really mean test' ' |
187 | git config beta.haha alpha && | |
188 | test_cmp expect .git/config | |
189 | ' | |
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 | haha = alpha | |
198 | [nextSection] | |
199 | nonewline = wow | |
200 | EOF | |
5a953fc5 JK |
201 | test_expect_success 'really really mean test' ' |
202 | git config nextsection.nonewline wow && | |
203 | test_cmp expect .git/config | |
204 | ' | |
942c1f53 | 205 | |
ed838e66 | 206 | test_expect_success 'get value' ' |
a5db0b77 | 207 | test_cmp_config alpha beta.haha |
ed838e66 | 208 | ' |
942c1f53 JS |
209 | |
210 | cat > expect << EOF | |
211 | [beta] ; silly comment # another comment | |
212 | noIndent= sillyValue ; 'nother silly comment | |
213 | ||
214 | # empty line | |
215 | ; comment | |
216 | [nextSection] | |
217 | nonewline = wow | |
218 | EOF | |
5a953fc5 JK |
219 | test_expect_success 'unset' ' |
220 | git config --unset beta.haha && | |
221 | test_cmp expect .git/config | |
222 | ' | |
942c1f53 JS |
223 | |
224 | cat > expect << EOF | |
225 | [beta] ; silly comment # another comment | |
226 | noIndent= sillyValue ; 'nother silly comment | |
227 | ||
228 | # empty line | |
229 | ; comment | |
230 | [nextSection] | |
231 | nonewline = wow | |
232 | NoNewLine = wow2 for me | |
233 | EOF | |
5a953fc5 JK |
234 | test_expect_success 'multivar' ' |
235 | git config nextsection.NoNewLine "wow2 for me" "for me$" && | |
236 | test_cmp expect .git/config | |
237 | ' | |
942c1f53 | 238 | |
ed838e66 JK |
239 | test_expect_success 'non-match' ' |
240 | git config --get nextsection.nonewline !for | |
241 | ' | |
f98d863d | 242 | |
ed838e66 | 243 | test_expect_success 'non-match value' ' |
a5db0b77 | 244 | test_cmp_config wow --get nextsection.nonewline !for |
ed838e66 | 245 | ' |
f98d863d | 246 | |
00b347d3 | 247 | test_expect_success 'multi-valued get returns final one' ' |
a5db0b77 | 248 | test_cmp_config "wow2 for me" --get nextsection.nonewline |
41ac414e | 249 | ' |
4ddba79d | 250 | |
cb20b691 JK |
251 | test_expect_success 'multi-valued get-all returns all' ' |
252 | cat >expect <<-\EOF && | |
253 | wow | |
254 | wow2 for me | |
255 | EOF | |
256 | git config --get-all nextsection.nonewline >actual && | |
257 | test_cmp expect actual | |
ed838e66 | 258 | ' |
4ddba79d | 259 | |
942c1f53 JS |
260 | cat > expect << EOF |
261 | [beta] ; silly comment # another comment | |
262 | noIndent= sillyValue ; 'nother silly comment | |
263 | ||
264 | # empty line | |
265 | ; comment | |
266 | [nextSection] | |
267 | nonewline = wow3 | |
268 | NoNewLine = wow2 for me | |
269 | EOF | |
5a953fc5 JK |
270 | test_expect_success 'multivar replace' ' |
271 | git config nextsection.nonewline "wow3" "wow$" && | |
272 | test_cmp expect .git/config | |
273 | ' | |
942c1f53 | 274 | |
41ac414e | 275 | test_expect_success 'ambiguous unset' ' |
d492b31c | 276 | test_must_fail git config --unset nextsection.nonewline |
41ac414e | 277 | ' |
942c1f53 | 278 | |
41ac414e | 279 | test_expect_success 'invalid unset' ' |
d492b31c | 280 | test_must_fail git config --unset somesection.nonewline |
41ac414e | 281 | ' |
942c1f53 | 282 | |
942c1f53 JS |
283 | cat > expect << EOF |
284 | [beta] ; silly comment # another comment | |
285 | noIndent= sillyValue ; 'nother silly comment | |
286 | ||
287 | # empty line | |
288 | ; comment | |
289 | [nextSection] | |
290 | NoNewLine = wow2 for me | |
291 | EOF | |
292 | ||
5a953fc5 JK |
293 | test_expect_success 'multivar unset' ' |
294 | git config --unset nextsection.nonewline "wow3$" && | |
295 | test_cmp expect .git/config | |
296 | ' | |
942c1f53 | 297 | |
d492b31c | 298 | test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla' |
942c1f53 | 299 | |
5be60078 | 300 | test_expect_success 'correct key' 'git config 123456.a123 987' |
942c1f53 | 301 | |
ed838e66 JK |
302 | test_expect_success 'hierarchical section' ' |
303 | git config Version.1.2.3eX.Alpha beta | |
304 | ' | |
b17e659d JS |
305 | |
306 | cat > expect << EOF | |
307 | [beta] ; silly comment # another comment | |
308 | noIndent= sillyValue ; 'nother silly comment | |
309 | ||
310 | # empty line | |
311 | ; comment | |
312 | [nextSection] | |
313 | NoNewLine = wow2 for me | |
314 | [123456] | |
315 | a123 = 987 | |
d14f7764 LT |
316 | [Version "1.2.3eX"] |
317 | Alpha = beta | |
b17e659d JS |
318 | EOF |
319 | ||
ed838e66 JK |
320 | test_expect_success 'hierarchical section value' ' |
321 | test_cmp expect .git/config | |
322 | ' | |
b17e659d | 323 | |
2fa9a0fb JS |
324 | cat > expect << EOF |
325 | beta.noindent=sillyValue | |
326 | nextsection.nonewline=wow2 for me | |
327 | 123456.a123=987 | |
d55aaefa | 328 | version.1.2.3eX.alpha=beta |
2fa9a0fb JS |
329 | EOF |
330 | ||
ed838e66 JK |
331 | test_expect_success 'working --list' ' |
332 | git config --list > output && | |
333 | test_cmp expect output | |
334 | ' | |
1f2baa78 JK |
335 | test_expect_success '--list without repo produces empty output' ' |
336 | git --git-dir=nonexistent config --list >output && | |
1c5e94f4 | 337 | test_must_be_empty output |
1f2baa78 JK |
338 | ' |
339 | ||
578625fa SG |
340 | cat > expect << EOF |
341 | beta.noindent | |
342 | nextsection.nonewline | |
343 | 123456.a123 | |
344 | version.1.2.3eX.alpha | |
345 | EOF | |
346 | ||
347 | test_expect_success '--name-only --list' ' | |
348 | git config --name-only --list >output && | |
349 | test_cmp expect output | |
350 | ' | |
351 | ||
2fa9a0fb JS |
352 | cat > expect << EOF |
353 | beta.noindent sillyValue | |
354 | nextsection.nonewline wow2 for me | |
355 | EOF | |
356 | ||
ed838e66 JK |
357 | test_expect_success '--get-regexp' ' |
358 | git config --get-regexp in >output && | |
359 | test_cmp expect output | |
360 | ' | |
2fa9a0fb | 361 | |
578625fa SG |
362 | cat > expect << EOF |
363 | beta.noindent | |
364 | nextsection.nonewline | |
365 | EOF | |
366 | ||
367 | test_expect_success '--name-only --get-regexp' ' | |
368 | git config --name-only --get-regexp in >output && | |
369 | test_cmp expect output | |
370 | ' | |
371 | ||
89c4afe0 BG |
372 | cat > expect << EOF |
373 | wow2 for me | |
374 | wow4 for you | |
375 | EOF | |
376 | ||
5a953fc5 JK |
377 | test_expect_success '--add' ' |
378 | git config --add nextsection.nonewline "wow4 for you" && | |
379 | git config --get-all nextsection.nonewline > output && | |
380 | test_cmp expect output | |
381 | ' | |
89c4afe0 | 382 | |
f067a137 JF |
383 | cat > .git/config << EOF |
384 | [novalue] | |
385 | variable | |
09bc098c CC |
386 | [emptyvalue] |
387 | variable = | |
f067a137 JF |
388 | EOF |
389 | ||
ed838e66 JK |
390 | test_expect_success 'get variable with no value' ' |
391 | git config --get novalue.variable ^$ | |
392 | ' | |
f067a137 | 393 | |
ed838e66 JK |
394 | test_expect_success 'get variable with empty value' ' |
395 | git config --get emptyvalue.variable ^$ | |
396 | ' | |
09bc098c | 397 | |
b69ba460 FL |
398 | echo novalue.variable > expect |
399 | ||
ed838e66 JK |
400 | test_expect_success 'get-regexp variable with no value' ' |
401 | git config --get-regexp novalue > output && | |
402 | test_cmp expect output | |
403 | ' | |
b69ba460 | 404 | |
008e3cc5 MM |
405 | echo 'novalue.variable true' > expect |
406 | ||
ed838e66 JK |
407 | test_expect_success 'get-regexp --bool variable with no value' ' |
408 | git config --bool --get-regexp novalue > output && | |
409 | test_cmp expect output | |
410 | ' | |
008e3cc5 | 411 | |
09bc098c CC |
412 | echo 'emptyvalue.variable ' > expect |
413 | ||
ed838e66 JK |
414 | test_expect_success 'get-regexp variable with empty value' ' |
415 | git config --get-regexp emptyvalue > output && | |
416 | test_cmp expect output | |
417 | ' | |
09bc098c CC |
418 | |
419 | echo true > expect | |
420 | ||
ed838e66 JK |
421 | test_expect_success 'get bool variable with no value' ' |
422 | git config --bool novalue.variable > output && | |
423 | test_cmp expect output | |
424 | ' | |
09bc098c CC |
425 | |
426 | echo false > expect | |
427 | ||
ed838e66 JK |
428 | test_expect_success 'get bool variable with empty value' ' |
429 | git config --bool emptyvalue.variable > output && | |
430 | test_cmp expect output | |
431 | ' | |
09bc098c | 432 | |
003f69b2 JK |
433 | test_expect_success 'no arguments, but no crash' ' |
434 | test_must_fail git config >output 2>&1 && | |
9a001381 | 435 | test_i18ngrep usage output |
003f69b2 | 436 | ' |
2fa9a0fb | 437 | |
bd886fd3 SE |
438 | cat > .git/config << EOF |
439 | [a.b] | |
440 | c = d | |
441 | EOF | |
442 | ||
bd886fd3 SE |
443 | cat > expect << EOF |
444 | [a.b] | |
445 | c = d | |
446 | [a] | |
447 | x = y | |
448 | EOF | |
449 | ||
5a953fc5 JK |
450 | test_expect_success 'new section is partial match of another' ' |
451 | git config a.x y && | |
452 | test_cmp expect .git/config | |
453 | ' | |
bd886fd3 SE |
454 | |
455 | cat > expect << EOF | |
456 | [a.b] | |
457 | c = d | |
458 | [a] | |
459 | x = y | |
460 | b = c | |
461 | [b] | |
462 | x = y | |
463 | EOF | |
464 | ||
5a953fc5 JK |
465 | test_expect_success 'new variable inserts into proper section' ' |
466 | git config b.x y && | |
467 | git config a.b c && | |
468 | test_cmp expect .git/config | |
469 | ' | |
bd886fd3 | 470 | |
f7e87141 | 471 | test_expect_success 'alternative --file (non-existing file should fail)' ' |
ed838e66 JK |
472 | test_must_fail git config --file non-existing-config -l |
473 | ' | |
773a69fb | 474 | |
9c3796fc JS |
475 | cat > other-config << EOF |
476 | [ein] | |
477 | bahn = strasse | |
478 | EOF | |
479 | ||
480 | cat > expect << EOF | |
481 | ein.bahn=strasse | |
482 | EOF | |
483 | ||
5a953fc5 | 484 | test_expect_success 'alternative GIT_CONFIG' ' |
3caec73b | 485 | GIT_CONFIG=other-config git config --list >output && |
5a953fc5 JK |
486 | test_cmp expect output |
487 | ' | |
9c3796fc | 488 | |
ed838e66 | 489 | test_expect_success 'alternative GIT_CONFIG (--file)' ' |
3caec73b | 490 | git config --file other-config --list >output && |
ed838e66 JK |
491 | test_cmp expect output |
492 | ' | |
773a69fb | 493 | |
3caec73b KS |
494 | test_expect_success 'alternative GIT_CONFIG (--file=-)' ' |
495 | git config --file - --list <other-config >output && | |
496 | test_cmp expect output | |
497 | ' | |
498 | ||
499 | test_expect_success 'setting a value in stdin is an error' ' | |
500 | test_must_fail git config --file - some.value foo | |
501 | ' | |
502 | ||
503 | test_expect_success 'editing stdin is an error' ' | |
504 | test_must_fail git config --file - --edit | |
505 | ' | |
506 | ||
65807ee6 JH |
507 | test_expect_success 'refer config from subdirectory' ' |
508 | mkdir x && | |
a5db0b77 | 509 | test_cmp_config -C x strasse --get --file ../other-config ein.bahn |
65807ee6 JH |
510 | ' |
511 | ||
f7e87141 | 512 | test_expect_success 'refer config from subdirectory via --file' ' |
a5db0b77 | 513 | test_cmp_config -C x strasse --file=../other-config --get ein.bahn |
270a3443 JK |
514 | ' |
515 | ||
9c3796fc JS |
516 | cat > expect << EOF |
517 | [ein] | |
518 | bahn = strasse | |
519 | [anwohner] | |
520 | park = ausweis | |
521 | EOF | |
522 | ||
f7e87141 JK |
523 | test_expect_success '--set in alternative file' ' |
524 | git config --file=other-config anwohner.park ausweis && | |
5a953fc5 JK |
525 | test_cmp expect other-config |
526 | ' | |
9c3796fc | 527 | |
0667fcfb JS |
528 | cat > .git/config << EOF |
529 | # Hallo | |
530 | #Bello | |
531 | [branch "eins"] | |
532 | x = 1 | |
533 | [branch.eins] | |
534 | y = 1 | |
535 | [branch "1 234 blabl/a"] | |
536 | weird | |
537 | EOF | |
538 | ||
ed838e66 JK |
539 | test_expect_success 'rename section' ' |
540 | git config --rename-section branch.eins branch.zwei | |
541 | ' | |
0667fcfb JS |
542 | |
543 | cat > expect << EOF | |
544 | # Hallo | |
545 | #Bello | |
546 | [branch "zwei"] | |
547 | x = 1 | |
548 | [branch "zwei"] | |
549 | y = 1 | |
550 | [branch "1 234 blabl/a"] | |
551 | weird | |
552 | EOF | |
553 | ||
ed838e66 JK |
554 | test_expect_success 'rename succeeded' ' |
555 | test_cmp expect .git/config | |
556 | ' | |
0667fcfb | 557 | |
ed838e66 | 558 | test_expect_success 'rename non-existing section' ' |
d492b31c SB |
559 | test_must_fail git config --rename-section \ |
560 | branch."world domination" branch.drei | |
41ac414e | 561 | ' |
0667fcfb | 562 | |
ed838e66 JK |
563 | test_expect_success 'rename succeeded' ' |
564 | test_cmp expect .git/config | |
565 | ' | |
0667fcfb | 566 | |
ed838e66 JK |
567 | test_expect_success 'rename another section' ' |
568 | git config --rename-section branch."1 234 blabl/a" branch.drei | |
569 | ' | |
0667fcfb JS |
570 | |
571 | cat > expect << EOF | |
572 | # Hallo | |
573 | #Bello | |
574 | [branch "zwei"] | |
575 | x = 1 | |
576 | [branch "zwei"] | |
577 | y = 1 | |
578 | [branch "drei"] | |
579 | weird | |
580 | EOF | |
581 | ||
ed838e66 JK |
582 | test_expect_success 'rename succeeded' ' |
583 | test_cmp expect .git/config | |
584 | ' | |
9a5abfc7 AV |
585 | |
586 | cat >> .git/config << EOF | |
587 | [branch "vier"] z = 1 | |
588 | EOF | |
589 | ||
ed838e66 JK |
590 | test_expect_success 'rename a section with a var on the same line' ' |
591 | git config --rename-section branch.vier branch.zwei | |
592 | ' | |
9a5abfc7 AV |
593 | |
594 | cat > expect << EOF | |
595 | # Hallo | |
596 | #Bello | |
597 | [branch "zwei"] | |
598 | x = 1 | |
599 | [branch "zwei"] | |
600 | y = 1 | |
601 | [branch "drei"] | |
602 | weird | |
603 | [branch "zwei"] | |
604 | z = 1 | |
605 | EOF | |
606 | ||
ed838e66 JK |
607 | test_expect_success 'rename succeeded' ' |
608 | test_cmp expect .git/config | |
609 | ' | |
0667fcfb | 610 | |
94a35b1a JK |
611 | test_expect_success 'renaming empty section name is rejected' ' |
612 | test_must_fail git config --rename-section branch.zwei "" | |
613 | ' | |
614 | ||
615 | test_expect_success 'renaming to bogus section is rejected' ' | |
616 | test_must_fail git config --rename-section branch.zwei "bogus name" | |
617 | ' | |
618 | ||
118f8b24 PB |
619 | cat >> .git/config << EOF |
620 | [branch "zwei"] a = 1 [branch "vier"] | |
621 | EOF | |
622 | ||
ed838e66 JK |
623 | test_expect_success 'remove section' ' |
624 | git config --remove-section branch.zwei | |
625 | ' | |
118f8b24 PB |
626 | |
627 | cat > expect << EOF | |
628 | # Hallo | |
629 | #Bello | |
630 | [branch "drei"] | |
631 | weird | |
632 | EOF | |
633 | ||
ed838e66 JK |
634 | test_expect_success 'section was removed properly' ' |
635 | test_cmp expect .git/config | |
636 | ' | |
118f8b24 | 637 | |
b18a2be3 SP |
638 | cat > expect << EOF |
639 | [gitcvs] | |
640 | enabled = true | |
641 | dbname = %Ggitcvs2.%a.%m.sqlite | |
642 | [gitcvs "ext"] | |
643 | dbname = %Ggitcvs1.%a.%m.sqlite | |
644 | EOF | |
645 | ||
646 | test_expect_success 'section ending' ' | |
795290e5 | 647 | rm -f .git/config && |
5be60078 JH |
648 | git config gitcvs.enabled true && |
649 | git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && | |
650 | git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && | |
5a953fc5 | 651 | test_cmp expect .git/config |
b18a2be3 SP |
652 | |
653 | ' | |
654 | ||
d77a64d3 | 655 | test_expect_success numbers ' |
5be60078 JH |
656 | git config kilo.gram 1k && |
657 | git config mega.ton 1m && | |
ed838e66 JK |
658 | echo 1024 >expect && |
659 | echo 1048576 >>expect && | |
660 | git config --int --get kilo.gram >actual && | |
661 | git config --int --get mega.ton >>actual && | |
662 | test_cmp expect actual | |
d77a64d3 SP |
663 | ' |
664 | ||
00160242 JK |
665 | test_expect_success '--int is at least 64 bits' ' |
666 | git config giga.watts 121g && | |
a5db0b77 NTND |
667 | echo >expect && |
668 | test_cmp_config 129922760704 --int --get giga.watts | |
00160242 JK |
669 | ' |
670 | ||
c8deb5a1 | 671 | test_expect_success 'invalid unit' ' |
c8deb5a1 | 672 | git config aninvalid.unit "1auto" && |
a5db0b77 | 673 | test_cmp_config 1auto aninvalid.unit && |
ed838e66 | 674 | test_must_fail git config --int --get aninvalid.unit 2>actual && |
2ec20212 | 675 | test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual |
c8deb5a1 SP |
676 | ' |
677 | ||
e2e14251 JS |
678 | test_expect_success 'line number is reported correctly' ' |
679 | printf "[bool]\n\tvar\n" >invalid && | |
680 | test_must_fail git config -f invalid --path bool.var 2>actual && | |
681 | test_i18ngrep "line 2" actual | |
682 | ' | |
683 | ||
473166b9 | 684 | test_expect_success 'invalid stdin config' ' |
473166b9 | 685 | echo "[broken" | test_must_fail git config --list --file - >output 2>&1 && |
2ec20212 | 686 | test_i18ngrep "bad config line 1 in standard input" output |
473166b9 LS |
687 | ' |
688 | ||
cab333cb FL |
689 | cat > expect << EOF |
690 | true | |
691 | false | |
692 | true | |
693 | false | |
694 | true | |
695 | false | |
696 | true | |
697 | false | |
698 | EOF | |
699 | ||
700 | test_expect_success bool ' | |
701 | ||
5be60078 JH |
702 | git config bool.true1 01 && |
703 | git config bool.true2 -1 && | |
704 | git config bool.true3 YeS && | |
705 | git config bool.true4 true && | |
706 | git config bool.false1 000 && | |
707 | git config bool.false2 "" && | |
708 | git config bool.false3 nO && | |
709 | git config bool.false4 FALSE && | |
cab333cb FL |
710 | rm -f result && |
711 | for i in 1 2 3 4 | |
712 | do | |
5be60078 JH |
713 | git config --bool --get bool.true$i >>result |
714 | git config --bool --get bool.false$i >>result | |
e3e042b1 | 715 | done && |
ed838e66 | 716 | test_cmp expect result' |
cab333cb | 717 | |
41ac414e | 718 | test_expect_success 'invalid bool (--get)' ' |
cab333cb | 719 | |
5be60078 | 720 | git config bool.nobool foobar && |
d492b31c | 721 | test_must_fail git config --bool --get bool.nobool' |
cab333cb | 722 | |
41ac414e | 723 | test_expect_success 'invalid bool (set)' ' |
db1696b8 | 724 | |
d492b31c | 725 | test_must_fail git config --bool bool.nobool foobar' |
db1696b8 | 726 | |
db1696b8 FL |
727 | cat > expect <<\EOF |
728 | [bool] | |
729 | true1 = true | |
730 | true2 = true | |
731 | true3 = true | |
732 | true4 = true | |
733 | false1 = false | |
734 | false2 = false | |
735 | false3 = false | |
736 | false4 = false | |
737 | EOF | |
738 | ||
739 | test_expect_success 'set --bool' ' | |
740 | ||
795290e5 | 741 | rm -f .git/config && |
5be60078 JH |
742 | git config --bool bool.true1 01 && |
743 | git config --bool bool.true2 -1 && | |
744 | git config --bool bool.true3 YeS && | |
745 | git config --bool bool.true4 true && | |
746 | git config --bool bool.false1 000 && | |
747 | git config --bool bool.false2 "" && | |
748 | git config --bool bool.false3 nO && | |
749 | git config --bool bool.false4 FALSE && | |
ed838e66 | 750 | test_cmp expect .git/config' |
db1696b8 | 751 | |
db1696b8 FL |
752 | cat > expect <<\EOF |
753 | [int] | |
754 | val1 = 1 | |
755 | val2 = -1 | |
756 | val3 = 5242880 | |
757 | EOF | |
758 | ||
759 | test_expect_success 'set --int' ' | |
760 | ||
795290e5 | 761 | rm -f .git/config && |
5be60078 JH |
762 | git config --int int.val1 01 && |
763 | git config --int int.val2 -1 && | |
764 | git config --int int.val3 5m && | |
ed838e66 JK |
765 | test_cmp expect .git/config |
766 | ' | |
db1696b8 | 767 | |
ed838e66 JK |
768 | test_expect_success 'get --bool-or-int' ' |
769 | cat >.git/config <<-\EOF && | |
770 | [bool] | |
771 | true1 | |
c35b0b58 | 772 | true2 = true |
ed838e66 JK |
773 | false = false |
774 | [int] | |
c35b0b58 JH |
775 | int1 = 0 |
776 | int2 = 1 | |
777 | int3 = -1 | |
ed838e66 JK |
778 | EOF |
779 | cat >expect <<-\EOF && | |
780 | true | |
781 | true | |
782 | false | |
783 | 0 | |
784 | 1 | |
785 | -1 | |
786 | EOF | |
787 | { | |
788 | git config --bool-or-int bool.true1 && | |
789 | git config --bool-or-int bool.true2 && | |
790 | git config --bool-or-int bool.false && | |
791 | git config --bool-or-int int.int1 && | |
792 | git config --bool-or-int int.int2 && | |
793 | git config --bool-or-int int.int3 | |
794 | } >actual && | |
795 | test_cmp expect actual | |
c35b0b58 JH |
796 | ' |
797 | ||
c35b0b58 JH |
798 | cat >expect <<\EOF |
799 | [bool] | |
800 | true1 = true | |
801 | false1 = false | |
802 | true2 = true | |
803 | false2 = false | |
804 | [int] | |
805 | int1 = 0 | |
806 | int2 = 1 | |
807 | int3 = -1 | |
808 | EOF | |
809 | ||
810 | test_expect_success 'set --bool-or-int' ' | |
795290e5 | 811 | rm -f .git/config && |
c35b0b58 JH |
812 | git config --bool-or-int bool.true1 true && |
813 | git config --bool-or-int bool.false1 false && | |
814 | git config --bool-or-int bool.true2 yes && | |
815 | git config --bool-or-int bool.false2 no && | |
816 | git config --bool-or-int int.int1 0 && | |
817 | git config --bool-or-int int.int2 1 && | |
818 | git config --bool-or-int int.int3 -1 && | |
819 | test_cmp expect .git/config | |
820 | ' | |
821 | ||
1349484e MM |
822 | cat >expect <<\EOF |
823 | [path] | |
824 | home = ~/ | |
825 | normal = /dev/null | |
826 | trailingtilde = foo~ | |
827 | EOF | |
828 | ||
f57a8715 | 829 | test_expect_success !MINGW 'set --path' ' |
795290e5 | 830 | rm -f .git/config && |
1349484e MM |
831 | git config --path path.home "~/" && |
832 | git config --path path.normal "/dev/null" && | |
833 | git config --path path.trailingtilde "foo~" && | |
834 | test_cmp expect .git/config' | |
835 | ||
f57a8715 | 836 | if test_have_prereq !MINGW && test "${HOME+set}" |
79bf1490 JN |
837 | then |
838 | test_set_prereq HOMEVAR | |
839 | fi | |
840 | ||
1349484e MM |
841 | cat >expect <<EOF |
842 | $HOME/ | |
843 | /dev/null | |
844 | foo~ | |
845 | EOF | |
846 | ||
79bf1490 | 847 | test_expect_success HOMEVAR 'get --path' ' |
1349484e MM |
848 | git config --get --path path.home > result && |
849 | git config --get --path path.normal >> result && | |
850 | git config --get --path path.trailingtilde >> result && | |
851 | test_cmp expect result | |
852 | ' | |
853 | ||
79bf1490 JN |
854 | cat >expect <<\EOF |
855 | /dev/null | |
856 | foo~ | |
857 | EOF | |
858 | ||
f57a8715 | 859 | test_expect_success !MINGW 'get --path copes with unset $HOME' ' |
79bf1490 | 860 | ( |
ed6c994a | 861 | sane_unset HOME && |
79bf1490 JN |
862 | test_must_fail git config --get --path path.home \ |
863 | >result 2>msg && | |
864 | git config --get --path path.normal >>result && | |
865 | git config --get --path path.trailingtilde >>result | |
866 | ) && | |
1edbaac3 | 867 | test_i18ngrep "[Ff]ailed to expand.*~/" msg && |
79bf1490 JN |
868 | test_cmp expect result |
869 | ' | |
870 | ||
962c38ee CMN |
871 | test_expect_success 'get --path barfs on boolean variable' ' |
872 | echo "[path]bool" >.git/config && | |
873 | test_must_fail git config --get --path path.bool | |
874 | ' | |
875 | ||
5f967424 HM |
876 | test_expect_success 'get --expiry-date' ' |
877 | rel="3.weeks.5.days.00:00" && | |
878 | rel_out="$rel ->" && | |
879 | cat >.git/config <<-\EOF && | |
880 | [date] | |
881 | valid1 = "3.weeks.5.days 00:00" | |
882 | valid2 = "Fri Jun 4 15:46:55 2010" | |
883 | valid3 = "2017/11/11 11:11:11PM" | |
884 | valid4 = "2017/11/10 09:08:07 PM" | |
885 | valid5 = "never" | |
886 | invalid1 = "abc" | |
887 | EOF | |
888 | cat >expect <<-EOF && | |
a801a7cf | 889 | $(test-tool date timestamp $rel) |
5f967424 HM |
890 | 1275666415 |
891 | 1510441871 | |
892 | 1510348087 | |
893 | 0 | |
894 | EOF | |
d38722eb | 895 | : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" && |
5f967424 HM |
896 | { |
897 | echo "$rel_out $(git config --expiry-date date.valid1)" | |
898 | git config --expiry-date date.valid2 && | |
899 | git config --expiry-date date.valid3 && | |
900 | git config --expiry-date date.valid4 && | |
901 | git config --expiry-date date.valid5 | |
902 | } >actual && | |
903 | test_cmp expect actual && | |
904 | test_must_fail git config --expiry-date date.invalid1 | |
905 | ' | |
906 | ||
63e2a0f8 TB |
907 | test_expect_success 'get --type=color' ' |
908 | rm .git/config && | |
909 | git config foo.color "red" && | |
910 | git config --get --type=color foo.color >actual.raw && | |
911 | test_decode_color <actual.raw >actual && | |
912 | echo "<RED>" >expect && | |
913 | test_cmp expect actual | |
914 | ' | |
915 | ||
916 | cat >expect << EOF | |
917 | [foo] | |
918 | color = red | |
919 | EOF | |
920 | ||
921 | test_expect_success 'set --type=color' ' | |
922 | rm .git/config && | |
923 | git config --type=color foo.color "red" && | |
924 | test_cmp expect .git/config | |
925 | ' | |
926 | ||
927 | test_expect_success 'get --type=color barfs on non-color' ' | |
928 | echo "[foo]bar=not-a-color" >.git/config && | |
929 | test_must_fail git config --get --type=color foo.bar | |
930 | ' | |
931 | ||
932 | test_expect_success 'set --type=color barfs on non-color' ' | |
933 | test_must_fail git config --type=color foo.color "not-a-color" 2>error && | |
934 | test_i18ngrep "cannot parse color" error | |
935 | ' | |
936 | ||
cdd4fb15 BG |
937 | cat > expect << EOF |
938 | [quote] | |
939 | leading = " test" | |
940 | ending = "test " | |
941 | semicolon = "test;test" | |
942 | hash = "test#test" | |
943 | EOF | |
5a953fc5 | 944 | test_expect_success 'quoting' ' |
795290e5 | 945 | rm -f .git/config && |
5a953fc5 JK |
946 | git config quote.leading " test" && |
947 | git config quote.ending "test " && | |
948 | git config quote.semicolon "test;test" && | |
949 | git config quote.hash "test#test" && | |
950 | test_cmp expect .git/config | |
951 | ' | |
cdd4fb15 | 952 | |
41ac414e | 953 | test_expect_success 'key with newline' ' |
d492b31c | 954 | test_must_fail git config "key.with |
41ac414e | 955 | newline" 123' |
6f71686e | 956 | |
e0d10e1c | 957 | test_expect_success 'value with newline' 'git config key.sub value.with\\\ |
6f71686e JS |
958 | newline' |
959 | ||
83cd10a0 JN |
960 | cat > .git/config <<\EOF |
961 | [section] | |
962 | ; comment \ | |
963 | continued = cont\ | |
964 | inued | |
965 | noncont = not continued ; \ | |
966 | quotecont = "cont;\ | |
967 | inued" | |
968 | EOF | |
969 | ||
970 | cat > expect <<\EOF | |
971 | section.continued=continued | |
972 | section.noncont=not continued | |
973 | section.quotecont=cont;inued | |
974 | EOF | |
975 | ||
5a953fc5 JK |
976 | test_expect_success 'value continued on next line' ' |
977 | git config --list > result && | |
dcbaa0b3 | 978 | test_cmp expect result |
5a953fc5 | 979 | ' |
83cd10a0 | 980 | |
2275d502 FL |
981 | cat > .git/config <<\EOF |
982 | [section "sub=section"] | |
983 | val1 = foo=bar | |
984 | val2 = foo\nbar | |
985 | val3 = \n\n | |
986 | val4 = | |
987 | val5 | |
988 | EOF | |
989 | ||
990 | cat > expect <<\EOF | |
2b9a5020 AR |
991 | section.sub=section.val1 |
992 | foo=barQsection.sub=section.val2 | |
993 | foo | |
994 | barQsection.sub=section.val3 | |
2275d502 FL |
995 | |
996 | ||
2b9a5020 AR |
997 | Qsection.sub=section.val4 |
998 | Qsection.sub=section.val5Q | |
2275d502 | 999 | EOF |
5a953fc5 | 1000 | test_expect_success '--null --list' ' |
a0578e03 LS |
1001 | git config --null --list >result.raw && |
1002 | nul_to_q <result.raw >result && | |
5a953fc5 JK |
1003 | echo >>result && |
1004 | test_cmp expect result | |
1005 | ' | |
2275d502 | 1006 | |
5a953fc5 | 1007 | test_expect_success '--null --get-regexp' ' |
a0578e03 LS |
1008 | git config --null --get-regexp "val[0-9]" >result.raw && |
1009 | nul_to_q <result.raw >result && | |
5a953fc5 JK |
1010 | echo >>result && |
1011 | test_cmp expect result | |
1012 | ' | |
2275d502 | 1013 | |
ebdaae37 BS |
1014 | test_expect_success 'inner whitespace kept verbatim' ' |
1015 | git config section.val "foo bar" && | |
a5db0b77 | 1016 | test_cmp_config "foo bar" section.val |
ebdaae37 BS |
1017 | ' |
1018 | ||
704a3143 | 1019 | test_expect_success SYMLINKS 'symlinked configuration' ' |
65a5a21d | 1020 | ln -s notyet myconfig && |
f7e87141 | 1021 | git config --file=myconfig test.frotz nitfol && |
65a5a21d JH |
1022 | test -h myconfig && |
1023 | test -f notyet && | |
f7e87141 JK |
1024 | test "z$(git config --file=notyet test.frotz)" = znitfol && |
1025 | git config --file=myconfig test.xyzzy rezrov && | |
65a5a21d JH |
1026 | test -h myconfig && |
1027 | test -f notyet && | |
ed838e66 JK |
1028 | cat >expect <<-\EOF && |
1029 | nitfol | |
1030 | rezrov | |
1031 | EOF | |
1032 | { | |
f7e87141 JK |
1033 | git config --file=notyet test.frotz && |
1034 | git config --file=notyet test.xyzzy | |
ed838e66 JK |
1035 | } >actual && |
1036 | test_cmp expect actual | |
65a5a21d JH |
1037 | ' |
1038 | ||
1f2baa78 | 1039 | test_expect_success 'nonexistent configuration' ' |
551a3e60 JK |
1040 | test_must_fail git config --file=doesnotexist --list && |
1041 | test_must_fail git config --file=doesnotexist test.xyzzy | |
1f2baa78 JK |
1042 | ' |
1043 | ||
1044 | test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' | |
1045 | ln -s doesnotexist linktonada && | |
1046 | ln -s linktonada linktolinktonada && | |
551a3e60 JK |
1047 | test_must_fail git config --file=linktonada --list && |
1048 | test_must_fail git config --file=linktolinktonada --list | |
1f2baa78 JK |
1049 | ' |
1050 | ||
dc4179f9 DM |
1051 | test_expect_success 'check split_cmdline return' " |
1052 | git config alias.split-cmdline-fix 'echo \"' && | |
1053 | test_must_fail git split-cmdline-fix && | |
1054 | echo foo > foo && | |
1055 | git add foo && | |
1056 | git commit -m 'initial commit' && | |
1057 | git config branch.master.mergeoptions 'echo \"' && | |
1058 | test_must_fail git merge master | |
ed838e66 | 1059 | " |
dc4179f9 | 1060 | |
8b1fa778 | 1061 | test_expect_success 'git -c "key=value" support' ' |
ed838e66 JK |
1062 | cat >expect <<-\EOF && |
1063 | value | |
1064 | value | |
1065 | true | |
1066 | EOF | |
1067 | { | |
1068 | git -c core.name=value config core.name && | |
1069 | git -c foo.CamelCase=value config foo.camelcase && | |
1070 | git -c foo.flag config --bool foo.flag | |
1071 | } >actual && | |
1072 | test_cmp expect actual && | |
b09c53a3 LP |
1073 | test_must_fail git -c name=value config core.name |
1074 | ' | |
1075 | ||
a789ca70 JH |
1076 | # We just need a type-specifier here that cares about the |
1077 | # distinction internally between a NULL boolean and a real | |
1078 | # string (because most of git's internal parsers do care). | |
1079 | # Using "--path" works, but we do not otherwise care about | |
1080 | # its semantics. | |
1081 | test_expect_success 'git -c can represent empty string' ' | |
1082 | echo >expect && | |
1083 | git -c foo.empty= config --path foo.empty >actual && | |
1084 | test_cmp expect actual | |
1085 | ' | |
1086 | ||
b09c53a3 LP |
1087 | test_expect_success 'key sanity-checking' ' |
1088 | test_must_fail git config foo=bar && | |
1089 | test_must_fail git config foo=.bar && | |
1090 | test_must_fail git config foo.ba=r && | |
1091 | test_must_fail git config foo.1bar && | |
1092 | test_must_fail git config foo."ba | |
1093 | z".bar && | |
2169ddc0 LP |
1094 | test_must_fail git config . false && |
1095 | test_must_fail git config .foo false && | |
1096 | test_must_fail git config foo. false && | |
1097 | test_must_fail git config .foo. false && | |
b09c53a3 LP |
1098 | git config foo.bar true && |
1099 | git config foo."ba =z".bar false | |
8b1fa778 AR |
1100 | ' |
1101 | ||
73546c08 | 1102 | test_expect_success 'git -c works with aliases of builtins' ' |
06eb708f JK |
1103 | git config alias.checkconfig "-c foo.check=bar config foo.check" && |
1104 | echo bar >expect && | |
1105 | git checkconfig >actual && | |
1106 | test_cmp expect actual | |
1107 | ' | |
1108 | ||
643df7e2 | 1109 | test_expect_success 'aliases can be CamelCased' ' |
084b0440 JS |
1110 | test_config alias.CamelCased "rev-parse HEAD" && |
1111 | git CamelCased >out && | |
1112 | git rev-parse HEAD >expect && | |
1113 | test_cmp expect out | |
1114 | ' | |
1115 | ||
5bf6529a JK |
1116 | test_expect_success 'git -c does not split values on equals' ' |
1117 | echo "value with = in it" >expect && | |
1118 | git -c core.foo="value with = in it" config core.foo >actual && | |
1119 | test_cmp expect actual | |
1120 | ' | |
1121 | ||
1c2c9bee JK |
1122 | test_expect_success 'git -c dies on bogus config' ' |
1123 | test_must_fail git -c core.bare=foo rev-parse | |
1124 | ' | |
1125 | ||
1126 | test_expect_success 'git -c complains about empty key' ' | |
1127 | test_must_fail git -c "=foo" rev-parse | |
1128 | ' | |
1129 | ||
c5d6350b JK |
1130 | test_expect_success 'git -c complains about empty key and value' ' |
1131 | test_must_fail git -c "" rev-parse | |
1132 | ' | |
1133 | ||
d1f88498 JK |
1134 | test_expect_success 'multiple git -c appends config' ' |
1135 | test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" && | |
1136 | cat >expect <<-\EOF && | |
1137 | x.one 1 | |
1138 | x.two 2 | |
1139 | EOF | |
1140 | git -c x.one=1 x >actual && | |
1141 | test_cmp expect actual | |
1142 | ' | |
1143 | ||
1274a155 JH |
1144 | test_expect_success 'last one wins: two level vars' ' |
1145 | ||
1146 | # sec.var and sec.VAR are the same variable, as the first | |
1147 | # and the last level of a configuration variable name is | |
1148 | # case insensitive. | |
1149 | ||
1150 | echo VAL >expect && | |
1151 | ||
1152 | git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual && | |
1153 | test_cmp expect actual && | |
1154 | git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual && | |
1155 | test_cmp expect actual && | |
1156 | ||
1157 | git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual && | |
1158 | test_cmp expect actual && | |
1159 | git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual && | |
1160 | test_cmp expect actual | |
1161 | ' | |
1162 | ||
1163 | test_expect_success 'last one wins: three level vars' ' | |
1164 | ||
1165 | # v.a.r and v.A.r are not the same variable, as the middle | |
1166 | # level of a three-level configuration variable name is | |
1167 | # case sensitive. | |
1168 | ||
1169 | echo val >expect && | |
1170 | git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual && | |
1171 | test_cmp expect actual && | |
1172 | git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual && | |
1173 | test_cmp expect actual && | |
1174 | ||
1175 | # v.a.r and V.a.R are the same variable, as the first | |
1176 | # and the last level of a configuration variable name is | |
1177 | # case insensitive. | |
1178 | ||
1179 | echo VAL >expect && | |
1180 | git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual && | |
1181 | test_cmp expect actual && | |
1182 | git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual && | |
1183 | test_cmp expect actual && | |
1184 | git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual && | |
1185 | test_cmp expect actual && | |
1186 | git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual && | |
1187 | test_cmp expect actual | |
1188 | ' | |
1189 | ||
999d9026 SB |
1190 | test_expect_success 'old-fashioned settings are case insensitive' ' |
1191 | test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" && | |
1192 | ||
1193 | cat >testConfig_actual <<-EOF && | |
1194 | [V.A] | |
1195 | r = value1 | |
1196 | EOF | |
1197 | q_to_tab >testConfig_expect <<-EOF && | |
1198 | [V.A] | |
1199 | Qr = value2 | |
1200 | EOF | |
1201 | git config -f testConfig_actual "v.a.r" value2 && | |
1202 | test_cmp testConfig_expect testConfig_actual && | |
1203 | ||
1204 | cat >testConfig_actual <<-EOF && | |
1205 | [V.A] | |
1206 | r = value1 | |
1207 | EOF | |
1208 | q_to_tab >testConfig_expect <<-EOF && | |
1209 | [V.A] | |
1210 | QR = value2 | |
1211 | EOF | |
1212 | git config -f testConfig_actual "V.a.R" value2 && | |
1213 | test_cmp testConfig_expect testConfig_actual && | |
1214 | ||
1215 | cat >testConfig_actual <<-EOF && | |
1216 | [V.A] | |
1217 | r = value1 | |
1218 | EOF | |
1219 | q_to_tab >testConfig_expect <<-EOF && | |
1220 | [V.A] | |
1221 | r = value1 | |
1222 | Qr = value2 | |
1223 | EOF | |
1224 | git config -f testConfig_actual "V.A.r" value2 && | |
1225 | test_cmp testConfig_expect testConfig_actual && | |
1226 | ||
1227 | cat >testConfig_actual <<-EOF && | |
1228 | [V.A] | |
1229 | r = value1 | |
1230 | EOF | |
1231 | q_to_tab >testConfig_expect <<-EOF && | |
1232 | [V.A] | |
1233 | r = value1 | |
1234 | Qr = value2 | |
1235 | EOF | |
1236 | git config -f testConfig_actual "v.A.r" value2 && | |
1237 | test_cmp testConfig_expect testConfig_actual | |
1238 | ' | |
1239 | ||
1240 | test_expect_success 'setting different case sensitive subsections ' ' | |
1241 | test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" && | |
1242 | ||
1243 | cat >testConfig_actual <<-EOF && | |
1244 | [V "A"] | |
1245 | R = v1 | |
1246 | [K "E"] | |
1247 | Y = v1 | |
1248 | [a "b"] | |
1249 | c = v1 | |
1250 | [d "e"] | |
1251 | f = v1 | |
1252 | EOF | |
1253 | q_to_tab >testConfig_expect <<-EOF && | |
1254 | [V "A"] | |
1255 | Qr = v2 | |
1256 | [K "E"] | |
1257 | Qy = v2 | |
1258 | [a "b"] | |
1259 | Qc = v2 | |
1260 | [d "e"] | |
1261 | f = v1 | |
2d84f13d | 1262 | [d "E"] |
999d9026 SB |
1263 | Qf = v2 |
1264 | EOF | |
1265 | # exact match | |
1266 | git config -f testConfig_actual a.b.c v2 && | |
1267 | # match section and subsection, key is cased differently. | |
1268 | git config -f testConfig_actual K.E.y v2 && | |
1269 | # section and key are matched case insensitive, but subsection needs | |
1270 | # to match; When writing out new values only the key is adjusted | |
1271 | git config -f testConfig_actual v.A.r v2 && | |
1272 | # subsection is not matched: | |
1273 | git config -f testConfig_actual d.E.f v2 && | |
1274 | test_cmp testConfig_expect testConfig_actual | |
1275 | ' | |
1276 | ||
1274a155 JH |
1277 | for VAR in a .a a. a.0b a."b c". a."b c".0d |
1278 | do | |
1279 | test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" ' | |
1280 | test_must_fail git -c "$VAR=VAL" config -l | |
1281 | ' | |
1282 | done | |
1283 | ||
1284 | for VAR in a.b a."b c".d | |
1285 | do | |
1286 | test_expect_success "git -c $VAR=VAL works with valid '$VAR'" ' | |
1287 | echo VAL >expect && | |
1288 | git -c "$VAR=VAL" config --get "$VAR" >actual && | |
1289 | test_cmp expect actual | |
1290 | ' | |
1291 | done | |
1292 | ||
d1f88498 JK |
1293 | test_expect_success 'git -c is not confused by empty environment' ' |
1294 | GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list | |
1295 | ' | |
1296 | ||
ddbbf8eb JK |
1297 | sq="'" |
1298 | test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' ' | |
1299 | cat >expect <<-\EOF && | |
1300 | env.one one | |
1301 | env.two two | |
1302 | EOF | |
1303 | GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq} ${sq}env.two=two${sq}" \ | |
1304 | git config --get-regexp "env.*" >actual && | |
1305 | test_cmp expect actual && | |
1306 | ||
1307 | cat >expect <<-EOF && | |
1308 | env.one one${sq} | |
1309 | env.two two | |
1310 | EOF | |
1311 | GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq$sq$sq ${sq}env.two=two${sq}" \ | |
1312 | git config --get-regexp "env.*" >actual && | |
1313 | test_cmp expect actual && | |
1314 | ||
1315 | test_must_fail env \ | |
1316 | GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq ${sq}env.two=two${sq}" \ | |
1317 | git config --get-regexp "env.*" | |
1318 | ' | |
1319 | ||
270a3443 JK |
1320 | test_expect_success 'git config --edit works' ' |
1321 | git config -f tmp test.value no && | |
1322 | echo test.value=yes >expect && | |
1323 | GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit && | |
1324 | git config -f tmp --list >actual && | |
1325 | test_cmp expect actual | |
1326 | ' | |
1327 | ||
1328 | test_expect_success 'git config --edit respects core.editor' ' | |
1329 | git config -f tmp test.value no && | |
1330 | echo test.value=yes >expect && | |
1331 | test_config core.editor "echo [test]value=yes >" && | |
1332 | git config -f tmp --edit && | |
1333 | git config -f tmp --list >actual && | |
1334 | test_cmp expect actual | |
1335 | ' | |
1336 | ||
4b340593 MS |
1337 | # malformed configuration files |
1338 | test_expect_success 'barf on syntax error' ' | |
1339 | cat >.git/config <<-\EOF && | |
1340 | # broken section line | |
1341 | [section] | |
1342 | key garbage | |
1343 | EOF | |
1344 | test_must_fail git config --get section.key >actual 2>error && | |
1edbaac3 | 1345 | test_i18ngrep " line 3 " error |
4b340593 MS |
1346 | ' |
1347 | ||
1348 | test_expect_success 'barf on incomplete section header' ' | |
1349 | cat >.git/config <<-\EOF && | |
1350 | # broken section line | |
1351 | [section | |
1352 | key = value | |
1353 | EOF | |
1354 | test_must_fail git config --get section.key >actual 2>error && | |
1edbaac3 | 1355 | test_i18ngrep " line 2 " error |
4b340593 MS |
1356 | ' |
1357 | ||
1358 | test_expect_success 'barf on incomplete string' ' | |
1359 | cat >.git/config <<-\EOF && | |
1360 | # broken section line | |
1361 | [section] | |
1362 | key = "value string | |
1363 | EOF | |
1364 | test_must_fail git config --get section.key >actual 2>error && | |
1edbaac3 | 1365 | test_i18ngrep " line 3 " error |
4b340593 MS |
1366 | ' |
1367 | ||
d4770964 JH |
1368 | test_expect_success 'urlmatch' ' |
1369 | cat >.git/config <<-\EOF && | |
1370 | [http] | |
1371 | sslVerify | |
1372 | [http "https://weak.example.com"] | |
1373 | sslVerify = false | |
1374 | cookieFile = /tmp/cookie.txt | |
1375 | EOF | |
1376 | ||
27b30be6 JK |
1377 | test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual && |
1378 | test_must_be_empty actual && | |
1379 | ||
d4770964 JH |
1380 | echo true >expect && |
1381 | git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual && | |
1382 | test_cmp expect actual && | |
1383 | ||
1384 | echo false >expect && | |
1385 | git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual && | |
1386 | test_cmp expect actual && | |
1387 | ||
1388 | { | |
1389 | echo http.cookiefile /tmp/cookie.txt && | |
1390 | echo http.sslverify false | |
1391 | } >expect && | |
1392 | git config --get-urlmatch HTTP https://weak.example.com >actual && | |
1393 | test_cmp expect actual | |
1394 | ' | |
1395 | ||
af99049c PS |
1396 | test_expect_success 'urlmatch favors more specific URLs' ' |
1397 | cat >.git/config <<-\EOF && | |
1398 | [http "https://example.com/"] | |
1399 | cookieFile = /tmp/root.txt | |
1400 | [http "https://example.com/subdirectory"] | |
1401 | cookieFile = /tmp/subdirectory.txt | |
1402 | [http "https://user@example.com/"] | |
1403 | cookieFile = /tmp/user.txt | |
1404 | [http "https://averylonguser@example.com/"] | |
1405 | cookieFile = /tmp/averylonguser.txt | |
a272b9e7 PS |
1406 | [http "https://preceding.example.com"] |
1407 | cookieFile = /tmp/preceding.txt | |
1408 | [http "https://*.example.com"] | |
1409 | cookieFile = /tmp/wildcard.txt | |
1410 | [http "https://*.example.com/wildcardwithsubdomain"] | |
1411 | cookieFile = /tmp/wildcardwithsubdomain.txt | |
1412 | [http "https://trailing.example.com"] | |
1413 | cookieFile = /tmp/trailing.txt | |
1414 | [http "https://user@*.example.com/"] | |
1415 | cookieFile = /tmp/wildcardwithuser.txt | |
1416 | [http "https://sub.example.com/"] | |
1417 | cookieFile = /tmp/sub.txt | |
af99049c PS |
1418 | EOF |
1419 | ||
1420 | echo http.cookiefile /tmp/root.txt >expect && | |
1421 | git config --get-urlmatch HTTP https://example.com >actual && | |
1422 | test_cmp expect actual && | |
1423 | ||
1424 | echo http.cookiefile /tmp/subdirectory.txt >expect && | |
1425 | git config --get-urlmatch HTTP https://example.com/subdirectory >actual && | |
1426 | test_cmp expect actual && | |
1427 | ||
1428 | echo http.cookiefile /tmp/subdirectory.txt >expect && | |
1429 | git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual && | |
1430 | test_cmp expect actual && | |
1431 | ||
1432 | echo http.cookiefile /tmp/user.txt >expect && | |
1433 | git config --get-urlmatch HTTP https://user@example.com/ >actual && | |
1434 | test_cmp expect actual && | |
1435 | ||
1436 | echo http.cookiefile /tmp/subdirectory.txt >expect && | |
1437 | git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual && | |
a272b9e7 PS |
1438 | test_cmp expect actual && |
1439 | ||
1440 | echo http.cookiefile /tmp/preceding.txt >expect && | |
1441 | git config --get-urlmatch HTTP https://preceding.example.com >actual && | |
1442 | test_cmp expect actual && | |
1443 | ||
1444 | echo http.cookiefile /tmp/wildcard.txt >expect && | |
1445 | git config --get-urlmatch HTTP https://wildcard.example.com >actual && | |
1446 | test_cmp expect actual && | |
1447 | ||
1448 | echo http.cookiefile /tmp/sub.txt >expect && | |
1449 | git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual && | |
1450 | test_cmp expect actual && | |
1451 | ||
1452 | echo http.cookiefile /tmp/trailing.txt >expect && | |
1453 | git config --get-urlmatch HTTP https://trailing.example.com >actual && | |
1454 | test_cmp expect actual && | |
1455 | ||
1456 | echo http.cookiefile /tmp/sub.txt >expect && | |
1457 | git config --get-urlmatch HTTP https://user@sub.example.com >actual && | |
1458 | test_cmp expect actual | |
1459 | ' | |
1460 | ||
1461 | test_expect_success 'urlmatch with wildcard' ' | |
1462 | cat >.git/config <<-\EOF && | |
1463 | [http] | |
1464 | sslVerify | |
1465 | [http "https://*.example.com"] | |
1466 | sslVerify = false | |
1467 | cookieFile = /tmp/cookie.txt | |
1468 | EOF | |
1469 | ||
1470 | test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual && | |
1471 | test_must_be_empty actual && | |
1472 | ||
1473 | echo true >expect && | |
1474 | git config --bool --get-urlmatch http.SSLverify https://example.com >actual && | |
1475 | test_cmp expect actual && | |
1476 | ||
1477 | echo true >expect && | |
1478 | git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual && | |
1479 | test_cmp expect actual && | |
1480 | ||
1481 | echo true >expect && | |
1482 | git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual && | |
1483 | test_cmp expect actual && | |
1484 | ||
1485 | echo false >expect && | |
1486 | git config --bool --get-urlmatch http.sslverify https://good.example.com >actual && | |
1487 | test_cmp expect actual && | |
1488 | ||
1489 | { | |
1490 | echo http.cookiefile /tmp/cookie.txt && | |
1491 | echo http.sslverify false | |
1492 | } >expect && | |
1493 | git config --get-urlmatch HTTP https://good.example.com >actual && | |
1494 | test_cmp expect actual && | |
1495 | ||
1496 | echo http.sslverify >expect && | |
1497 | git config --get-urlmatch HTTP https://more.example.com.au >actual && | |
af99049c PS |
1498 | test_cmp expect actual |
1499 | ' | |
1500 | ||
53ca053b | 1501 | # good section hygiene |
22aedfcc | 1502 | test_expect_success '--unset last key removes section (except if commented)' ' |
53ca053b JK |
1503 | cat >.git/config <<-\EOF && |
1504 | # some generic comment on the configuration file itself | |
1505 | # a comment specific to this "section" section. | |
1506 | [section] | |
1507 | # some intervening lines | |
1508 | # that should also be dropped | |
1509 | ||
1510 | key = value | |
1511 | # please be careful when you update the above variable | |
1512 | EOF | |
1513 | ||
1514 | cat >expect <<-\EOF && | |
1515 | # some generic comment on the configuration file itself | |
dde154b5 JS |
1516 | # a comment specific to this "section" section. |
1517 | [section] | |
1518 | # some intervening lines | |
1519 | # that should also be dropped | |
1520 | ||
1521 | # please be careful when you update the above variable | |
53ca053b JK |
1522 | EOF |
1523 | ||
1524 | git config --unset section.key && | |
dde154b5 JS |
1525 | test_cmp expect .git/config && |
1526 | ||
1527 | cat >.git/config <<-\EOF && | |
1528 | [section] | |
1529 | key = value | |
1530 | [next-section] | |
1531 | EOF | |
1532 | ||
1533 | cat >expect <<-\EOF && | |
1534 | [next-section] | |
53ca053b JK |
1535 | EOF |
1536 | ||
1537 | git config --unset section.key && | |
422e8ef2 JS |
1538 | test_cmp expect .git/config && |
1539 | ||
1540 | q_to_tab >.git/config <<-\EOF && | |
1541 | [one] | |
1542 | Qkey = "multiline \ | |
1543 | QQ# with comment" | |
1544 | [two] | |
1545 | key = true | |
1546 | EOF | |
1547 | git config --unset two.key && | |
1548 | ! grep two .git/config && | |
1549 | ||
1550 | q_to_tab >.git/config <<-\EOF && | |
1551 | [one] | |
1552 | Qkey = "multiline \ | |
1553 | QQ# with comment" | |
1554 | [one] | |
1555 | key = true | |
1556 | EOF | |
1557 | git config --unset-all one.key && | |
1558 | test_line_count = 0 .git/config && | |
1559 | ||
1560 | q_to_tab >.git/config <<-\EOF && | |
1561 | [one] | |
1562 | Qkey = true | |
1563 | Q# a comment not at the start | |
1564 | [two] | |
1565 | Qkey = true | |
1566 | EOF | |
1567 | git config --unset two.key && | |
1568 | grep two .git/config && | |
1569 | ||
1570 | q_to_tab >.git/config <<-\EOF && | |
1571 | [one] | |
1572 | Qkey = not [two "subsection"] | |
1573 | [two "subsection"] | |
1574 | [two "subsection"] | |
1575 | Qkey = true | |
1576 | [TWO "subsection"] | |
1577 | [one] | |
1578 | EOF | |
1579 | git config --unset two.subsection.key && | |
1580 | test "not [two subsection]" = "$(git config one.key)" && | |
1581 | test_line_count = 3 .git/config | |
53ca053b JK |
1582 | ' |
1583 | ||
22aedfcc | 1584 | test_expect_success '--unset-all removes section if empty & uncommented' ' |
b73bdc34 JS |
1585 | cat >.git/config <<-\EOF && |
1586 | [section] | |
1587 | key = value1 | |
1588 | key = value2 | |
1589 | EOF | |
1590 | ||
1591 | git config --unset-all section.key && | |
1592 | test_line_count = 0 .git/config | |
53ca053b JK |
1593 | ' |
1594 | ||
c71d8bb3 | 1595 | test_expect_success 'adding a key into an empty section reuses header' ' |
53ca053b JK |
1596 | cat >.git/config <<-\EOF && |
1597 | [section] | |
1598 | EOF | |
1599 | ||
1600 | q_to_tab >expect <<-\EOF && | |
1601 | [section] | |
1602 | Qkey = value | |
1603 | EOF | |
1604 | ||
60687de5 | 1605 | git config section.key value && |
53ca053b JK |
1606 | test_cmp expect .git/config |
1607 | ' | |
1608 | ||
daa22c6f EW |
1609 | test_expect_success POSIXPERM,PERL 'preserves existing permissions' ' |
1610 | chmod 0600 .git/config && | |
1611 | git config imap.pass Hunter2 && | |
1612 | perl -e \ | |
1613 | "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" && | |
1614 | git config --rename-section imap pop && | |
1615 | perl -e \ | |
1616 | "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600" | |
1617 | ' | |
1618 | ||
45bf3297 JS |
1619 | ! test_have_prereq MINGW || |
1620 | HOME="$(pwd)" # convert to Windows path | |
1621 | ||
70bd879a LS |
1622 | test_expect_success 'set up --show-origin tests' ' |
1623 | INCLUDE_DIR="$HOME/include" && | |
1624 | mkdir -p "$INCLUDE_DIR" && | |
1625 | cat >"$INCLUDE_DIR"/absolute.include <<-\EOF && | |
1626 | [user] | |
1627 | absolute = include | |
1628 | EOF | |
1629 | cat >"$INCLUDE_DIR"/relative.include <<-\EOF && | |
1630 | [user] | |
1631 | relative = include | |
1632 | EOF | |
1633 | cat >"$HOME"/.gitconfig <<-EOF && | |
1634 | [user] | |
1635 | global = true | |
1636 | override = global | |
1637 | [include] | |
1638 | path = "$INCLUDE_DIR/absolute.include" | |
1639 | EOF | |
1640 | cat >.git/config <<-\EOF | |
1641 | [user] | |
1642 | local = true | |
1643 | override = local | |
1644 | [include] | |
1645 | path = ../include/relative.include | |
1646 | EOF | |
1647 | ' | |
1648 | ||
1649 | test_expect_success '--show-origin with --list' ' | |
1650 | cat >expect <<-EOF && | |
1651 | file:$HOME/.gitconfig user.global=true | |
1652 | file:$HOME/.gitconfig user.override=global | |
1653 | file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include | |
1654 | file:$INCLUDE_DIR/absolute.include user.absolute=include | |
1655 | file:.git/config user.local=true | |
1656 | file:.git/config user.override=local | |
1657 | file:.git/config include.path=../include/relative.include | |
1658 | file:.git/../include/relative.include user.relative=include | |
1659 | command line: user.cmdline=true | |
1660 | EOF | |
1661 | git -c user.cmdline=true config --list --show-origin >output && | |
1662 | test_cmp expect output | |
1663 | ' | |
1664 | ||
1665 | test_expect_success '--show-origin with --list --null' ' | |
1666 | cat >expect <<-EOF && | |
1667 | file:$HOME/.gitconfigQuser.global | |
1668 | trueQfile:$HOME/.gitconfigQuser.override | |
1669 | globalQfile:$HOME/.gitconfigQinclude.path | |
1670 | $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute | |
1671 | includeQfile:.git/configQuser.local | |
1672 | trueQfile:.git/configQuser.override | |
1673 | localQfile:.git/configQinclude.path | |
1674 | ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative | |
1675 | includeQcommand line:Quser.cmdline | |
1676 | trueQ | |
1677 | EOF | |
1678 | git -c user.cmdline=true config --null --list --show-origin >output.raw && | |
1679 | nul_to_q <output.raw >output && | |
1680 | # The here-doc above adds a newline that the --null output would not | |
1681 | # include. Add it here to make the two comparable. | |
1682 | echo >>output && | |
1683 | test_cmp expect output | |
1684 | ' | |
1685 | ||
1686 | test_expect_success '--show-origin with single file' ' | |
1687 | cat >expect <<-\EOF && | |
1688 | file:.git/config user.local=true | |
1689 | file:.git/config user.override=local | |
1690 | file:.git/config include.path=../include/relative.include | |
1691 | EOF | |
1692 | git config --local --list --show-origin >output && | |
1693 | test_cmp expect output | |
1694 | ' | |
1695 | ||
1696 | test_expect_success '--show-origin with --get-regexp' ' | |
1697 | cat >expect <<-EOF && | |
1698 | file:$HOME/.gitconfig user.global true | |
1699 | file:.git/config user.local true | |
1700 | EOF | |
1701 | git config --show-origin --get-regexp "user\.[g|l].*" >output && | |
1702 | test_cmp expect output | |
1703 | ' | |
1704 | ||
1705 | test_expect_success '--show-origin getting a single key' ' | |
1706 | cat >expect <<-\EOF && | |
1707 | file:.git/config local | |
1708 | EOF | |
1709 | git config --show-origin user.override >output && | |
1710 | test_cmp expect output | |
1711 | ' | |
1712 | ||
1713 | test_expect_success 'set up custom config file' ' | |
1714 | CUSTOM_CONFIG_FILE="file\" (dq) and spaces.conf" && | |
1715 | cat >"$CUSTOM_CONFIG_FILE" <<-\EOF | |
1716 | [user] | |
1717 | custom = true | |
1718 | EOF | |
1719 | ' | |
1720 | ||
45bf3297 | 1721 | test_expect_success !MINGW '--show-origin escape special file name characters' ' |
70bd879a LS |
1722 | cat >expect <<-\EOF && |
1723 | file:"file\" (dq) and spaces.conf" user.custom=true | |
1724 | EOF | |
1725 | git config --file "$CUSTOM_CONFIG_FILE" --show-origin --list >output && | |
1726 | test_cmp expect output | |
1727 | ' | |
1728 | ||
1729 | test_expect_success '--show-origin stdin' ' | |
1730 | cat >expect <<-\EOF && | |
1731 | standard input: user.custom=true | |
1732 | EOF | |
1733 | git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output && | |
1734 | test_cmp expect output | |
1735 | ' | |
1736 | ||
1737 | test_expect_success '--show-origin stdin with file include' ' | |
1738 | cat >"$INCLUDE_DIR"/stdin.include <<-EOF && | |
1739 | [user] | |
1740 | stdin = include | |
1741 | EOF | |
1742 | cat >expect <<-EOF && | |
1743 | file:$INCLUDE_DIR/stdin.include include | |
1744 | EOF | |
bdbc17e8 MD |
1745 | echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" | |
1746 | git config --show-origin --includes --file - user.stdin >output && | |
1747 | ||
70bd879a LS |
1748 | test_cmp expect output |
1749 | ' | |
1750 | ||
45bf3297 | 1751 | test_expect_success !MINGW '--show-origin blob' ' |
70bd879a | 1752 | blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") && |
0dc3ad99 | 1753 | cat >expect <<-EOF && |
1754 | blob:$blob user.custom=true | |
1755 | EOF | |
70bd879a LS |
1756 | git config --blob=$blob --show-origin --list >output && |
1757 | test_cmp expect output | |
1758 | ' | |
1759 | ||
45bf3297 | 1760 | test_expect_success !MINGW '--show-origin blob ref' ' |
70bd879a LS |
1761 | cat >expect <<-\EOF && |
1762 | blob:"master:file\" (dq) and spaces.conf" user.custom=true | |
1763 | EOF | |
1764 | git add "$CUSTOM_CONFIG_FILE" && | |
1765 | git commit -m "new config file" && | |
1766 | git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output && | |
1767 | test_cmp expect output | |
1768 | ' | |
1769 | ||
25cd2919 | 1770 | test_expect_success '--local requires a repo' ' |
588a538a JK |
1771 | # we expect 128 to ensure that we do not simply |
1772 | # fail to find anything and return code "1" | |
1773 | test_expect_code 128 nongit git config --local foo.bar | |
1774 | ' | |
1775 | ||
0a8950be TB |
1776 | cat >.git/config <<-\EOF && |
1777 | [core] | |
fb0dc3ba | 1778 | foo = true |
0a8950be | 1779 | number = 10 |
fb0dc3ba | 1780 | big = 1M |
0a8950be TB |
1781 | EOF |
1782 | ||
fb0dc3ba | 1783 | test_expect_success 'identical modern --type specifiers are allowed' ' |
a5db0b77 | 1784 | test_cmp_config 1048576 --type=int --type=int core.big |
0a8950be TB |
1785 | ' |
1786 | ||
fb0dc3ba | 1787 | test_expect_success 'identical legacy --type specifiers are allowed' ' |
a5db0b77 | 1788 | test_cmp_config 1048576 --int --int core.big |
fb0dc3ba TB |
1789 | ' |
1790 | ||
1791 | test_expect_success 'identical mixed --type specifiers are allowed' ' | |
a5db0b77 | 1792 | test_cmp_config 1048576 --int --type=int core.big |
fb0dc3ba TB |
1793 | ' |
1794 | ||
1795 | test_expect_success 'non-identical modern --type specifiers are not allowed' ' | |
1796 | test_must_fail git config --type=int --type=bool core.big 2>error && | |
1797 | test_i18ngrep "only one type at a time" error | |
1798 | ' | |
1799 | ||
1800 | test_expect_success 'non-identical legacy --type specifiers are not allowed' ' | |
1801 | test_must_fail git config --int --bool core.big 2>error && | |
1802 | test_i18ngrep "only one type at a time" error | |
1803 | ' | |
1804 | ||
1805 | test_expect_success 'non-identical mixed --type specifiers are not allowed' ' | |
1806 | test_must_fail git config --type=int --bool core.big 2>error && | |
1807 | test_i18ngrep "only one type at a time" error | |
1808 | ' | |
1809 | ||
1810 | test_expect_success '--type allows valid type specifiers' ' | |
a5db0b77 | 1811 | test_cmp_config true --type=bool core.foo |
fb0dc3ba TB |
1812 | ' |
1813 | ||
1814 | test_expect_success '--no-type unsets type specifiers' ' | |
a5db0b77 | 1815 | test_cmp_config 10 --type=bool --no-type core.number |
fb0dc3ba TB |
1816 | ' |
1817 | ||
1818 | test_expect_success 'unset type specifiers may be reset to conflicting ones' ' | |
a5db0b77 | 1819 | test_cmp_config 1048576 --type=bool --no-type --type=int core.big |
fb0dc3ba TB |
1820 | ' |
1821 | ||
1822 | test_expect_success '--type rejects unknown specifiers' ' | |
1823 | test_must_fail git config --type=nonsense core.foo 2>error && | |
1824 | test_i18ngrep "unrecognized --type argument" error | |
1825 | ' | |
1826 | ||
46fc89ce | 1827 | test_expect_success '--replace-all does not invent newlines' ' |
e9313952 JS |
1828 | q_to_tab >.git/config <<-\EOF && |
1829 | [abc]key | |
1830 | QkeepSection | |
1831 | [xyz] | |
1832 | Qkey = 1 | |
1833 | [abc] | |
1834 | Qkey = a | |
1835 | EOF | |
1836 | q_to_tab >expect <<-\EOF && | |
1837 | [abc] | |
1838 | QkeepSection | |
1839 | [xyz] | |
1840 | Qkey = 1 | |
1841 | [abc] | |
1842 | Qkey = b | |
1843 | EOF | |
1844 | git config --replace-all abc.key b && | |
dcbaa0b3 | 1845 | test_cmp expect .git/config |
e9313952 JS |
1846 | ' |
1847 | ||
942c1f53 | 1848 | test_done |