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