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