]>
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 | 7 | |
06d53148 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
67606301 | 11 | TEST_PASSES_SANITIZE_LEAK=true |
942c1f53 JS |
12 | . ./test-lib.sh |
13 | ||
5a953fc5 JK |
14 | test_expect_success 'clear default config' ' |
15 | rm -f .git/config | |
16 | ' | |
942c1f53 JS |
17 | |
18 | cat > expect << EOF | |
04f6b0a1 | 19 | [section] |
942c1f53 JS |
20 | penguin = little blue |
21 | EOF | |
5a953fc5 | 22 | test_expect_success 'initial' ' |
04f6b0a1 | 23 | git config section.penguin "little blue" && |
5a953fc5 JK |
24 | test_cmp expect .git/config |
25 | ' | |
942c1f53 JS |
26 | |
27 | cat > expect << EOF | |
04f6b0a1 | 28 | [section] |
942c1f53 JS |
29 | penguin = little blue |
30 | Movie = BadPhysics | |
31 | EOF | |
5a953fc5 | 32 | test_expect_success 'mixed case' ' |
04f6b0a1 | 33 | git config Section.Movie BadPhysics && |
5a953fc5 JK |
34 | test_cmp expect .git/config |
35 | ' | |
942c1f53 JS |
36 | |
37 | cat > expect << EOF | |
04f6b0a1 | 38 | [section] |
942c1f53 JS |
39 | penguin = little blue |
40 | Movie = BadPhysics | |
04f6b0a1 | 41 | [Sections] |
942c1f53 JS |
42 | WhatEver = Second |
43 | EOF | |
5a953fc5 | 44 | test_expect_success 'similar section' ' |
04f6b0a1 | 45 | git config Sections.WhatEver Second && |
5a953fc5 JK |
46 | test_cmp expect .git/config |
47 | ' | |
942c1f53 JS |
48 | |
49 | cat > expect << EOF | |
04f6b0a1 | 50 | [section] |
942c1f53 JS |
51 | penguin = little blue |
52 | Movie = BadPhysics | |
53 | UPPERCASE = true | |
04f6b0a1 | 54 | [Sections] |
942c1f53 JS |
55 | WhatEver = Second |
56 | EOF | |
5a953fc5 | 57 | test_expect_success 'uppercase section' ' |
04f6b0a1 | 58 | git config SECTION.UPPERCASE true && |
5a953fc5 JK |
59 | test_cmp expect .git/config |
60 | ' | |
942c1f53 | 61 | |
ed838e66 | 62 | test_expect_success 'replace with non-match' ' |
04f6b0a1 | 63 | git config section.penguin kingpin !blue |
ed838e66 | 64 | ' |
f98d863d | 65 | |
ed838e66 | 66 | test_expect_success 'replace with non-match (actually matching)' ' |
04f6b0a1 | 67 | git config section.penguin "very blue" !kingpin |
ed838e66 | 68 | ' |
f98d863d JS |
69 | |
70 | cat > expect << EOF | |
04f6b0a1 | 71 | [section] |
f98d863d JS |
72 | penguin = very blue |
73 | Movie = BadPhysics | |
74 | UPPERCASE = true | |
75 | penguin = kingpin | |
04f6b0a1 | 76 | [Sections] |
f98d863d JS |
77 | WhatEver = Second |
78 | EOF | |
79 | ||
5a953fc5 | 80 | test_expect_success 'non-match result' 'test_cmp expect .git/config' |
f98d863d | 81 | |
88d42af8 | 82 | test_expect_success 'find mixed-case key by canonical name' ' |
04f6b0a1 | 83 | test_cmp_config Second sections.whatever |
88d42af8 JK |
84 | ' |
85 | ||
86 | test_expect_success 'find mixed-case key by non-canonical name' ' | |
04f6b0a1 | 87 | test_cmp_config Second SeCtIoNs.WhAtEvEr |
88d42af8 JK |
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 | |
a5db0b77 NTND |
97 | test_cmp_config one section.subsection.key && |
98 | test_cmp_config two section.SubSection.key | |
88d42af8 | 99 | ' |
f98d863d | 100 | |
7a31cc0f FL |
101 | cat > .git/config <<\EOF |
102 | [alpha] | |
103 | bar = foo | |
104 | [beta] | |
105 | baz = multiple \ | |
106 | lines | |
85bf5d61 | 107 | foo = bar |
7a31cc0f FL |
108 | EOF |
109 | ||
ed838e66 JK |
110 | test_expect_success 'unset with cont. lines' ' |
111 | git config --unset beta.baz | |
112 | ' | |
7a31cc0f FL |
113 | |
114 | cat > expect <<\EOF | |
115 | [alpha] | |
116 | bar = foo | |
117 | [beta] | |
85bf5d61 | 118 | foo = bar |
7a31cc0f FL |
119 | EOF |
120 | ||
5a953fc5 | 121 | test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config' |
7a31cc0f | 122 | |
942c1f53 JS |
123 | cat > .git/config << EOF |
124 | [beta] ; silly comment # another comment | |
125 | noIndent= sillyValue ; 'nother silly comment | |
126 | ||
127 | # empty line | |
128 | ; comment | |
129 | haha ="beta" # last silly comment | |
4ddba79d JS |
130 | haha = hello |
131 | haha = bello | |
942c1f53 JS |
132 | [nextSection] noNewline = ouch |
133 | EOF | |
134 | ||
4ddba79d JS |
135 | cp .git/config .git/config2 |
136 | ||
ed838e66 JK |
137 | test_expect_success 'multiple unset' ' |
138 | git config --unset-all beta.haha | |
139 | ' | |
4ddba79d JS |
140 | |
141 | cat > expect << EOF | |
142 | [beta] ; silly comment # another comment | |
143 | noIndent= sillyValue ; 'nother silly comment | |
144 | ||
145 | # empty line | |
146 | ; comment | |
147 | [nextSection] noNewline = ouch | |
148 | EOF | |
149 | ||
ed838e66 JK |
150 | test_expect_success 'multiple unset is correct' ' |
151 | test_cmp expect .git/config | |
152 | ' | |
4ddba79d | 153 | |
bf71b4b3 CR |
154 | cp .git/config2 .git/config |
155 | ||
156 | test_expect_success '--replace-all missing value' ' | |
157 | test_must_fail git config --replace-all beta.haha && | |
158 | test_cmp .git/config2 .git/config | |
159 | ' | |
160 | ||
161 | rm .git/config2 | |
4ddba79d | 162 | |
ed838e66 JK |
163 | test_expect_success '--replace-all' ' |
164 | git config --replace-all beta.haha gamma | |
165 | ' | |
4ddba79d JS |
166 | |
167 | cat > expect << EOF | |
168 | [beta] ; silly comment # another comment | |
169 | noIndent= sillyValue ; 'nother silly comment | |
170 | ||
171 | # empty line | |
172 | ; comment | |
173 | haha = gamma | |
174 | [nextSection] noNewline = ouch | |
175 | EOF | |
176 | ||
ed838e66 JK |
177 | test_expect_success 'all replaced' ' |
178 | test_cmp expect .git/config | |
179 | ' | |
942c1f53 JS |
180 | |
181 | cat > expect << EOF | |
182 | [beta] ; silly comment # another comment | |
183 | noIndent= sillyValue ; 'nother silly comment | |
184 | ||
185 | # empty line | |
186 | ; comment | |
187 | haha = alpha | |
188 | [nextSection] noNewline = ouch | |
189 | EOF | |
5a953fc5 JK |
190 | test_expect_success 'really mean test' ' |
191 | git config beta.haha alpha && | |
192 | test_cmp expect .git/config | |
193 | ' | |
942c1f53 JS |
194 | |
195 | cat > expect << EOF | |
196 | [beta] ; silly comment # another comment | |
197 | noIndent= sillyValue ; 'nother silly comment | |
198 | ||
199 | # empty line | |
200 | ; comment | |
201 | haha = alpha | |
202 | [nextSection] | |
203 | nonewline = wow | |
204 | EOF | |
5a953fc5 JK |
205 | test_expect_success 'really really mean test' ' |
206 | git config nextsection.nonewline wow && | |
207 | test_cmp expect .git/config | |
208 | ' | |
942c1f53 | 209 | |
ed838e66 | 210 | test_expect_success 'get value' ' |
a5db0b77 | 211 | test_cmp_config alpha beta.haha |
ed838e66 | 212 | ' |
942c1f53 JS |
213 | |
214 | cat > expect << EOF | |
215 | [beta] ; silly comment # another comment | |
216 | noIndent= sillyValue ; 'nother silly comment | |
217 | ||
218 | # empty line | |
219 | ; comment | |
220 | [nextSection] | |
221 | nonewline = wow | |
222 | EOF | |
5a953fc5 JK |
223 | test_expect_success 'unset' ' |
224 | git config --unset beta.haha && | |
225 | test_cmp expect .git/config | |
226 | ' | |
942c1f53 JS |
227 | |
228 | cat > expect << EOF | |
229 | [beta] ; silly comment # another comment | |
230 | noIndent= sillyValue ; 'nother silly comment | |
231 | ||
232 | # empty line | |
233 | ; comment | |
234 | [nextSection] | |
235 | nonewline = wow | |
236 | NoNewLine = wow2 for me | |
237 | EOF | |
5a953fc5 JK |
238 | test_expect_success 'multivar' ' |
239 | git config nextsection.NoNewLine "wow2 for me" "for me$" && | |
240 | test_cmp expect .git/config | |
241 | ' | |
942c1f53 | 242 | |
ed838e66 JK |
243 | test_expect_success 'non-match' ' |
244 | git config --get nextsection.nonewline !for | |
245 | ' | |
f98d863d | 246 | |
ed838e66 | 247 | test_expect_success 'non-match value' ' |
a5db0b77 | 248 | test_cmp_config wow --get nextsection.nonewline !for |
ed838e66 | 249 | ' |
f98d863d | 250 | |
00b347d3 | 251 | test_expect_success 'multi-valued get returns final one' ' |
a5db0b77 | 252 | test_cmp_config "wow2 for me" --get nextsection.nonewline |
41ac414e | 253 | ' |
4ddba79d | 254 | |
cb20b691 JK |
255 | test_expect_success 'multi-valued get-all returns all' ' |
256 | cat >expect <<-\EOF && | |
257 | wow | |
258 | wow2 for me | |
259 | EOF | |
260 | git config --get-all nextsection.nonewline >actual && | |
261 | test_cmp expect actual | |
ed838e66 | 262 | ' |
4ddba79d | 263 | |
942c1f53 JS |
264 | cat > expect << EOF |
265 | [beta] ; silly comment # another comment | |
266 | noIndent= sillyValue ; 'nother silly comment | |
267 | ||
268 | # empty line | |
269 | ; comment | |
270 | [nextSection] | |
271 | nonewline = wow3 | |
272 | NoNewLine = wow2 for me | |
273 | EOF | |
5a953fc5 JK |
274 | test_expect_success 'multivar replace' ' |
275 | git config nextsection.nonewline "wow3" "wow$" && | |
276 | test_cmp expect .git/config | |
277 | ' | |
942c1f53 | 278 | |
41ac414e | 279 | test_expect_success 'ambiguous unset' ' |
d492b31c | 280 | test_must_fail git config --unset nextsection.nonewline |
41ac414e | 281 | ' |
942c1f53 | 282 | |
41ac414e | 283 | test_expect_success 'invalid unset' ' |
d492b31c | 284 | test_must_fail git config --unset somesection.nonewline |
41ac414e | 285 | ' |
942c1f53 | 286 | |
942c1f53 JS |
287 | cat > expect << EOF |
288 | [beta] ; silly comment # another comment | |
289 | noIndent= sillyValue ; 'nother silly comment | |
290 | ||
291 | # empty line | |
292 | ; comment | |
293 | [nextSection] | |
294 | NoNewLine = wow2 for me | |
295 | EOF | |
296 | ||
5a953fc5 JK |
297 | test_expect_success 'multivar unset' ' |
298 | git config --unset nextsection.nonewline "wow3$" && | |
299 | test_cmp expect .git/config | |
300 | ' | |
942c1f53 | 301 | |
d492b31c | 302 | test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla' |
942c1f53 | 303 | |
5be60078 | 304 | test_expect_success 'correct key' 'git config 123456.a123 987' |
942c1f53 | 305 | |
ed838e66 JK |
306 | test_expect_success 'hierarchical section' ' |
307 | git config Version.1.2.3eX.Alpha beta | |
308 | ' | |
b17e659d JS |
309 | |
310 | cat > expect << EOF | |
311 | [beta] ; silly comment # another comment | |
312 | noIndent= sillyValue ; 'nother silly comment | |
313 | ||
314 | # empty line | |
315 | ; comment | |
316 | [nextSection] | |
317 | NoNewLine = wow2 for me | |
318 | [123456] | |
319 | a123 = 987 | |
d14f7764 LT |
320 | [Version "1.2.3eX"] |
321 | Alpha = beta | |
b17e659d JS |
322 | EOF |
323 | ||
ed838e66 JK |
324 | test_expect_success 'hierarchical section value' ' |
325 | test_cmp expect .git/config | |
326 | ' | |
b17e659d | 327 | |
2fa9a0fb JS |
328 | cat > expect << EOF |
329 | beta.noindent=sillyValue | |
330 | nextsection.nonewline=wow2 for me | |
331 | 123456.a123=987 | |
d55aaefa | 332 | version.1.2.3eX.alpha=beta |
2fa9a0fb JS |
333 | EOF |
334 | ||
ed838e66 JK |
335 | test_expect_success 'working --list' ' |
336 | git config --list > output && | |
337 | test_cmp expect output | |
338 | ' | |
1f2baa78 JK |
339 | test_expect_success '--list without repo produces empty output' ' |
340 | git --git-dir=nonexistent config --list >output && | |
1c5e94f4 | 341 | test_must_be_empty output |
1f2baa78 JK |
342 | ' |
343 | ||
578625fa SG |
344 | cat > expect << EOF |
345 | beta.noindent | |
346 | nextsection.nonewline | |
347 | 123456.a123 | |
348 | version.1.2.3eX.alpha | |
349 | EOF | |
350 | ||
351 | test_expect_success '--name-only --list' ' | |
352 | git config --name-only --list >output && | |
353 | test_cmp expect output | |
354 | ' | |
355 | ||
2fa9a0fb JS |
356 | cat > expect << EOF |
357 | beta.noindent sillyValue | |
358 | nextsection.nonewline wow2 for me | |
359 | EOF | |
360 | ||
ed838e66 JK |
361 | test_expect_success '--get-regexp' ' |
362 | git config --get-regexp in >output && | |
363 | test_cmp expect output | |
364 | ' | |
2fa9a0fb | 365 | |
578625fa SG |
366 | cat > expect << EOF |
367 | beta.noindent | |
368 | nextsection.nonewline | |
369 | EOF | |
370 | ||
371 | test_expect_success '--name-only --get-regexp' ' | |
372 | git config --name-only --get-regexp in >output && | |
373 | test_cmp expect output | |
374 | ' | |
375 | ||
89c4afe0 BG |
376 | cat > expect << EOF |
377 | wow2 for me | |
378 | wow4 for you | |
379 | EOF | |
380 | ||
5a953fc5 JK |
381 | test_expect_success '--add' ' |
382 | git config --add nextsection.nonewline "wow4 for you" && | |
383 | git config --get-all nextsection.nonewline > output && | |
384 | test_cmp expect output | |
385 | ' | |
89c4afe0 | 386 | |
f067a137 JF |
387 | cat > .git/config << EOF |
388 | [novalue] | |
389 | variable | |
09bc098c CC |
390 | [emptyvalue] |
391 | variable = | |
f067a137 JF |
392 | EOF |
393 | ||
ed838e66 JK |
394 | test_expect_success 'get variable with no value' ' |
395 | git config --get novalue.variable ^$ | |
396 | ' | |
f067a137 | 397 | |
ed838e66 JK |
398 | test_expect_success 'get variable with empty value' ' |
399 | git config --get emptyvalue.variable ^$ | |
400 | ' | |
09bc098c | 401 | |
b69ba460 FL |
402 | echo novalue.variable > expect |
403 | ||
ed838e66 JK |
404 | test_expect_success 'get-regexp variable with no value' ' |
405 | git config --get-regexp novalue > output && | |
406 | test_cmp expect output | |
407 | ' | |
b69ba460 | 408 | |
008e3cc5 MM |
409 | echo 'novalue.variable true' > expect |
410 | ||
ed838e66 JK |
411 | test_expect_success 'get-regexp --bool variable with no value' ' |
412 | git config --bool --get-regexp novalue > output && | |
413 | test_cmp expect output | |
414 | ' | |
008e3cc5 | 415 | |
09bc098c CC |
416 | echo 'emptyvalue.variable ' > expect |
417 | ||
ed838e66 JK |
418 | test_expect_success 'get-regexp variable with empty value' ' |
419 | git config --get-regexp emptyvalue > output && | |
420 | test_cmp expect output | |
421 | ' | |
09bc098c CC |
422 | |
423 | echo true > expect | |
424 | ||
ed838e66 JK |
425 | test_expect_success 'get bool variable with no value' ' |
426 | git config --bool novalue.variable > output && | |
427 | test_cmp expect output | |
428 | ' | |
09bc098c CC |
429 | |
430 | echo false > expect | |
431 | ||
ed838e66 JK |
432 | test_expect_success 'get bool variable with empty value' ' |
433 | git config --bool emptyvalue.variable > output && | |
434 | test_cmp expect output | |
435 | ' | |
09bc098c | 436 | |
003f69b2 JK |
437 | test_expect_success 'no arguments, but no crash' ' |
438 | test_must_fail git config >output 2>&1 && | |
9a001381 | 439 | test_i18ngrep usage output |
003f69b2 | 440 | ' |
2fa9a0fb | 441 | |
bd886fd3 SE |
442 | cat > .git/config << EOF |
443 | [a.b] | |
444 | c = d | |
445 | EOF | |
446 | ||
bd886fd3 SE |
447 | cat > expect << EOF |
448 | [a.b] | |
449 | c = d | |
450 | [a] | |
451 | x = y | |
452 | EOF | |
453 | ||
5a953fc5 JK |
454 | test_expect_success 'new section is partial match of another' ' |
455 | git config a.x y && | |
456 | test_cmp expect .git/config | |
457 | ' | |
bd886fd3 SE |
458 | |
459 | cat > expect << EOF | |
460 | [a.b] | |
461 | c = d | |
462 | [a] | |
463 | x = y | |
464 | b = c | |
465 | [b] | |
466 | x = y | |
467 | EOF | |
468 | ||
5a953fc5 JK |
469 | test_expect_success 'new variable inserts into proper section' ' |
470 | git config b.x y && | |
471 | git config a.b c && | |
472 | test_cmp expect .git/config | |
473 | ' | |
bd886fd3 | 474 | |
f7e87141 | 475 | test_expect_success 'alternative --file (non-existing file should fail)' ' |
34479d71 MÅ |
476 | test_must_fail git config --file non-existing-config -l && |
477 | test_must_fail git config --file non-existing-config test.xyzzy | |
ed838e66 | 478 | ' |
773a69fb | 479 | |
9c3796fc JS |
480 | cat > other-config << EOF |
481 | [ein] | |
482 | bahn = strasse | |
483 | EOF | |
484 | ||
485 | cat > expect << EOF | |
486 | ein.bahn=strasse | |
487 | EOF | |
488 | ||
5a953fc5 | 489 | test_expect_success 'alternative GIT_CONFIG' ' |
3caec73b | 490 | GIT_CONFIG=other-config git config --list >output && |
5a953fc5 JK |
491 | test_cmp expect output |
492 | ' | |
9c3796fc | 493 | |
ed838e66 | 494 | test_expect_success 'alternative GIT_CONFIG (--file)' ' |
3caec73b | 495 | git config --file other-config --list >output && |
ed838e66 JK |
496 | test_cmp expect output |
497 | ' | |
773a69fb | 498 | |
3caec73b KS |
499 | test_expect_success 'alternative GIT_CONFIG (--file=-)' ' |
500 | git config --file - --list <other-config >output && | |
501 | test_cmp expect output | |
502 | ' | |
503 | ||
504 | test_expect_success 'setting a value in stdin is an error' ' | |
505 | test_must_fail git config --file - some.value foo | |
506 | ' | |
507 | ||
508 | test_expect_success 'editing stdin is an error' ' | |
509 | test_must_fail git config --file - --edit | |
510 | ' | |
511 | ||
65807ee6 JH |
512 | test_expect_success 'refer config from subdirectory' ' |
513 | mkdir x && | |
a5db0b77 | 514 | test_cmp_config -C x strasse --file=../other-config --get ein.bahn |
270a3443 JK |
515 | ' |
516 | ||
9c3796fc JS |
517 | cat > expect << EOF |
518 | [ein] | |
519 | bahn = strasse | |
520 | [anwohner] | |
521 | park = ausweis | |
522 | EOF | |
523 | ||
f7e87141 JK |
524 | test_expect_success '--set in alternative file' ' |
525 | git config --file=other-config anwohner.park ausweis && | |
5a953fc5 JK |
526 | test_cmp expect other-config |
527 | ' | |
9c3796fc | 528 | |
0667fcfb JS |
529 | cat > .git/config << EOF |
530 | # Hallo | |
531 | #Bello | |
532 | [branch "eins"] | |
533 | x = 1 | |
534 | [branch.eins] | |
535 | y = 1 | |
536 | [branch "1 234 blabl/a"] | |
537 | weird | |
538 | EOF | |
539 | ||
ed838e66 JK |
540 | test_expect_success 'rename section' ' |
541 | git config --rename-section branch.eins branch.zwei | |
542 | ' | |
0667fcfb JS |
543 | |
544 | cat > expect << EOF | |
545 | # Hallo | |
546 | #Bello | |
547 | [branch "zwei"] | |
548 | x = 1 | |
549 | [branch "zwei"] | |
550 | y = 1 | |
551 | [branch "1 234 blabl/a"] | |
552 | weird | |
553 | EOF | |
554 | ||
ed838e66 JK |
555 | test_expect_success 'rename succeeded' ' |
556 | test_cmp expect .git/config | |
557 | ' | |
0667fcfb | 558 | |
ed838e66 | 559 | test_expect_success 'rename non-existing section' ' |
d492b31c SB |
560 | test_must_fail git config --rename-section \ |
561 | branch."world domination" branch.drei | |
41ac414e | 562 | ' |
0667fcfb | 563 | |
ed838e66 JK |
564 | test_expect_success 'rename succeeded' ' |
565 | test_cmp expect .git/config | |
566 | ' | |
0667fcfb | 567 | |
ed838e66 JK |
568 | test_expect_success 'rename another section' ' |
569 | git config --rename-section branch."1 234 blabl/a" branch.drei | |
570 | ' | |
0667fcfb JS |
571 | |
572 | cat > expect << EOF | |
573 | # Hallo | |
574 | #Bello | |
575 | [branch "zwei"] | |
576 | x = 1 | |
577 | [branch "zwei"] | |
578 | y = 1 | |
579 | [branch "drei"] | |
580 | weird | |
581 | EOF | |
582 | ||
ed838e66 JK |
583 | test_expect_success 'rename succeeded' ' |
584 | test_cmp expect .git/config | |
585 | ' | |
9a5abfc7 AV |
586 | |
587 | cat >> .git/config << EOF | |
588 | [branch "vier"] z = 1 | |
589 | EOF | |
590 | ||
ed838e66 JK |
591 | test_expect_success 'rename a section with a var on the same line' ' |
592 | git config --rename-section branch.vier branch.zwei | |
593 | ' | |
9a5abfc7 AV |
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 | [branch "zwei"] | |
605 | z = 1 | |
606 | EOF | |
607 | ||
ed838e66 JK |
608 | test_expect_success 'rename succeeded' ' |
609 | test_cmp expect .git/config | |
610 | ' | |
0667fcfb | 611 | |
94a35b1a JK |
612 | test_expect_success 'renaming empty section name is rejected' ' |
613 | test_must_fail git config --rename-section branch.zwei "" | |
614 | ' | |
615 | ||
616 | test_expect_success 'renaming to bogus section is rejected' ' | |
617 | test_must_fail git config --rename-section branch.zwei "bogus name" | |
618 | ' | |
619 | ||
118f8b24 PB |
620 | cat >> .git/config << EOF |
621 | [branch "zwei"] a = 1 [branch "vier"] | |
622 | EOF | |
623 | ||
ed838e66 JK |
624 | test_expect_success 'remove section' ' |
625 | git config --remove-section branch.zwei | |
626 | ' | |
118f8b24 PB |
627 | |
628 | cat > expect << EOF | |
629 | # Hallo | |
630 | #Bello | |
631 | [branch "drei"] | |
632 | weird | |
633 | EOF | |
634 | ||
ed838e66 JK |
635 | test_expect_success 'section was removed properly' ' |
636 | test_cmp expect .git/config | |
637 | ' | |
118f8b24 | 638 | |
b18a2be3 SP |
639 | cat > expect << EOF |
640 | [gitcvs] | |
641 | enabled = true | |
642 | dbname = %Ggitcvs2.%a.%m.sqlite | |
643 | [gitcvs "ext"] | |
644 | dbname = %Ggitcvs1.%a.%m.sqlite | |
645 | EOF | |
646 | ||
647 | test_expect_success 'section ending' ' | |
795290e5 | 648 | rm -f .git/config && |
5be60078 JH |
649 | git config gitcvs.enabled true && |
650 | git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && | |
651 | git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && | |
5a953fc5 | 652 | test_cmp expect .git/config |
b18a2be3 SP |
653 | |
654 | ' | |
655 | ||
d77a64d3 | 656 | test_expect_success numbers ' |
5be60078 JH |
657 | git config kilo.gram 1k && |
658 | git config mega.ton 1m && | |
ed838e66 JK |
659 | echo 1024 >expect && |
660 | echo 1048576 >>expect && | |
661 | git config --int --get kilo.gram >actual && | |
662 | git config --int --get mega.ton >>actual && | |
663 | test_cmp expect actual | |
d77a64d3 SP |
664 | ' |
665 | ||
00160242 JK |
666 | test_expect_success '--int is at least 64 bits' ' |
667 | git config giga.watts 121g && | |
a5db0b77 NTND |
668 | echo >expect && |
669 | test_cmp_config 129922760704 --int --get giga.watts | |
00160242 JK |
670 | ' |
671 | ||
c8deb5a1 | 672 | test_expect_success 'invalid unit' ' |
c8deb5a1 | 673 | git config aninvalid.unit "1auto" && |
a5db0b77 | 674 | test_cmp_config 1auto aninvalid.unit && |
ed838e66 | 675 | test_must_fail git config --int --get aninvalid.unit 2>actual && |
2ec20212 | 676 | test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual |
c8deb5a1 SP |
677 | ' |
678 | ||
f276e2a4 AK |
679 | test_expect_success 'invalid unit boolean' ' |
680 | git config commit.gpgsign "1true" && | |
681 | test_cmp_config 1true commit.gpgsign && | |
682 | test_must_fail git config --bool --get commit.gpgsign 2>actual && | |
683 | test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual | |
684 | ' | |
685 | ||
e2e14251 JS |
686 | test_expect_success 'line number is reported correctly' ' |
687 | printf "[bool]\n\tvar\n" >invalid && | |
688 | test_must_fail git config -f invalid --path bool.var 2>actual && | |
689 | test_i18ngrep "line 2" actual | |
690 | ' | |
691 | ||
473166b9 | 692 | test_expect_success 'invalid stdin config' ' |
473166b9 | 693 | echo "[broken" | test_must_fail git config --list --file - >output 2>&1 && |
2ec20212 | 694 | test_i18ngrep "bad config line 1 in standard input" output |
473166b9 LS |
695 | ' |
696 | ||
cab333cb FL |
697 | cat > expect << EOF |
698 | true | |
699 | false | |
700 | true | |
701 | false | |
702 | true | |
703 | false | |
704 | true | |
705 | false | |
706 | EOF | |
707 | ||
708 | test_expect_success bool ' | |
709 | ||
5be60078 JH |
710 | git config bool.true1 01 && |
711 | git config bool.true2 -1 && | |
712 | git config bool.true3 YeS && | |
713 | git config bool.true4 true && | |
714 | git config bool.false1 000 && | |
715 | git config bool.false2 "" && | |
716 | git config bool.false3 nO && | |
717 | git config bool.false4 FALSE && | |
cab333cb FL |
718 | rm -f result && |
719 | for i in 1 2 3 4 | |
720 | do | |
74d2f569 | 721 | git config --bool --get bool.true$i >>result && |
db5875aa | 722 | git config --bool --get bool.false$i >>result || return 1 |
e3e042b1 | 723 | done && |
ed838e66 | 724 | test_cmp expect result' |
cab333cb | 725 | |
41ac414e | 726 | test_expect_success 'invalid bool (--get)' ' |
cab333cb | 727 | |
5be60078 | 728 | git config bool.nobool foobar && |
d492b31c | 729 | test_must_fail git config --bool --get bool.nobool' |
cab333cb | 730 | |
41ac414e | 731 | test_expect_success 'invalid bool (set)' ' |
db1696b8 | 732 | |
d492b31c | 733 | test_must_fail git config --bool bool.nobool foobar' |
db1696b8 | 734 | |
db1696b8 FL |
735 | cat > expect <<\EOF |
736 | [bool] | |
737 | true1 = true | |
738 | true2 = true | |
739 | true3 = true | |
740 | true4 = true | |
741 | false1 = false | |
742 | false2 = false | |
743 | false3 = false | |
744 | false4 = false | |
745 | EOF | |
746 | ||
747 | test_expect_success 'set --bool' ' | |
748 | ||
795290e5 | 749 | rm -f .git/config && |
5be60078 JH |
750 | git config --bool bool.true1 01 && |
751 | git config --bool bool.true2 -1 && | |
752 | git config --bool bool.true3 YeS && | |
753 | git config --bool bool.true4 true && | |
754 | git config --bool bool.false1 000 && | |
755 | git config --bool bool.false2 "" && | |
756 | git config --bool bool.false3 nO && | |
757 | git config --bool bool.false4 FALSE && | |
ed838e66 | 758 | test_cmp expect .git/config' |
db1696b8 | 759 | |
db1696b8 FL |
760 | cat > expect <<\EOF |
761 | [int] | |
762 | val1 = 1 | |
763 | val2 = -1 | |
764 | val3 = 5242880 | |
765 | EOF | |
766 | ||
767 | test_expect_success 'set --int' ' | |
768 | ||
795290e5 | 769 | rm -f .git/config && |
5be60078 JH |
770 | git config --int int.val1 01 && |
771 | git config --int int.val2 -1 && | |
772 | git config --int int.val3 5m && | |
ed838e66 JK |
773 | test_cmp expect .git/config |
774 | ' | |
db1696b8 | 775 | |
ed838e66 JK |
776 | test_expect_success 'get --bool-or-int' ' |
777 | cat >.git/config <<-\EOF && | |
778 | [bool] | |
779 | true1 | |
c35b0b58 | 780 | true2 = true |
ed838e66 JK |
781 | false = false |
782 | [int] | |
c35b0b58 JH |
783 | int1 = 0 |
784 | int2 = 1 | |
785 | int3 = -1 | |
ed838e66 JK |
786 | EOF |
787 | cat >expect <<-\EOF && | |
788 | true | |
789 | true | |
790 | false | |
791 | 0 | |
792 | 1 | |
793 | -1 | |
794 | EOF | |
795 | { | |
796 | git config --bool-or-int bool.true1 && | |
797 | git config --bool-or-int bool.true2 && | |
798 | git config --bool-or-int bool.false && | |
799 | git config --bool-or-int int.int1 && | |
800 | git config --bool-or-int int.int2 && | |
801 | git config --bool-or-int int.int3 | |
802 | } >actual && | |
803 | test_cmp expect actual | |
c35b0b58 JH |
804 | ' |
805 | ||
c35b0b58 JH |
806 | cat >expect <<\EOF |
807 | [bool] | |
808 | true1 = true | |
809 | false1 = false | |
810 | true2 = true | |
811 | false2 = false | |
812 | [int] | |
813 | int1 = 0 | |
814 | int2 = 1 | |
815 | int3 = -1 | |
816 | EOF | |
817 | ||
818 | test_expect_success 'set --bool-or-int' ' | |
795290e5 | 819 | rm -f .git/config && |
c35b0b58 JH |
820 | git config --bool-or-int bool.true1 true && |
821 | git config --bool-or-int bool.false1 false && | |
822 | git config --bool-or-int bool.true2 yes && | |
823 | git config --bool-or-int bool.false2 no && | |
824 | git config --bool-or-int int.int1 0 && | |
825 | git config --bool-or-int int.int2 1 && | |
826 | git config --bool-or-int int.int3 -1 && | |
827 | test_cmp expect .git/config | |
828 | ' | |
829 | ||
1349484e MM |
830 | cat >expect <<\EOF |
831 | [path] | |
832 | home = ~/ | |
833 | normal = /dev/null | |
834 | trailingtilde = foo~ | |
835 | EOF | |
836 | ||
f57a8715 | 837 | test_expect_success !MINGW 'set --path' ' |
795290e5 | 838 | rm -f .git/config && |
1349484e MM |
839 | git config --path path.home "~/" && |
840 | git config --path path.normal "/dev/null" && | |
841 | git config --path path.trailingtilde "foo~" && | |
842 | test_cmp expect .git/config' | |
843 | ||
f57a8715 | 844 | if test_have_prereq !MINGW && test "${HOME+set}" |
79bf1490 JN |
845 | then |
846 | test_set_prereq HOMEVAR | |
847 | fi | |
848 | ||
1349484e MM |
849 | cat >expect <<EOF |
850 | $HOME/ | |
851 | /dev/null | |
852 | foo~ | |
853 | EOF | |
854 | ||
79bf1490 | 855 | test_expect_success HOMEVAR 'get --path' ' |
1349484e MM |
856 | git config --get --path path.home > result && |
857 | git config --get --path path.normal >> result && | |
858 | git config --get --path path.trailingtilde >> result && | |
859 | test_cmp expect result | |
860 | ' | |
861 | ||
79bf1490 JN |
862 | cat >expect <<\EOF |
863 | /dev/null | |
864 | foo~ | |
865 | EOF | |
866 | ||
f57a8715 | 867 | test_expect_success !MINGW 'get --path copes with unset $HOME' ' |
79bf1490 | 868 | ( |
ed6c994a | 869 | sane_unset HOME && |
79bf1490 JN |
870 | test_must_fail git config --get --path path.home \ |
871 | >result 2>msg && | |
872 | git config --get --path path.normal >>result && | |
873 | git config --get --path path.trailingtilde >>result | |
874 | ) && | |
1edbaac3 | 875 | test_i18ngrep "[Ff]ailed to expand.*~/" msg && |
79bf1490 JN |
876 | test_cmp expect result |
877 | ' | |
878 | ||
962c38ee CMN |
879 | test_expect_success 'get --path barfs on boolean variable' ' |
880 | echo "[path]bool" >.git/config && | |
881 | test_must_fail git config --get --path path.bool | |
882 | ' | |
883 | ||
5f967424 HM |
884 | test_expect_success 'get --expiry-date' ' |
885 | rel="3.weeks.5.days.00:00" && | |
886 | rel_out="$rel ->" && | |
887 | cat >.git/config <<-\EOF && | |
888 | [date] | |
889 | valid1 = "3.weeks.5.days 00:00" | |
890 | valid2 = "Fri Jun 4 15:46:55 2010" | |
891 | valid3 = "2017/11/11 11:11:11PM" | |
892 | valid4 = "2017/11/10 09:08:07 PM" | |
893 | valid5 = "never" | |
894 | invalid1 = "abc" | |
895 | EOF | |
896 | cat >expect <<-EOF && | |
a801a7cf | 897 | $(test-tool date timestamp $rel) |
5f967424 HM |
898 | 1275666415 |
899 | 1510441871 | |
900 | 1510348087 | |
901 | 0 | |
902 | EOF | |
d38722eb | 903 | : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" && |
5f967424 | 904 | { |
7abcbcb7 | 905 | echo "$rel_out $(git config --expiry-date date.valid1)" && |
5f967424 HM |
906 | git config --expiry-date date.valid2 && |
907 | git config --expiry-date date.valid3 && | |
908 | git config --expiry-date date.valid4 && | |
909 | git config --expiry-date date.valid5 | |
910 | } >actual && | |
911 | test_cmp expect actual && | |
912 | test_must_fail git config --expiry-date date.invalid1 | |
913 | ' | |
914 | ||
63e2a0f8 TB |
915 | test_expect_success 'get --type=color' ' |
916 | rm .git/config && | |
917 | git config foo.color "red" && | |
918 | git config --get --type=color foo.color >actual.raw && | |
919 | test_decode_color <actual.raw >actual && | |
920 | echo "<RED>" >expect && | |
921 | test_cmp expect actual | |
922 | ' | |
923 | ||
924 | cat >expect << EOF | |
925 | [foo] | |
926 | color = red | |
927 | EOF | |
928 | ||
929 | test_expect_success 'set --type=color' ' | |
930 | rm .git/config && | |
931 | git config --type=color foo.color "red" && | |
932 | test_cmp expect .git/config | |
933 | ' | |
934 | ||
935 | test_expect_success 'get --type=color barfs on non-color' ' | |
936 | echo "[foo]bar=not-a-color" >.git/config && | |
937 | test_must_fail git config --get --type=color foo.bar | |
938 | ' | |
939 | ||
940 | test_expect_success 'set --type=color barfs on non-color' ' | |
941 | test_must_fail git config --type=color foo.color "not-a-color" 2>error && | |
942 | test_i18ngrep "cannot parse color" error | |
943 | ' | |
944 | ||
cdd4fb15 BG |
945 | cat > expect << EOF |
946 | [quote] | |
947 | leading = " test" | |
948 | ending = "test " | |
949 | semicolon = "test;test" | |
950 | hash = "test#test" | |
951 | EOF | |
5a953fc5 | 952 | test_expect_success 'quoting' ' |
795290e5 | 953 | rm -f .git/config && |
5a953fc5 JK |
954 | git config quote.leading " test" && |
955 | git config quote.ending "test " && | |
956 | git config quote.semicolon "test;test" && | |
957 | git config quote.hash "test#test" && | |
958 | test_cmp expect .git/config | |
959 | ' | |
cdd4fb15 | 960 | |
41ac414e | 961 | test_expect_success 'key with newline' ' |
d492b31c | 962 | test_must_fail git config "key.with |
41ac414e | 963 | newline" 123' |
6f71686e | 964 | |
e0d10e1c | 965 | test_expect_success 'value with newline' 'git config key.sub value.with\\\ |
6f71686e JS |
966 | newline' |
967 | ||
83cd10a0 JN |
968 | cat > .git/config <<\EOF |
969 | [section] | |
970 | ; comment \ | |
971 | continued = cont\ | |
972 | inued | |
973 | noncont = not continued ; \ | |
974 | quotecont = "cont;\ | |
975 | inued" | |
976 | EOF | |
977 | ||
978 | cat > expect <<\EOF | |
979 | section.continued=continued | |
980 | section.noncont=not continued | |
981 | section.quotecont=cont;inued | |
982 | EOF | |
983 | ||
5a953fc5 JK |
984 | test_expect_success 'value continued on next line' ' |
985 | git config --list > result && | |
dcbaa0b3 | 986 | test_cmp expect result |
5a953fc5 | 987 | ' |
83cd10a0 | 988 | |
2275d502 FL |
989 | cat > .git/config <<\EOF |
990 | [section "sub=section"] | |
991 | val1 = foo=bar | |
992 | val2 = foo\nbar | |
993 | val3 = \n\n | |
994 | val4 = | |
995 | val5 | |
996 | EOF | |
997 | ||
998 | cat > expect <<\EOF | |
2b9a5020 AR |
999 | section.sub=section.val1 |
1000 | foo=barQsection.sub=section.val2 | |
1001 | foo | |
1002 | barQsection.sub=section.val3 | |
2275d502 FL |
1003 | |
1004 | ||
2b9a5020 AR |
1005 | Qsection.sub=section.val4 |
1006 | Qsection.sub=section.val5Q | |
2275d502 | 1007 | EOF |
5a953fc5 | 1008 | test_expect_success '--null --list' ' |
a0578e03 LS |
1009 | git config --null --list >result.raw && |
1010 | nul_to_q <result.raw >result && | |
5a953fc5 JK |
1011 | echo >>result && |
1012 | test_cmp expect result | |
1013 | ' | |
2275d502 | 1014 | |
5a953fc5 | 1015 | test_expect_success '--null --get-regexp' ' |
a0578e03 LS |
1016 | git config --null --get-regexp "val[0-9]" >result.raw && |
1017 | nul_to_q <result.raw >result && | |
5a953fc5 JK |
1018 | echo >>result && |
1019 | test_cmp expect result | |
1020 | ' | |
2275d502 | 1021 | |
ebdaae37 BS |
1022 | test_expect_success 'inner whitespace kept verbatim' ' |
1023 | git config section.val "foo bar" && | |
a5db0b77 | 1024 | test_cmp_config "foo bar" section.val |
ebdaae37 BS |
1025 | ' |
1026 | ||
704a3143 | 1027 | test_expect_success SYMLINKS 'symlinked configuration' ' |
65a5a21d | 1028 | ln -s notyet myconfig && |
f7e87141 | 1029 | git config --file=myconfig test.frotz nitfol && |
65a5a21d JH |
1030 | test -h myconfig && |
1031 | test -f notyet && | |
f7e87141 JK |
1032 | test "z$(git config --file=notyet test.frotz)" = znitfol && |
1033 | git config --file=myconfig test.xyzzy rezrov && | |
65a5a21d JH |
1034 | test -h myconfig && |
1035 | test -f notyet && | |
ed838e66 JK |
1036 | cat >expect <<-\EOF && |
1037 | nitfol | |
1038 | rezrov | |
1039 | EOF | |
1040 | { | |
f7e87141 JK |
1041 | git config --file=notyet test.frotz && |
1042 | git config --file=notyet test.xyzzy | |
ed838e66 JK |
1043 | } >actual && |
1044 | test_cmp expect actual | |
65a5a21d JH |
1045 | ' |
1046 | ||
1f2baa78 JK |
1047 | test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' |
1048 | ln -s doesnotexist linktonada && | |
1049 | ln -s linktonada linktolinktonada && | |
551a3e60 JK |
1050 | test_must_fail git config --file=linktonada --list && |
1051 | test_must_fail git config --file=linktolinktonada --list | |
1f2baa78 JK |
1052 | ' |
1053 | ||
dc4179f9 DM |
1054 | test_expect_success 'check split_cmdline return' " |
1055 | git config alias.split-cmdline-fix 'echo \"' && | |
1056 | test_must_fail git split-cmdline-fix && | |
1057 | echo foo > foo && | |
1058 | git add foo && | |
1059 | git commit -m 'initial commit' && | |
06d53148 JS |
1060 | git config branch.main.mergeoptions 'echo \"' && |
1061 | test_must_fail git merge main | |
ed838e66 | 1062 | " |
dc4179f9 | 1063 | |
8b1fa778 | 1064 | test_expect_success 'git -c "key=value" support' ' |
ed838e66 JK |
1065 | cat >expect <<-\EOF && |
1066 | value | |
1067 | value | |
1068 | true | |
1069 | EOF | |
1070 | { | |
04f6b0a1 | 1071 | git -c section.name=value config section.name && |
ed838e66 JK |
1072 | git -c foo.CamelCase=value config foo.camelcase && |
1073 | git -c foo.flag config --bool foo.flag | |
1074 | } >actual && | |
1075 | test_cmp expect actual && | |
04f6b0a1 | 1076 | test_must_fail git -c name=value config section.name |
b09c53a3 LP |
1077 | ' |
1078 | ||
a789ca70 JH |
1079 | # We just need a type-specifier here that cares about the |
1080 | # distinction internally between a NULL boolean and a real | |
1081 | # string (because most of git's internal parsers do care). | |
1082 | # Using "--path" works, but we do not otherwise care about | |
1083 | # its semantics. | |
1084 | test_expect_success 'git -c can represent empty string' ' | |
1085 | echo >expect && | |
1086 | git -c foo.empty= config --path foo.empty >actual && | |
1087 | test_cmp expect actual | |
1088 | ' | |
1089 | ||
b09c53a3 LP |
1090 | test_expect_success 'key sanity-checking' ' |
1091 | test_must_fail git config foo=bar && | |
1092 | test_must_fail git config foo=.bar && | |
1093 | test_must_fail git config foo.ba=r && | |
1094 | test_must_fail git config foo.1bar && | |
1095 | test_must_fail git config foo."ba | |
1096 | z".bar && | |
2169ddc0 LP |
1097 | test_must_fail git config . false && |
1098 | test_must_fail git config .foo false && | |
1099 | test_must_fail git config foo. false && | |
1100 | test_must_fail git config .foo. false && | |
b09c53a3 LP |
1101 | git config foo.bar true && |
1102 | git config foo."ba =z".bar false | |
8b1fa778 AR |
1103 | ' |
1104 | ||
73546c08 | 1105 | test_expect_success 'git -c works with aliases of builtins' ' |
06eb708f JK |
1106 | git config alias.checkconfig "-c foo.check=bar config foo.check" && |
1107 | echo bar >expect && | |
1108 | git checkconfig >actual && | |
1109 | test_cmp expect actual | |
1110 | ' | |
1111 | ||
643df7e2 | 1112 | test_expect_success 'aliases can be CamelCased' ' |
084b0440 JS |
1113 | test_config alias.CamelCased "rev-parse HEAD" && |
1114 | git CamelCased >out && | |
1115 | git rev-parse HEAD >expect && | |
1116 | test_cmp expect out | |
1117 | ' | |
1118 | ||
5bf6529a JK |
1119 | test_expect_success 'git -c does not split values on equals' ' |
1120 | echo "value with = in it" >expect && | |
04f6b0a1 | 1121 | git -c section.foo="value with = in it" config section.foo >actual && |
5bf6529a JK |
1122 | test_cmp expect actual |
1123 | ' | |
1124 | ||
1c2c9bee JK |
1125 | test_expect_success 'git -c dies on bogus config' ' |
1126 | test_must_fail git -c core.bare=foo rev-parse | |
1127 | ' | |
1128 | ||
1129 | test_expect_success 'git -c complains about empty key' ' | |
1130 | test_must_fail git -c "=foo" rev-parse | |
1131 | ' | |
1132 | ||
c5d6350b JK |
1133 | test_expect_success 'git -c complains about empty key and value' ' |
1134 | test_must_fail git -c "" rev-parse | |
1135 | ' | |
1136 | ||
d1f88498 JK |
1137 | test_expect_success 'multiple git -c appends config' ' |
1138 | test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" && | |
1139 | cat >expect <<-\EOF && | |
1140 | x.one 1 | |
1141 | x.two 2 | |
1142 | EOF | |
1143 | git -c x.one=1 x >actual && | |
1144 | test_cmp expect actual | |
1145 | ' | |
1146 | ||
1274a155 JH |
1147 | test_expect_success 'last one wins: two level vars' ' |
1148 | ||
1149 | # sec.var and sec.VAR are the same variable, as the first | |
1150 | # and the last level of a configuration variable name is | |
1151 | # case insensitive. | |
1152 | ||
1153 | echo VAL >expect && | |
1154 | ||
1155 | git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual && | |
1156 | test_cmp expect actual && | |
1157 | git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual && | |
1158 | test_cmp expect actual && | |
1159 | ||
1160 | git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual && | |
1161 | test_cmp expect actual && | |
1162 | git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual && | |
1163 | test_cmp expect actual | |
1164 | ' | |
1165 | ||
1166 | test_expect_success 'last one wins: three level vars' ' | |
1167 | ||
1168 | # v.a.r and v.A.r are not the same variable, as the middle | |
1169 | # level of a three-level configuration variable name is | |
1170 | # case sensitive. | |
1171 | ||
1172 | echo val >expect && | |
1173 | git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual && | |
1174 | test_cmp expect actual && | |
1175 | git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual && | |
1176 | test_cmp expect actual && | |
1177 | ||
1178 | # v.a.r and V.a.R are the same variable, as the first | |
1179 | # and the last level of a configuration variable name is | |
1180 | # case insensitive. | |
1181 | ||
1182 | echo VAL >expect && | |
1183 | git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual && | |
1184 | test_cmp expect actual && | |
1185 | git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual && | |
1186 | test_cmp expect actual && | |
1187 | git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual && | |
1188 | test_cmp expect actual && | |
1189 | git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual && | |
1190 | test_cmp expect actual | |
1191 | ' | |
1192 | ||
999d9026 SB |
1193 | test_expect_success 'old-fashioned settings are case insensitive' ' |
1194 | test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" && | |
1195 | ||
1196 | cat >testConfig_actual <<-EOF && | |
3de7ee36 MR |
1197 | [V.A] |
1198 | r = value1 | |
999d9026 SB |
1199 | EOF |
1200 | q_to_tab >testConfig_expect <<-EOF && | |
3de7ee36 MR |
1201 | [V.A] |
1202 | Qr = value2 | |
999d9026 SB |
1203 | EOF |
1204 | git config -f testConfig_actual "v.a.r" value2 && | |
1205 | test_cmp testConfig_expect testConfig_actual && | |
1206 | ||
1207 | cat >testConfig_actual <<-EOF && | |
3de7ee36 MR |
1208 | [V.A] |
1209 | r = value1 | |
999d9026 SB |
1210 | EOF |
1211 | q_to_tab >testConfig_expect <<-EOF && | |
3de7ee36 MR |
1212 | [V.A] |
1213 | QR = value2 | |
999d9026 SB |
1214 | EOF |
1215 | git config -f testConfig_actual "V.a.R" value2 && | |
1216 | test_cmp testConfig_expect testConfig_actual && | |
1217 | ||
1218 | cat >testConfig_actual <<-EOF && | |
3de7ee36 MR |
1219 | [V.A] |
1220 | r = value1 | |
999d9026 SB |
1221 | EOF |
1222 | q_to_tab >testConfig_expect <<-EOF && | |
3de7ee36 MR |
1223 | [V.A] |
1224 | r = value1 | |
1225 | Qr = value2 | |
999d9026 SB |
1226 | EOF |
1227 | git config -f testConfig_actual "V.A.r" value2 && | |
1228 | test_cmp testConfig_expect testConfig_actual && | |
1229 | ||
1230 | cat >testConfig_actual <<-EOF && | |
3de7ee36 MR |
1231 | [V.A] |
1232 | r = value1 | |
999d9026 SB |
1233 | EOF |
1234 | q_to_tab >testConfig_expect <<-EOF && | |
3de7ee36 MR |
1235 | [V.A] |
1236 | r = value1 | |
1237 | Qr = value2 | |
999d9026 SB |
1238 | EOF |
1239 | git config -f testConfig_actual "v.A.r" value2 && | |
1240 | test_cmp testConfig_expect testConfig_actual | |
1241 | ' | |
1242 | ||
1243 | test_expect_success 'setting different case sensitive subsections ' ' | |
1244 | test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" && | |
1245 | ||
1246 | cat >testConfig_actual <<-EOF && | |
3de7ee36 MR |
1247 | [V "A"] |
1248 | R = v1 | |
1249 | [K "E"] | |
1250 | Y = v1 | |
1251 | [a "b"] | |
1252 | c = v1 | |
1253 | [d "e"] | |
1254 | f = v1 | |
999d9026 SB |
1255 | EOF |
1256 | q_to_tab >testConfig_expect <<-EOF && | |
3de7ee36 MR |
1257 | [V "A"] |
1258 | Qr = v2 | |
1259 | [K "E"] | |
1260 | Qy = v2 | |
1261 | [a "b"] | |
1262 | Qc = v2 | |
1263 | [d "e"] | |
1264 | f = v1 | |
1265 | [d "E"] | |
1266 | Qf = v2 | |
999d9026 SB |
1267 | EOF |
1268 | # exact match | |
1269 | git config -f testConfig_actual a.b.c v2 && | |
1270 | # match section and subsection, key is cased differently. | |
1271 | git config -f testConfig_actual K.E.y v2 && | |
1272 | # section and key are matched case insensitive, but subsection needs | |
1273 | # to match; When writing out new values only the key is adjusted | |
1274 | git config -f testConfig_actual v.A.r v2 && | |
1275 | # subsection is not matched: | |
1276 | git config -f testConfig_actual d.E.f v2 && | |
1277 | test_cmp testConfig_expect testConfig_actual | |
1278 | ' | |
1279 | ||
1274a155 JH |
1280 | for VAR in a .a a. a.0b a."b c". a."b c".0d |
1281 | do | |
1282 | test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" ' | |
1283 | test_must_fail git -c "$VAR=VAL" config -l | |
1284 | ' | |
1285 | done | |
1286 | ||
1287 | for VAR in a.b a."b c".d | |
1288 | do | |
1289 | test_expect_success "git -c $VAR=VAL works with valid '$VAR'" ' | |
1290 | echo VAL >expect && | |
1291 | git -c "$VAR=VAL" config --get "$VAR" >actual && | |
1292 | test_cmp expect actual | |
1293 | ' | |
1294 | done | |
1295 | ||
d1f88498 JK |
1296 | test_expect_success 'git -c is not confused by empty environment' ' |
1297 | GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list | |
1298 | ' | |
1299 | ||
f9dbb64f JK |
1300 | test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' ' |
1301 | v="${SQ}key.one=foo${SQ}" && | |
1302 | v="$v ${SQ}key.two=bar${SQ}" && | |
1303 | v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" && | |
1304 | GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && | |
1305 | cat >expect <<-EOF && | |
1306 | key.one foo | |
1307 | key.two bar | |
1308 | key.ambiguous section.whatever=value | |
1309 | EOF | |
1310 | test_cmp expect actual | |
1311 | ' | |
1312 | ||
1313 | test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' ' | |
1314 | v="${SQ}key.one${SQ}=${SQ}foo${SQ}" && | |
1315 | v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" && | |
1316 | v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" && | |
1317 | GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && | |
1318 | cat >expect <<-EOF && | |
1319 | key.one foo | |
1320 | key.two bar | |
1321 | key.ambiguous=section.whatever value | |
1322 | EOF | |
1323 | test_cmp expect actual | |
1324 | ' | |
1325 | ||
1326 | test_expect_success 'old and new-style entries can mix' ' | |
1327 | v="${SQ}key.oldone=oldfoo${SQ}" && | |
1328 | v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" && | |
1329 | v="$v ${SQ}key.oldtwo=oldbar${SQ}" && | |
1330 | v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" && | |
1331 | GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && | |
1332 | cat >expect <<-EOF && | |
1333 | key.oldone oldfoo | |
1334 | key.newone newfoo | |
1335 | key.oldtwo oldbar | |
1336 | key.newtwo newbar | |
1337 | EOF | |
1338 | test_cmp expect actual | |
1339 | ' | |
1340 | ||
1341 | test_expect_success 'old and new bools with ambiguous subsection' ' | |
1342 | v="${SQ}key.with=equals.oldbool${SQ}" && | |
1343 | v="$v ${SQ}key.with=equals.newbool${SQ}=" && | |
1344 | GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && | |
1345 | cat >expect <<-EOF && | |
1346 | key.with equals.oldbool | |
1347 | key.with=equals.newbool | |
1348 | EOF | |
1349 | test_cmp expect actual | |
1350 | ' | |
1351 | ||
ddbbf8eb JK |
1352 | test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' ' |
1353 | cat >expect <<-\EOF && | |
1354 | env.one one | |
1355 | env.two two | |
1356 | EOF | |
bd482d6e | 1357 | GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \ |
ddbbf8eb JK |
1358 | git config --get-regexp "env.*" >actual && |
1359 | test_cmp expect actual && | |
1360 | ||
1361 | cat >expect <<-EOF && | |
bd482d6e | 1362 | env.one one${SQ} |
ddbbf8eb JK |
1363 | env.two two |
1364 | EOF | |
bd482d6e | 1365 | GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \ |
ddbbf8eb JK |
1366 | git config --get-regexp "env.*" >actual && |
1367 | test_cmp expect actual && | |
1368 | ||
1369 | test_must_fail env \ | |
bd482d6e | 1370 | GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \ |
ddbbf8eb JK |
1371 | git config --get-regexp "env.*" |
1372 | ' | |
1373 | ||
ce81b1da PS |
1374 | test_expect_success 'git --config-env=key=envvar support' ' |
1375 | cat >expect <<-\EOF && | |
1376 | value | |
1377 | value | |
c331551c PS |
1378 | value |
1379 | value | |
1380 | false | |
ce81b1da PS |
1381 | false |
1382 | EOF | |
1383 | { | |
1384 | ENVVAR=value git --config-env=core.name=ENVVAR config core.name && | |
c331551c | 1385 | ENVVAR=value git --config-env core.name=ENVVAR config core.name && |
ce81b1da | 1386 | ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase && |
c331551c PS |
1387 | ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase && |
1388 | ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag && | |
1389 | ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag | |
ce81b1da PS |
1390 | } >actual && |
1391 | test_cmp expect actual | |
1392 | ' | |
1393 | ||
c331551c PS |
1394 | test_expect_success 'git --config-env with missing value' ' |
1395 | test_must_fail env ENVVAR=value git --config-env 2>error && | |
1396 | grep "no config key given for --config-env" error && | |
1397 | test_must_fail env ENVVAR=value git --config-env config core.name 2>error && | |
1398 | grep "invalid config format: config" error | |
1399 | ' | |
1400 | ||
ce81b1da PS |
1401 | test_expect_success 'git --config-env fails with invalid parameters' ' |
1402 | test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error && | |
1403 | test_i18ngrep "invalid config format: foo.flag" error && | |
1404 | test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error && | |
1405 | test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error && | |
1406 | sane_unset NONEXISTENT && | |
1407 | test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error && | |
1408 | test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error | |
1409 | ' | |
1410 | ||
1411 | test_expect_success 'git -c and --config-env work together' ' | |
1412 | cat >expect <<-\EOF && | |
1413 | bar.cmd cmd-value | |
1414 | bar.env env-value | |
1415 | EOF | |
1416 | ENVVAR=env-value git \ | |
1417 | -c bar.cmd=cmd-value \ | |
1418 | --config-env=bar.env=ENVVAR \ | |
1419 | config --get-regexp "^bar.*" >actual && | |
1420 | test_cmp expect actual | |
1421 | ' | |
1422 | ||
1423 | test_expect_success 'git -c and --config-env override each other' ' | |
1424 | cat >expect <<-\EOF && | |
1425 | env | |
1426 | cmd | |
1427 | EOF | |
1428 | { | |
1429 | ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar && | |
1430 | ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar | |
1431 | } >actual && | |
1432 | test_cmp expect actual | |
1433 | ' | |
1434 | ||
1ff21c05 PS |
1435 | test_expect_success '--config-env handles keys with equals' ' |
1436 | echo value=with=equals >expect && | |
1437 | ENVVAR=value=with=equals git \ | |
1438 | --config-env=section.subsection=with=equals.key=ENVVAR \ | |
1439 | config section.subsection=with=equals.key >actual && | |
1440 | test_cmp expect actual | |
1441 | ' | |
1442 | ||
d8d77153 PS |
1443 | test_expect_success 'git config handles environment config pairs' ' |
1444 | GIT_CONFIG_COUNT=2 \ | |
1445 | GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \ | |
1446 | GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \ | |
1447 | git config --get-regexp "pair.*" >actual && | |
1448 | cat >expect <<-EOF && | |
1449 | pair.one foo | |
1450 | pair.two bar | |
1451 | EOF | |
1452 | test_cmp expect actual | |
1453 | ' | |
1454 | ||
1455 | test_expect_success 'git config ignores pairs without count' ' | |
1456 | test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ | |
1457 | git config pair.one 2>error && | |
1458 | test_must_be_empty error | |
1459 | ' | |
1460 | ||
1461 | test_expect_success 'git config ignores pairs with zero count' ' | |
1462 | test_must_fail env \ | |
1463 | GIT_CONFIG_COUNT=0 \ | |
1464 | GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ | |
1465 | git config pair.one | |
1466 | ' | |
1467 | ||
1468 | test_expect_success 'git config ignores pairs exceeding count' ' | |
1469 | GIT_CONFIG_COUNT=1 \ | |
1470 | GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ | |
1471 | GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \ | |
1472 | git config --get-regexp "pair.*" >actual && | |
1473 | cat >expect <<-EOF && | |
1474 | pair.one value | |
1475 | EOF | |
1476 | test_cmp expect actual | |
1477 | ' | |
1478 | ||
1479 | test_expect_success 'git config ignores pairs with zero count' ' | |
1480 | test_must_fail env \ | |
1481 | GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ | |
1482 | git config pair.one >error && | |
1483 | test_must_be_empty error | |
1484 | ' | |
1485 | ||
1486 | test_expect_success 'git config ignores pairs with empty count' ' | |
1487 | test_must_fail env \ | |
1488 | GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ | |
1489 | git config pair.one >error && | |
1490 | test_must_be_empty error | |
1491 | ' | |
1492 | ||
1493 | test_expect_success 'git config fails with invalid count' ' | |
1494 | test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error && | |
1495 | test_i18ngrep "bogus count" error && | |
1496 | test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error && | |
1497 | test_i18ngrep "too many entries" error | |
1498 | ' | |
1499 | ||
1500 | test_expect_success 'git config fails with missing config key' ' | |
1501 | test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \ | |
1502 | git config --list 2>error && | |
1503 | test_i18ngrep "missing config key" error | |
1504 | ' | |
1505 | ||
1506 | test_expect_success 'git config fails with missing config value' ' | |
1507 | test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \ | |
1508 | git config --list 2>error && | |
1509 | test_i18ngrep "missing config value" error | |
1510 | ' | |
1511 | ||
1512 | test_expect_success 'git config fails with invalid config pair key' ' | |
1513 | test_must_fail env GIT_CONFIG_COUNT=1 \ | |
1514 | GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \ | |
1515 | git config --list && | |
1516 | test_must_fail env GIT_CONFIG_COUNT=1 \ | |
1517 | GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \ | |
1518 | git config --list | |
1519 | ' | |
1520 | ||
1521 | test_expect_success 'environment overrides config file' ' | |
1522 | test_when_finished "rm -f .git/config" && | |
1523 | cat >.git/config <<-EOF && | |
1524 | [pair] | |
1525 | one = value | |
1526 | EOF | |
1527 | GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \ | |
1528 | git config pair.one >actual && | |
1529 | cat >expect <<-EOF && | |
1530 | override | |
1531 | EOF | |
1532 | test_cmp expect actual | |
1533 | ' | |
1534 | ||
1535 | test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' ' | |
1536 | GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \ | |
1537 | GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \ | |
1538 | git config pair.one >actual && | |
1539 | cat >expect <<-EOF && | |
1540 | override | |
1541 | EOF | |
1542 | test_cmp expect actual | |
1543 | ' | |
1544 | ||
1545 | test_expect_success 'command line overrides environment config' ' | |
1546 | GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \ | |
1547 | git -c pair.one=override config pair.one >actual && | |
1548 | cat >expect <<-EOF && | |
1549 | override | |
1550 | EOF | |
1551 | test_cmp expect actual | |
1552 | ' | |
1553 | ||
270a3443 JK |
1554 | test_expect_success 'git config --edit works' ' |
1555 | git config -f tmp test.value no && | |
1556 | echo test.value=yes >expect && | |
1557 | GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit && | |
1558 | git config -f tmp --list >actual && | |
1559 | test_cmp expect actual | |
1560 | ' | |
1561 | ||
1562 | test_expect_success 'git config --edit respects core.editor' ' | |
1563 | git config -f tmp test.value no && | |
1564 | echo test.value=yes >expect && | |
1565 | test_config core.editor "echo [test]value=yes >" && | |
1566 | git config -f tmp --edit && | |
1567 | git config -f tmp --list >actual && | |
1568 | test_cmp expect actual | |
1569 | ' | |
1570 | ||
4b340593 MS |
1571 | # malformed configuration files |
1572 | test_expect_success 'barf on syntax error' ' | |
1573 | cat >.git/config <<-\EOF && | |
1574 | # broken section line | |
1575 | [section] | |
1576 | key garbage | |
1577 | EOF | |
1578 | test_must_fail git config --get section.key >actual 2>error && | |
1edbaac3 | 1579 | test_i18ngrep " line 3 " error |
4b340593 MS |
1580 | ' |
1581 | ||
1582 | test_expect_success 'barf on incomplete section header' ' | |
1583 | cat >.git/config <<-\EOF && | |
1584 | # broken section line | |
1585 | [section | |
1586 | key = value | |
1587 | EOF | |
1588 | test_must_fail git config --get section.key >actual 2>error && | |
1edbaac3 | 1589 | test_i18ngrep " line 2 " error |
4b340593 MS |
1590 | ' |
1591 | ||
1592 | test_expect_success 'barf on incomplete string' ' | |
1593 | cat >.git/config <<-\EOF && | |
1594 | # broken section line | |
1595 | [section] | |
1596 | key = "value string | |
1597 | EOF | |
1598 | test_must_fail git config --get section.key >actual 2>error && | |
1edbaac3 | 1599 | test_i18ngrep " line 3 " error |
4b340593 MS |
1600 | ' |
1601 | ||
d4770964 JH |
1602 | test_expect_success 'urlmatch' ' |
1603 | cat >.git/config <<-\EOF && | |
1604 | [http] | |
1605 | sslVerify | |
1606 | [http "https://weak.example.com"] | |
1607 | sslVerify = false | |
1608 | cookieFile = /tmp/cookie.txt | |
1609 | EOF | |
1610 | ||
27b30be6 JK |
1611 | test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual && |
1612 | test_must_be_empty actual && | |
1613 | ||
d4770964 JH |
1614 | echo true >expect && |
1615 | git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual && | |
1616 | test_cmp expect actual && | |
1617 | ||
1618 | echo false >expect && | |
1619 | git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual && | |
1620 | test_cmp expect actual && | |
1621 | ||
1622 | { | |
1623 | echo http.cookiefile /tmp/cookie.txt && | |
1624 | echo http.sslverify false | |
1625 | } >expect && | |
1626 | git config --get-urlmatch HTTP https://weak.example.com >actual && | |
1627 | test_cmp expect actual | |
1628 | ' | |
1629 | ||
af99049c PS |
1630 | test_expect_success 'urlmatch favors more specific URLs' ' |
1631 | cat >.git/config <<-\EOF && | |
1632 | [http "https://example.com/"] | |
1633 | cookieFile = /tmp/root.txt | |
1634 | [http "https://example.com/subdirectory"] | |
1635 | cookieFile = /tmp/subdirectory.txt | |
1636 | [http "https://user@example.com/"] | |
1637 | cookieFile = /tmp/user.txt | |
1638 | [http "https://averylonguser@example.com/"] | |
1639 | cookieFile = /tmp/averylonguser.txt | |
a272b9e7 PS |
1640 | [http "https://preceding.example.com"] |
1641 | cookieFile = /tmp/preceding.txt | |
1642 | [http "https://*.example.com"] | |
1643 | cookieFile = /tmp/wildcard.txt | |
1644 | [http "https://*.example.com/wildcardwithsubdomain"] | |
1645 | cookieFile = /tmp/wildcardwithsubdomain.txt | |
732f9344 | 1646 | [http "https://*.example.*"] |
1647 | cookieFile = /tmp/multiwildcard.txt | |
a272b9e7 PS |
1648 | [http "https://trailing.example.com"] |
1649 | cookieFile = /tmp/trailing.txt | |
1650 | [http "https://user@*.example.com/"] | |
1651 | cookieFile = /tmp/wildcardwithuser.txt | |
1652 | [http "https://sub.example.com/"] | |
1653 | cookieFile = /tmp/sub.txt | |
af99049c PS |
1654 | EOF |
1655 | ||
1656 | echo http.cookiefile /tmp/root.txt >expect && | |
1657 | git config --get-urlmatch HTTP https://example.com >actual && | |
1658 | test_cmp expect actual && | |
1659 | ||
1660 | echo http.cookiefile /tmp/subdirectory.txt >expect && | |
1661 | git config --get-urlmatch HTTP https://example.com/subdirectory >actual && | |
1662 | test_cmp expect actual && | |
1663 | ||
1664 | echo http.cookiefile /tmp/subdirectory.txt >expect && | |
1665 | git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual && | |
1666 | test_cmp expect actual && | |
1667 | ||
1668 | echo http.cookiefile /tmp/user.txt >expect && | |
1669 | git config --get-urlmatch HTTP https://user@example.com/ >actual && | |
1670 | test_cmp expect actual && | |
1671 | ||
1672 | echo http.cookiefile /tmp/subdirectory.txt >expect && | |
1673 | git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual && | |
a272b9e7 PS |
1674 | test_cmp expect actual && |
1675 | ||
1676 | echo http.cookiefile /tmp/preceding.txt >expect && | |
1677 | git config --get-urlmatch HTTP https://preceding.example.com >actual && | |
1678 | test_cmp expect actual && | |
1679 | ||
1680 | echo http.cookiefile /tmp/wildcard.txt >expect && | |
1681 | git config --get-urlmatch HTTP https://wildcard.example.com >actual && | |
1682 | test_cmp expect actual && | |
1683 | ||
1684 | echo http.cookiefile /tmp/sub.txt >expect && | |
1685 | git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual && | |
1686 | test_cmp expect actual && | |
1687 | ||
1688 | echo http.cookiefile /tmp/trailing.txt >expect && | |
1689 | git config --get-urlmatch HTTP https://trailing.example.com >actual && | |
1690 | test_cmp expect actual && | |
1691 | ||
1692 | echo http.cookiefile /tmp/sub.txt >expect && | |
1693 | git config --get-urlmatch HTTP https://user@sub.example.com >actual && | |
732f9344 | 1694 | test_cmp expect actual && |
1695 | ||
1696 | echo http.cookiefile /tmp/multiwildcard.txt >expect && | |
1697 | git config --get-urlmatch HTTP https://wildcard.example.org >actual && | |
a272b9e7 PS |
1698 | test_cmp expect actual |
1699 | ' | |
1700 | ||
1701 | test_expect_success 'urlmatch with wildcard' ' | |
1702 | cat >.git/config <<-\EOF && | |
1703 | [http] | |
1704 | sslVerify | |
1705 | [http "https://*.example.com"] | |
1706 | sslVerify = false | |
1707 | cookieFile = /tmp/cookie.txt | |
1708 | EOF | |
1709 | ||
1710 | test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual && | |
1711 | test_must_be_empty actual && | |
1712 | ||
1713 | echo true >expect && | |
1714 | git config --bool --get-urlmatch http.SSLverify https://example.com >actual && | |
1715 | test_cmp expect actual && | |
1716 | ||
1717 | echo true >expect && | |
1718 | git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual && | |
1719 | test_cmp expect actual && | |
1720 | ||
1721 | echo true >expect && | |
1722 | git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual && | |
1723 | test_cmp expect actual && | |
1724 | ||
1725 | echo false >expect && | |
1726 | git config --bool --get-urlmatch http.sslverify https://good.example.com >actual && | |
1727 | test_cmp expect actual && | |
1728 | ||
1729 | { | |
1730 | echo http.cookiefile /tmp/cookie.txt && | |
1731 | echo http.sslverify false | |
1732 | } >expect && | |
1733 | git config --get-urlmatch HTTP https://good.example.com >actual && | |
1734 | test_cmp expect actual && | |
1735 | ||
1736 | echo http.sslverify >expect && | |
1737 | git config --get-urlmatch HTTP https://more.example.com.au >actual && | |
af99049c PS |
1738 | test_cmp expect actual |
1739 | ' | |
1740 | ||
53ca053b | 1741 | # good section hygiene |
22aedfcc | 1742 | test_expect_success '--unset last key removes section (except if commented)' ' |
53ca053b JK |
1743 | cat >.git/config <<-\EOF && |
1744 | # some generic comment on the configuration file itself | |
1745 | # a comment specific to this "section" section. | |
1746 | [section] | |
1747 | # some intervening lines | |
1748 | # that should also be dropped | |
1749 | ||
1750 | key = value | |
1751 | # please be careful when you update the above variable | |
1752 | EOF | |
1753 | ||
1754 | cat >expect <<-\EOF && | |
1755 | # some generic comment on the configuration file itself | |
dde154b5 JS |
1756 | # a comment specific to this "section" section. |
1757 | [section] | |
1758 | # some intervening lines | |
1759 | # that should also be dropped | |
1760 | ||
1761 | # please be careful when you update the above variable | |
53ca053b JK |
1762 | EOF |
1763 | ||
1764 | git config --unset section.key && | |
dde154b5 JS |
1765 | test_cmp expect .git/config && |
1766 | ||
1767 | cat >.git/config <<-\EOF && | |
1768 | [section] | |
1769 | key = value | |
1770 | [next-section] | |
1771 | EOF | |
1772 | ||
1773 | cat >expect <<-\EOF && | |
1774 | [next-section] | |
53ca053b JK |
1775 | EOF |
1776 | ||
1777 | git config --unset section.key && | |
422e8ef2 JS |
1778 | test_cmp expect .git/config && |
1779 | ||
1780 | q_to_tab >.git/config <<-\EOF && | |
1781 | [one] | |
1782 | Qkey = "multiline \ | |
1783 | QQ# with comment" | |
1784 | [two] | |
1785 | key = true | |
1786 | EOF | |
1787 | git config --unset two.key && | |
1788 | ! grep two .git/config && | |
1789 | ||
1790 | q_to_tab >.git/config <<-\EOF && | |
1791 | [one] | |
1792 | Qkey = "multiline \ | |
1793 | QQ# with comment" | |
1794 | [one] | |
1795 | key = true | |
1796 | EOF | |
1797 | git config --unset-all one.key && | |
1798 | test_line_count = 0 .git/config && | |
1799 | ||
1800 | q_to_tab >.git/config <<-\EOF && | |
1801 | [one] | |
1802 | Qkey = true | |
1803 | Q# a comment not at the start | |
1804 | [two] | |
1805 | Qkey = true | |
1806 | EOF | |
1807 | git config --unset two.key && | |
1808 | grep two .git/config && | |
1809 | ||
1810 | q_to_tab >.git/config <<-\EOF && | |
1811 | [one] | |
1812 | Qkey = not [two "subsection"] | |
1813 | [two "subsection"] | |
1814 | [two "subsection"] | |
1815 | Qkey = true | |
1816 | [TWO "subsection"] | |
1817 | [one] | |
1818 | EOF | |
1819 | git config --unset two.subsection.key && | |
1820 | test "not [two subsection]" = "$(git config one.key)" && | |
1821 | test_line_count = 3 .git/config | |
53ca053b JK |
1822 | ' |
1823 | ||
22aedfcc | 1824 | test_expect_success '--unset-all removes section if empty & uncommented' ' |
b73bdc34 JS |
1825 | cat >.git/config <<-\EOF && |
1826 | [section] | |
1827 | key = value1 | |
1828 | key = value2 | |
1829 | EOF | |
1830 | ||
1831 | git config --unset-all section.key && | |
1832 | test_line_count = 0 .git/config | |
53ca053b JK |
1833 | ' |
1834 | ||
c71d8bb3 | 1835 | test_expect_success 'adding a key into an empty section reuses header' ' |
53ca053b JK |
1836 | cat >.git/config <<-\EOF && |
1837 | [section] | |
1838 | EOF | |
1839 | ||
1840 | q_to_tab >expect <<-\EOF && | |
1841 | [section] | |
1842 | Qkey = value | |
1843 | EOF | |
1844 | ||
60687de5 | 1845 | git config section.key value && |
53ca053b JK |
1846 | test_cmp expect .git/config |
1847 | ' | |
1848 | ||
daa22c6f EW |
1849 | test_expect_success POSIXPERM,PERL 'preserves existing permissions' ' |
1850 | chmod 0600 .git/config && | |
1851 | git config imap.pass Hunter2 && | |
1852 | perl -e \ | |
1853 | "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" && | |
1854 | git config --rename-section imap pop && | |
1855 | perl -e \ | |
1856 | "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600" | |
1857 | ' | |
1858 | ||
45bf3297 JS |
1859 | ! test_have_prereq MINGW || |
1860 | HOME="$(pwd)" # convert to Windows path | |
1861 | ||
70bd879a LS |
1862 | test_expect_success 'set up --show-origin tests' ' |
1863 | INCLUDE_DIR="$HOME/include" && | |
1864 | mkdir -p "$INCLUDE_DIR" && | |
1865 | cat >"$INCLUDE_DIR"/absolute.include <<-\EOF && | |
3de7ee36 MR |
1866 | [user] |
1867 | absolute = include | |
70bd879a LS |
1868 | EOF |
1869 | cat >"$INCLUDE_DIR"/relative.include <<-\EOF && | |
3de7ee36 MR |
1870 | [user] |
1871 | relative = include | |
70bd879a LS |
1872 | EOF |
1873 | cat >"$HOME"/.gitconfig <<-EOF && | |
3de7ee36 MR |
1874 | [user] |
1875 | global = true | |
1876 | override = global | |
1877 | [include] | |
1878 | path = "$INCLUDE_DIR/absolute.include" | |
70bd879a LS |
1879 | EOF |
1880 | cat >.git/config <<-\EOF | |
3de7ee36 MR |
1881 | [user] |
1882 | local = true | |
1883 | override = local | |
1884 | [include] | |
1885 | path = ../include/relative.include | |
70bd879a LS |
1886 | EOF |
1887 | ' | |
1888 | ||
1889 | test_expect_success '--show-origin with --list' ' | |
1890 | cat >expect <<-EOF && | |
3de7ee36 MR |
1891 | file:$HOME/.gitconfig user.global=true |
1892 | file:$HOME/.gitconfig user.override=global | |
1893 | file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include | |
1894 | file:$INCLUDE_DIR/absolute.include user.absolute=include | |
1895 | file:.git/config user.local=true | |
1896 | file:.git/config user.override=local | |
1897 | file:.git/config include.path=../include/relative.include | |
1898 | file:.git/../include/relative.include user.relative=include | |
d8d77153 | 1899 | command line: user.environ=true |
3de7ee36 | 1900 | command line: user.cmdline=true |
70bd879a | 1901 | EOF |
d8d77153 PS |
1902 | GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\ |
1903 | git -c user.cmdline=true config --list --show-origin >output && | |
70bd879a LS |
1904 | test_cmp expect output |
1905 | ' | |
1906 | ||
1907 | test_expect_success '--show-origin with --list --null' ' | |
1908 | cat >expect <<-EOF && | |
3de7ee36 MR |
1909 | file:$HOME/.gitconfigQuser.global |
1910 | trueQfile:$HOME/.gitconfigQuser.override | |
1911 | globalQfile:$HOME/.gitconfigQinclude.path | |
1912 | $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute | |
1913 | includeQfile:.git/configQuser.local | |
1914 | trueQfile:.git/configQuser.override | |
1915 | localQfile:.git/configQinclude.path | |
1916 | ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative | |
1917 | includeQcommand line:Quser.cmdline | |
1918 | trueQ | |
70bd879a LS |
1919 | EOF |
1920 | git -c user.cmdline=true config --null --list --show-origin >output.raw && | |
1921 | nul_to_q <output.raw >output && | |
1922 | # The here-doc above adds a newline that the --null output would not | |
1923 | # include. Add it here to make the two comparable. | |
1924 | echo >>output && | |
1925 | test_cmp expect output | |
1926 | ' | |
1927 | ||
1928 | test_expect_success '--show-origin with single file' ' | |
1929 | cat >expect <<-\EOF && | |
3de7ee36 MR |
1930 | file:.git/config user.local=true |
1931 | file:.git/config user.override=local | |
1932 | file:.git/config include.path=../include/relative.include | |
70bd879a LS |
1933 | EOF |
1934 | git config --local --list --show-origin >output && | |
1935 | test_cmp expect output | |
1936 | ' | |
1937 | ||
1938 | test_expect_success '--show-origin with --get-regexp' ' | |
1939 | cat >expect <<-EOF && | |
3de7ee36 MR |
1940 | file:$HOME/.gitconfig user.global true |
1941 | file:.git/config user.local true | |
70bd879a LS |
1942 | EOF |
1943 | git config --show-origin --get-regexp "user\.[g|l].*" >output && | |
1944 | test_cmp expect output | |
1945 | ' | |
1946 | ||
1947 | test_expect_success '--show-origin getting a single key' ' | |
1948 | cat >expect <<-\EOF && | |
3de7ee36 | 1949 | file:.git/config local |
70bd879a LS |
1950 | EOF |
1951 | git config --show-origin user.override >output && | |
1952 | test_cmp expect output | |
1953 | ' | |
1954 | ||
1955 | test_expect_success 'set up custom config file' ' | |
417be08d | 1956 | CUSTOM_CONFIG_FILE="custom.conf" && |
70bd879a | 1957 | cat >"$CUSTOM_CONFIG_FILE" <<-\EOF |
3de7ee36 MR |
1958 | [user] |
1959 | custom = true | |
70bd879a LS |
1960 | EOF |
1961 | ' | |
1962 | ||
417be08d MR |
1963 | test_expect_success !MINGW 'set up custom config file with special name characters' ' |
1964 | WEIRDLY_NAMED_FILE="file\" (dq) and spaces.conf" && | |
1965 | cp "$CUSTOM_CONFIG_FILE" "$WEIRDLY_NAMED_FILE" | |
1966 | ' | |
1967 | ||
45bf3297 | 1968 | test_expect_success !MINGW '--show-origin escape special file name characters' ' |
70bd879a | 1969 | cat >expect <<-\EOF && |
3de7ee36 | 1970 | file:"file\" (dq) and spaces.conf" user.custom=true |
70bd879a | 1971 | EOF |
417be08d | 1972 | git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output && |
70bd879a LS |
1973 | test_cmp expect output |
1974 | ' | |
1975 | ||
1976 | test_expect_success '--show-origin stdin' ' | |
1977 | cat >expect <<-\EOF && | |
3de7ee36 | 1978 | standard input: user.custom=true |
70bd879a LS |
1979 | EOF |
1980 | git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output && | |
1981 | test_cmp expect output | |
1982 | ' | |
1983 | ||
1984 | test_expect_success '--show-origin stdin with file include' ' | |
1985 | cat >"$INCLUDE_DIR"/stdin.include <<-EOF && | |
3de7ee36 MR |
1986 | [user] |
1987 | stdin = include | |
70bd879a LS |
1988 | EOF |
1989 | cat >expect <<-EOF && | |
3de7ee36 | 1990 | file:$INCLUDE_DIR/stdin.include include |
70bd879a | 1991 | EOF |
bdbc17e8 MD |
1992 | echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" | |
1993 | git config --show-origin --includes --file - user.stdin >output && | |
1994 | ||
70bd879a LS |
1995 | test_cmp expect output |
1996 | ' | |
1997 | ||
417be08d | 1998 | test_expect_success '--show-origin blob' ' |
70bd879a | 1999 | blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") && |
0dc3ad99 | 2000 | cat >expect <<-EOF && |
3de7ee36 | 2001 | blob:$blob user.custom=true |
0dc3ad99 | 2002 | EOF |
70bd879a LS |
2003 | git config --blob=$blob --show-origin --list >output && |
2004 | test_cmp expect output | |
2005 | ' | |
2006 | ||
417be08d | 2007 | test_expect_success '--show-origin blob ref' ' |
70bd879a | 2008 | cat >expect <<-\EOF && |
06d53148 | 2009 | blob:main:custom.conf user.custom=true |
70bd879a LS |
2010 | EOF |
2011 | git add "$CUSTOM_CONFIG_FILE" && | |
2012 | git commit -m "new config file" && | |
06d53148 | 2013 | git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output && |
70bd879a LS |
2014 | test_cmp expect output |
2015 | ' | |
2016 | ||
145d59f4 MR |
2017 | test_expect_success '--show-scope with --list' ' |
2018 | cat >expect <<-EOF && | |
2019 | global user.global=true | |
2020 | global user.override=global | |
2021 | global include.path=$INCLUDE_DIR/absolute.include | |
2022 | global user.absolute=include | |
2023 | local user.local=true | |
2024 | local user.override=local | |
2025 | local include.path=../include/relative.include | |
2026 | local user.relative=include | |
db7961e6 GC |
2027 | local core.repositoryformatversion=1 |
2028 | local extensions.worktreeconfig=true | |
2029 | worktree user.worktree=true | |
145d59f4 MR |
2030 | command user.cmdline=true |
2031 | EOF | |
db7961e6 GC |
2032 | git worktree add wt1 && |
2033 | # We need these to test for worktree scope, but outside of this | |
2034 | # test, this is just noise | |
2035 | test_config core.repositoryformatversion 1 && | |
2036 | test_config extensions.worktreeConfig true && | |
2037 | git config --worktree user.worktree true && | |
145d59f4 MR |
2038 | git -c user.cmdline=true config --list --show-scope >output && |
2039 | test_cmp expect output | |
2040 | ' | |
2041 | ||
2042 | test_expect_success !MINGW '--show-scope with --blob' ' | |
2043 | blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") && | |
2044 | cat >expect <<-EOF && | |
2045 | command user.custom=true | |
2046 | EOF | |
2047 | git config --blob=$blob --show-scope --list >output && | |
2048 | test_cmp expect output | |
2049 | ' | |
2050 | ||
2051 | test_expect_success '--show-scope with --local' ' | |
2052 | cat >expect <<-\EOF && | |
2053 | local user.local=true | |
2054 | local user.override=local | |
2055 | local include.path=../include/relative.include | |
2056 | EOF | |
2057 | git config --local --list --show-scope >output && | |
2058 | test_cmp expect output | |
2059 | ' | |
2060 | ||
2061 | test_expect_success '--show-scope getting a single value' ' | |
2062 | cat >expect <<-\EOF && | |
2063 | local true | |
2064 | EOF | |
2065 | git config --show-scope --get user.local >output && | |
2066 | test_cmp expect output | |
2067 | ' | |
2068 | ||
2069 | test_expect_success '--show-scope with --show-origin' ' | |
2070 | cat >expect <<-EOF && | |
2071 | global file:$HOME/.gitconfig user.global=true | |
2072 | global file:$HOME/.gitconfig user.override=global | |
2073 | global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include | |
2074 | global file:$INCLUDE_DIR/absolute.include user.absolute=include | |
2075 | local file:.git/config user.local=true | |
2076 | local file:.git/config user.override=local | |
2077 | local file:.git/config include.path=../include/relative.include | |
2078 | local file:.git/../include/relative.include user.relative=include | |
2079 | command command line: user.cmdline=true | |
2080 | EOF | |
2081 | git -c user.cmdline=true config --list --show-origin --show-scope >output && | |
2082 | test_cmp expect output | |
2083 | ' | |
2084 | ||
4179b489 | 2085 | test_expect_success 'override global and system config' ' |
eb1cd602 | 2086 | test_when_finished rm -f \"\$HOME\"/.gitconfig && |
4179b489 PS |
2087 | cat >"$HOME"/.gitconfig <<-EOF && |
2088 | [home] | |
2089 | config = true | |
2090 | EOF | |
eb1cd602 ÆAB |
2091 | |
2092 | test_when_finished rm -rf \"\$HOME\"/.config/git && | |
4179b489 PS |
2093 | mkdir -p "$HOME"/.config/git && |
2094 | cat >"$HOME"/.config/git/config <<-EOF && | |
2095 | [xdg] | |
2096 | config = true | |
2097 | EOF | |
2098 | cat >.git/config <<-EOF && | |
2099 | [local] | |
2100 | config = true | |
2101 | EOF | |
2102 | cat >custom-global-config <<-EOF && | |
2103 | [global] | |
2104 | config = true | |
2105 | EOF | |
2106 | cat >custom-system-config <<-EOF && | |
2107 | [system] | |
2108 | config = true | |
2109 | EOF | |
2110 | ||
2111 | cat >expect <<-EOF && | |
2112 | global xdg.config=true | |
2113 | global home.config=true | |
2114 | local local.config=true | |
2115 | EOF | |
2116 | git config --show-scope --list >output && | |
2117 | test_cmp expect output && | |
2118 | ||
4179b489 PS |
2119 | cat >expect <<-EOF && |
2120 | system system.config=true | |
2121 | global global.config=true | |
2122 | local local.config=true | |
2123 | EOF | |
482d5499 | 2124 | GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \ |
4179b489 PS |
2125 | git config --show-scope --list >output && |
2126 | test_cmp expect output && | |
2127 | ||
2128 | cat >expect <<-EOF && | |
2129 | local local.config=true | |
2130 | EOF | |
482d5499 PS |
2131 | GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \ |
2132 | git config --show-scope --list >output && | |
4179b489 PS |
2133 | test_cmp expect output |
2134 | ' | |
2135 | ||
2136 | test_expect_success 'override global and system config with missing file' ' | |
2137 | test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list && | |
2138 | test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list && | |
2139 | GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version | |
2140 | ' | |
2141 | ||
2142 | test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' ' | |
2143 | # `git config --system` has different semantics compared to other | |
2144 | # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the | |
2145 | # variable has an effect via a different proxy. | |
2146 | cat >alias-config <<-EOF && | |
2147 | [alias] | |
2148 | hello-world = !echo "hello world" | |
2149 | EOF | |
2150 | test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \ | |
2151 | git hello-world && | |
2152 | GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \ | |
2153 | git hello-world >actual && | |
2154 | echo "hello world" >expect && | |
2155 | test_cmp expect actual | |
2156 | ' | |
2157 | ||
2158 | test_expect_success 'write to overridden global and system config' ' | |
2159 | cat >expect <<EOF && | |
2160 | [config] | |
2161 | key = value | |
2162 | EOF | |
2163 | ||
2164 | GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value && | |
2165 | test_cmp expect write-to-global && | |
2166 | ||
2167 | GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value && | |
2168 | test_cmp expect write-to-system | |
2169 | ' | |
2170 | ||
378fe5fc MT |
2171 | for opt in --local --worktree |
2172 | do | |
2173 | test_expect_success "$opt requires a repo" ' | |
2174 | # we expect 128 to ensure that we do not simply | |
2175 | # fail to find anything and return code "1" | |
2176 | test_expect_code 128 nongit git config $opt foo.bar | |
2177 | ' | |
2178 | done | |
588a538a | 2179 | |
0a8950be | 2180 | cat >.git/config <<-\EOF && |
04f6b0a1 | 2181 | [section] |
fb0dc3ba | 2182 | foo = true |
0a8950be | 2183 | number = 10 |
fb0dc3ba | 2184 | big = 1M |
0a8950be TB |
2185 | EOF |
2186 | ||
fb0dc3ba | 2187 | test_expect_success 'identical modern --type specifiers are allowed' ' |
04f6b0a1 | 2188 | test_cmp_config 1048576 --type=int --type=int section.big |
0a8950be TB |
2189 | ' |
2190 | ||
fb0dc3ba | 2191 | test_expect_success 'identical legacy --type specifiers are allowed' ' |
04f6b0a1 | 2192 | test_cmp_config 1048576 --int --int section.big |
fb0dc3ba TB |
2193 | ' |
2194 | ||
2195 | test_expect_success 'identical mixed --type specifiers are allowed' ' | |
04f6b0a1 | 2196 | test_cmp_config 1048576 --int --type=int section.big |
fb0dc3ba TB |
2197 | ' |
2198 | ||
2199 | test_expect_success 'non-identical modern --type specifiers are not allowed' ' | |
04f6b0a1 | 2200 | test_must_fail git config --type=int --type=bool section.big 2>error && |
fb0dc3ba TB |
2201 | test_i18ngrep "only one type at a time" error |
2202 | ' | |
2203 | ||
2204 | test_expect_success 'non-identical legacy --type specifiers are not allowed' ' | |
04f6b0a1 | 2205 | test_must_fail git config --int --bool section.big 2>error && |
fb0dc3ba TB |
2206 | test_i18ngrep "only one type at a time" error |
2207 | ' | |
2208 | ||
2209 | test_expect_success 'non-identical mixed --type specifiers are not allowed' ' | |
04f6b0a1 | 2210 | test_must_fail git config --type=int --bool section.big 2>error && |
fb0dc3ba TB |
2211 | test_i18ngrep "only one type at a time" error |
2212 | ' | |
2213 | ||
2214 | test_expect_success '--type allows valid type specifiers' ' | |
04f6b0a1 | 2215 | test_cmp_config true --type=bool section.foo |
fb0dc3ba TB |
2216 | ' |
2217 | ||
2218 | test_expect_success '--no-type unsets type specifiers' ' | |
04f6b0a1 | 2219 | test_cmp_config 10 --type=bool --no-type section.number |
fb0dc3ba TB |
2220 | ' |
2221 | ||
2222 | test_expect_success 'unset type specifiers may be reset to conflicting ones' ' | |
04f6b0a1 | 2223 | test_cmp_config 1048576 --type=bool --no-type --type=int section.big |
fb0dc3ba TB |
2224 | ' |
2225 | ||
2226 | test_expect_success '--type rejects unknown specifiers' ' | |
04f6b0a1 | 2227 | test_must_fail git config --type=nonsense section.foo 2>error && |
fb0dc3ba TB |
2228 | test_i18ngrep "unrecognized --type argument" error |
2229 | ' | |
2230 | ||
46fc89ce | 2231 | test_expect_success '--replace-all does not invent newlines' ' |
e9313952 JS |
2232 | q_to_tab >.git/config <<-\EOF && |
2233 | [abc]key | |
2234 | QkeepSection | |
2235 | [xyz] | |
2236 | Qkey = 1 | |
2237 | [abc] | |
2238 | Qkey = a | |
2239 | EOF | |
2240 | q_to_tab >expect <<-\EOF && | |
2241 | [abc] | |
2242 | QkeepSection | |
2243 | [xyz] | |
2244 | Qkey = 1 | |
2245 | [abc] | |
2246 | Qkey = b | |
2247 | EOF | |
2248 | git config --replace-all abc.key b && | |
dcbaa0b3 | 2249 | test_cmp expect .git/config |
e9313952 JS |
2250 | ' |
2251 | ||
2076dba2 DS |
2252 | test_expect_success 'set all config with value-pattern' ' |
2253 | test_when_finished rm -f config initial && | |
2254 | git config --file=initial abc.key one && | |
2255 | ||
2256 | # no match => add new entry | |
2257 | cp initial config && | |
2258 | git config --file=config abc.key two a+ && | |
2259 | git config --file=config --list >actual && | |
2260 | cat >expect <<-\EOF && | |
2261 | abc.key=one | |
2262 | abc.key=two | |
2263 | EOF | |
2264 | test_cmp expect actual && | |
2265 | ||
2266 | # multiple matches => failure | |
2267 | test_must_fail git config --file=config abc.key three o+ 2>err && | |
2268 | test_i18ngrep "has multiple values" err && | |
2269 | ||
2270 | # multiple values, no match => add | |
2271 | git config --file=config abc.key three a+ && | |
2272 | git config --file=config --list >actual && | |
2273 | cat >expect <<-\EOF && | |
2274 | abc.key=one | |
2275 | abc.key=two | |
2276 | abc.key=three | |
2277 | EOF | |
2278 | test_cmp expect actual && | |
2279 | ||
2280 | # single match => replace | |
2281 | git config --file=config abc.key four h+ && | |
2282 | git config --file=config --list >actual && | |
2283 | cat >expect <<-\EOF && | |
2284 | abc.key=one | |
2285 | abc.key=two | |
2286 | abc.key=four | |
2287 | EOF | |
2288 | test_cmp expect actual | |
2289 | ' | |
2290 | ||
d1567194 DS |
2291 | test_expect_success '--replace-all and value-pattern' ' |
2292 | test_when_finished rm -f config && | |
2293 | git config --file=config --add abc.key one && | |
2294 | git config --file=config --add abc.key two && | |
2295 | git config --file=config --add abc.key three && | |
2296 | git config --file=config --replace-all abc.key four "o+" && | |
2297 | git config --file=config --list >actual && | |
2298 | cat >expect <<-\EOF && | |
2299 | abc.key=four | |
2300 | abc.key=three | |
2301 | EOF | |
2302 | test_cmp expect actual | |
2303 | ' | |
2304 | ||
fda43942 DS |
2305 | test_expect_success 'refuse --fixed-value for incompatible actions' ' |
2306 | test_when_finished rm -f config && | |
2307 | git config --file=config dev.null bogus && | |
2308 | ||
2309 | # These modes do not allow --fixed-value at all | |
2310 | test_must_fail git config --file=config --fixed-value --add dev.null bogus && | |
2311 | test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && | |
2312 | test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && | |
2313 | test_must_fail git config --file=config --fixed-value --rename-section dev null && | |
2314 | test_must_fail git config --file=config --fixed-value --remove-section dev && | |
2315 | test_must_fail git config --file=config --fixed-value --list && | |
2316 | test_must_fail git config --file=config --fixed-value --get-color dev.null && | |
2317 | test_must_fail git config --file=config --fixed-value --get-colorbool dev.null && | |
2318 | ||
2319 | # These modes complain when --fixed-value has no value-pattern | |
2320 | test_must_fail git config --file=config --fixed-value dev.null bogus && | |
2321 | test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus && | |
2322 | test_must_fail git config --file=config --fixed-value --get dev.null && | |
2323 | test_must_fail git config --file=config --fixed-value --get-all dev.null && | |
2324 | test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" && | |
2325 | test_must_fail git config --file=config --fixed-value --unset dev.null && | |
2326 | test_must_fail git config --file=config --fixed-value --unset-all dev.null | |
2327 | ' | |
2328 | ||
c90702a1 DS |
2329 | test_expect_success '--fixed-value uses exact string matching' ' |
2330 | test_when_finished rm -f config initial && | |
2331 | META="a+b*c?d[e]f.g" && | |
2332 | git config --file=initial fixed.test "$META" && | |
2333 | ||
2334 | cp initial config && | |
2335 | git config --file=config fixed.test bogus "$META" && | |
2336 | git config --file=config --list >actual && | |
2337 | cat >expect <<-EOF && | |
2338 | fixed.test=$META | |
2339 | fixed.test=bogus | |
2340 | EOF | |
2341 | test_cmp expect actual && | |
2342 | ||
2343 | cp initial config && | |
2344 | git config --file=config --fixed-value fixed.test bogus "$META" && | |
2345 | git config --file=config --list >actual && | |
2346 | cat >expect <<-\EOF && | |
2347 | fixed.test=bogus | |
2348 | EOF | |
2349 | test_cmp expect actual && | |
2350 | ||
2351 | cp initial config && | |
2352 | test_must_fail git config --file=config --unset fixed.test "$META" && | |
2353 | git config --file=config --fixed-value --unset fixed.test "$META" && | |
2354 | test_must_fail git config --file=config fixed.test && | |
2355 | ||
2356 | cp initial config && | |
2357 | test_must_fail git config --file=config --unset-all fixed.test "$META" && | |
2358 | git config --file=config --fixed-value --unset-all fixed.test "$META" && | |
2359 | test_must_fail git config --file=config fixed.test && | |
2360 | ||
2361 | cp initial config && | |
2362 | git config --file=config --replace-all fixed.test bogus "$META" && | |
2363 | git config --file=config --list >actual && | |
2364 | cat >expect <<-EOF && | |
2365 | fixed.test=$META | |
2366 | fixed.test=bogus | |
2367 | EOF | |
2368 | test_cmp expect actual && | |
2369 | ||
2370 | git config --file=config --fixed-value --replace-all fixed.test bogus "$META" && | |
2371 | git config --file=config --list >actual && | |
2372 | cat >expect <<-EOF && | |
2373 | fixed.test=bogus | |
2374 | fixed.test=bogus | |
2375 | EOF | |
2376 | test_cmp expect actual | |
2377 | ' | |
2378 | ||
3f1bae1d DS |
2379 | test_expect_success '--get and --get-all with --fixed-value' ' |
2380 | test_when_finished rm -f config && | |
2381 | META="a+b*c?d[e]f.g" && | |
2382 | git config --file=config fixed.test bogus && | |
2383 | git config --file=config --add fixed.test "$META" && | |
2384 | ||
2385 | git config --file=config --get fixed.test bogus && | |
2386 | test_must_fail git config --file=config --get fixed.test "$META" && | |
2387 | git config --file=config --get --fixed-value fixed.test "$META" && | |
2388 | test_must_fail git config --file=config --get --fixed-value fixed.test non-existent && | |
2389 | ||
2390 | git config --file=config --get-all fixed.test bogus && | |
2391 | test_must_fail git config --file=config --get-all fixed.test "$META" && | |
2392 | git config --file=config --get-all --fixed-value fixed.test "$META" && | |
2393 | test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent && | |
2394 | ||
2395 | git config --file=config --get-regexp fixed+ bogus && | |
2396 | test_must_fail git config --file=config --get-regexp fixed+ "$META" && | |
2397 | git config --file=config --get-regexp --fixed-value fixed+ "$META" && | |
2398 | test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent | |
2399 | ' | |
2400 | ||
399b1984 JT |
2401 | test_expect_success 'includeIf.hasconfig:remote.*.url' ' |
2402 | git init hasremoteurlTest && | |
2403 | test_when_finished "rm -rf hasremoteurlTest" && | |
2404 | ||
2405 | cat >include-this <<-\EOF && | |
2406 | [user] | |
2407 | this = this-is-included | |
2408 | EOF | |
2409 | cat >dont-include-that <<-\EOF && | |
2410 | [user] | |
2411 | that = that-is-not-included | |
2412 | EOF | |
2413 | cat >>hasremoteurlTest/.git/config <<-EOF && | |
2414 | [includeIf "hasconfig:remote.*.url:foourl"] | |
2415 | path = "$(pwd)/include-this" | |
2416 | [includeIf "hasconfig:remote.*.url:barurl"] | |
2417 | path = "$(pwd)/dont-include-that" | |
2418 | [remote "foo"] | |
2419 | url = foourl | |
2420 | EOF | |
2421 | ||
2422 | echo this-is-included >expect-this && | |
2423 | git -C hasremoteurlTest config --get user.this >actual-this && | |
2424 | test_cmp expect-this actual-this && | |
2425 | ||
2426 | test_must_fail git -C hasremoteurlTest config --get user.that | |
2427 | ' | |
2428 | ||
2429 | test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' ' | |
2430 | git init hasremoteurlTest && | |
2431 | test_when_finished "rm -rf hasremoteurlTest" && | |
2432 | ||
2433 | cat >include-two-three <<-\EOF && | |
2434 | [user] | |
2435 | two = included-config | |
2436 | three = included-config | |
2437 | EOF | |
2438 | cat >>hasremoteurlTest/.git/config <<-EOF && | |
2439 | [remote "foo"] | |
2440 | url = foourl | |
2441 | [user] | |
2442 | one = main-config | |
2443 | two = main-config | |
2444 | [includeIf "hasconfig:remote.*.url:foourl"] | |
2445 | path = "$(pwd)/include-two-three" | |
2446 | [user] | |
2447 | three = main-config | |
2448 | EOF | |
2449 | ||
2450 | echo main-config >expect-main-config && | |
2451 | echo included-config >expect-included-config && | |
2452 | ||
2453 | git -C hasremoteurlTest config --get user.one >actual && | |
2454 | test_cmp expect-main-config actual && | |
2455 | ||
2456 | git -C hasremoteurlTest config --get user.two >actual && | |
2457 | test_cmp expect-included-config actual && | |
2458 | ||
2459 | git -C hasremoteurlTest config --get user.three >actual && | |
2460 | test_cmp expect-main-config actual | |
2461 | ' | |
2462 | ||
2463 | test_expect_success 'includeIf.hasconfig:remote.*.url globs' ' | |
2464 | git init hasremoteurlTest && | |
2465 | test_when_finished "rm -rf hasremoteurlTest" && | |
2466 | ||
2467 | printf "[user]\ndss = yes\n" >double-star-start && | |
2468 | printf "[user]\ndse = yes\n" >double-star-end && | |
2469 | printf "[user]\ndsm = yes\n" >double-star-middle && | |
2470 | printf "[user]\nssm = yes\n" >single-star-middle && | |
2471 | printf "[user]\nno = no\n" >no && | |
2472 | ||
2473 | cat >>hasremoteurlTest/.git/config <<-EOF && | |
2474 | [remote "foo"] | |
2475 | url = https://foo/bar/baz | |
2476 | [includeIf "hasconfig:remote.*.url:**/baz"] | |
2477 | path = "$(pwd)/double-star-start" | |
2478 | [includeIf "hasconfig:remote.*.url:**/nomatch"] | |
2479 | path = "$(pwd)/no" | |
2480 | [includeIf "hasconfig:remote.*.url:https:/**"] | |
2481 | path = "$(pwd)/double-star-end" | |
2482 | [includeIf "hasconfig:remote.*.url:nomatch:/**"] | |
2483 | path = "$(pwd)/no" | |
2484 | [includeIf "hasconfig:remote.*.url:https:/**/baz"] | |
2485 | path = "$(pwd)/double-star-middle" | |
2486 | [includeIf "hasconfig:remote.*.url:https:/**/nomatch"] | |
2487 | path = "$(pwd)/no" | |
2488 | [includeIf "hasconfig:remote.*.url:https://*/bar/baz"] | |
2489 | path = "$(pwd)/single-star-middle" | |
2490 | [includeIf "hasconfig:remote.*.url:https://*/baz"] | |
2491 | path = "$(pwd)/no" | |
2492 | EOF | |
2493 | ||
2494 | git -C hasremoteurlTest config --get user.dss && | |
2495 | git -C hasremoteurlTest config --get user.dse && | |
2496 | git -C hasremoteurlTest config --get user.dsm && | |
2497 | git -C hasremoteurlTest config --get user.ssm && | |
2498 | test_must_fail git -C hasremoteurlTest config --get user.no | |
2499 | ' | |
2500 | ||
2501 | test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' ' | |
2502 | git init hasremoteurlTest && | |
2503 | test_when_finished "rm -rf hasremoteurlTest" && | |
2504 | ||
2505 | cat >include-with-url <<-\EOF && | |
2506 | [remote "bar"] | |
2507 | url = barurl | |
2508 | EOF | |
2509 | cat >>hasremoteurlTest/.git/config <<-EOF && | |
2510 | [includeIf "hasconfig:remote.*.url:foourl"] | |
2511 | path = "$(pwd)/include-with-url" | |
2512 | EOF | |
2513 | ||
2514 | # test with any Git command | |
2515 | test_must_fail git -C hasremoteurlTest status 2>err && | |
2516 | grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err | |
2517 | ' | |
2518 | ||
942c1f53 | 2519 | test_done |