Debian Codegraph @

tests/test-config.t

raw
1 Windows needs ';' as a file separator in an environment variable, and MSYS
2 doesn't automatically convert it in every case.
3
4 #if windows
5 $ path_list_var() {
6 > echo $1 | sed 's/:/;/g'
7 > }
8 #else
9 $ path_list_var() {
10 > echo $1
11 > }
12 #endif
13
14
15 hide outer repo
16 $ hg init
17
18 Invalid syntax: no value
19
20 $ cat > .hg/hgrc << EOF
21 > novaluekey
22 > EOF
23 $ hg showconfig
24 config error at $TESTTMP/.hg/hgrc:1: novaluekey
25 [30]
26
27 Invalid syntax: no key
28
29 $ cat > .hg/hgrc << EOF
30 > =nokeyvalue
31 > EOF
32 $ hg showconfig
33 config error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
34 [30]
35
36 Test hint about invalid syntax from leading white space
37
38 $ cat > .hg/hgrc << EOF
39 > key=value
40 > EOF
41 $ hg showconfig
42 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: key=value
43 [30]
44
45 $ cat > .hg/hgrc << EOF
46 > [section]
47 > key=value
48 > EOF
49 $ hg showconfig
50 config error at $TESTTMP/.hg/hgrc:1: unexpected leading whitespace: [section]
51 [30]
52
53 Reset hgrc
54
55 $ echo > .hg/hgrc
56
57 Test case sensitive configuration
58
59 $ cat <<EOF >> $HGRCPATH
60 > [Section]
61 > KeY = Case Sensitive
62 > key = lower case
63 > EOF
64
65 $ hg showconfig Section
66 Section.KeY=Case Sensitive
67 Section.key=lower case
68
69 $ hg showconfig Section -Tjson
70 [
71 {
72 "defaultvalue": null,
73 "name": "Section.KeY",
74 "source": "$HGRCPATH:*", (glob) (no-windows !)
75 "source": "$STR_REPR_HGRCPATH:*", (glob) (windows !)
76 "value": "Case Sensitive"
77 },
78 {
79 "defaultvalue": null,
80 "name": "Section.key",
81 "source": "$HGRCPATH:*", (glob) (no-windows !)
82 "source": "$STR_REPR_HGRCPATH:*", (glob) (windows !)
83 "value": "lower case"
84 }
85 ]
86 $ hg showconfig Section.KeY -Tjson
87 [
88 {
89 "defaultvalue": null,
90 "name": "Section.KeY",
91 "source": "$HGRCPATH:*", (glob) (no-windows !)
92 "source": "$STR_REPR_HGRCPATH:*", (glob) (windows !)
93 "value": "Case Sensitive"
94 }
95 ]
96 $ hg showconfig -Tjson | tail -7
97 {
98 "defaultvalue": null,
99 "name": "*", (glob)
100 "source": "*", (glob)
101 "value": "*" (glob)
102 }
103 ]
104
105 Test config default of various types:
106
107 {"defaultvalue": ""} for -T'json(defaultvalue)' looks weird, but that's
108 how the templater works. Unknown keywords are evaluated to "".
109
110 dynamicdefault
111
112 $ hg config --config alias.foo= alias -Tjson
113 [
114 {
115 "name": "alias.foo",
116 "source": "--config",
117 "value": ""
118 }
119 ]
120 $ hg config --config alias.foo= alias -T'json(defaultvalue)'
121 [
122 {"defaultvalue": ""}
123 ]
124 $ hg config --config alias.foo= alias -T'{defaultvalue}\n'
125
126
127 null
128
129 $ hg config --config auth.cookiefile= auth -Tjson
130 [
131 {
132 "defaultvalue": null,
133 "name": "auth.cookiefile",
134 "source": "--config",
135 "value": ""
136 }
137 ]
138 $ hg config --config auth.cookiefile= auth -T'json(defaultvalue)'
139 [
140 {"defaultvalue": null}
141 ]
142 $ hg config --config auth.cookiefile= auth -T'{defaultvalue}\n'
143
144
145 false
146
147 $ hg config --config commands.commit.post-status= commands -Tjson
148 [
149 {
150 "defaultvalue": false,
151 "name": "commands.commit.post-status",
152 "source": "--config",
153 "value": ""
154 }
155 ]
156 $ hg config --config commands.commit.post-status= commands -T'json(defaultvalue)'
157 [
158 {"defaultvalue": false}
159 ]
160 $ hg config --config commands.commit.post-status= commands -T'{defaultvalue}\n'
161 False
162
163 true
164
165 $ hg config --config format.dotencode= format.dotencode -Tjson
166 [
167 {
168 "defaultvalue": true,
169 "name": "format.dotencode",
170 "source": "--config",
171 "value": ""
172 }
173 ]
174 $ hg config --config format.dotencode= format.dotencode -T'json(defaultvalue)'
175 [
176 {"defaultvalue": true}
177 ]
178 $ hg config --config format.dotencode= format.dotencode -T'{defaultvalue}\n'
179 True
180
181 bytes
182
183 $ hg config --config commands.resolve.mark-check= commands -Tjson
184 [
185 {
186 "defaultvalue": "none",
187 "name": "commands.resolve.mark-check",
188 "source": "--config",
189 "value": ""
190 }
191 ]
192 $ hg config --config commands.resolve.mark-check= commands -T'json(defaultvalue)'
193 [
194 {"defaultvalue": "none"}
195 ]
196 $ hg config --config commands.resolve.mark-check= commands -T'{defaultvalue}\n'
197 none
198
199 empty list
200
201 $ hg config --config commands.show.aliasprefix= commands -Tjson
202 [
203 {
204 "defaultvalue": [],
205 "name": "commands.show.aliasprefix",
206 "source": "--config",
207 "value": ""
208 }
209 ]
210 $ hg config --config commands.show.aliasprefix= commands -T'json(defaultvalue)'
211 [
212 {"defaultvalue": []}
213 ]
214 $ hg config --config commands.show.aliasprefix= commands -T'{defaultvalue}\n'
215
216
217 nonempty list
218
219 $ hg config --config progress.format= progress -Tjson
220 [
221 {
222 "defaultvalue": ["topic", "bar", "number", "estimate"],
223 "name": "progress.format",
224 "source": "--config",
225 "value": ""
226 }
227 ]
228 $ hg config --config progress.format= progress -T'json(defaultvalue)'
229 [
230 {"defaultvalue": ["topic", "bar", "number", "estimate"]}
231 ]
232 $ hg config --config progress.format= progress -T'{defaultvalue}\n'
233 topic bar number estimate
234
235 int
236
237 $ hg config --config profiling.freq= profiling -Tjson
238 [
239 {
240 "defaultvalue": 1000,
241 "name": "profiling.freq",
242 "source": "--config",
243 "value": ""
244 }
245 ]
246 $ hg config --config profiling.freq= profiling -T'json(defaultvalue)'
247 [
248 {"defaultvalue": 1000}
249 ]
250 $ hg config --config profiling.freq= profiling -T'{defaultvalue}\n'
251 1000
252
253 float
254
255 $ hg config --config profiling.showmax= profiling -Tjson
256 [
257 {
258 "defaultvalue": 0.999,
259 "name": "profiling.showmax",
260 "source": "--config",
261 "value": ""
262 }
263 ]
264 $ hg config --config profiling.showmax= profiling -T'json(defaultvalue)'
265 [
266 {"defaultvalue": 0.999}
267 ]
268 $ hg config --config profiling.showmax= profiling -T'{defaultvalue}\n'
269 0.999
270
271 Test empty config source:
272
273 $ cat <<EOF > emptysource.py
274 > def reposetup(ui, repo):
275 > ui.setconfig(b'empty', b'source', b'value')
276 > EOF
277 $ cp .hg/hgrc .hg/hgrc.orig
278 $ cat <<EOF >> .hg/hgrc
279 > [extensions]
280 > emptysource = `pwd`/emptysource.py
281 > EOF
282
283 $ hg config --source empty.source
284 none: value
285 $ hg config empty.source -Tjson
286 [
287 {
288 "defaultvalue": null,
289 "name": "empty.source",
290 "source": "",
291 "value": "value"
292 }
293 ]
294
295 $ cp .hg/hgrc.orig .hg/hgrc
296
297 Test "%unset"
298
299 $ cat >> $HGRCPATH <<EOF
300 > [unsettest]
301 > local-hgrcpath = should be unset (HGRCPATH)
302 > %unset local-hgrcpath
303 >
304 > global = should be unset (HGRCPATH)
305 >
306 > both = should be unset (HGRCPATH)
307 >
308 > set-after-unset = should be unset (HGRCPATH)
309 > EOF
310
311 $ cat >> .hg/hgrc <<EOF
312 > [unsettest]
313 > local-hgrc = should be unset (.hg/hgrc)
314 > %unset local-hgrc
315 >
316 > %unset global
317 >
318 > both = should be unset (.hg/hgrc)
319 > %unset both
320 >
321 > set-after-unset = should be unset (.hg/hgrc)
322 > %unset set-after-unset
323 > set-after-unset = should be set (.hg/hgrc)
324 > EOF
325
326 $ hg showconfig unsettest
327 unsettest.set-after-unset=should be set (.hg/hgrc)
328
329 Test exit code when no config matches
330
331 $ hg config Section.idontexist
332 [1]
333
334 sub-options in [paths] aren't expanded
335
336 $ cat > .hg/hgrc << EOF
337 > [paths]
338 > foo = ~/foo
339 > foo:suboption = ~/foo
340 > EOF
341
342 $ hg showconfig paths
343 paths.foo=~/foo
344 paths.foo:suboption=~/foo
345
346 note: The path expansion no longer happens at the config level, but the path is
347 still expanded:
348
349 $ hg path | grep foo
350 foo = $TESTTMP/foo
351
352 edit failure
353
354 $ HGEDITOR=false hg config --edit
355 abort: edit failed: false exited with status 1
356 [10]
357
358 config affected by environment variables
359
360 $ EDITOR=e1 VISUAL=e2 hg config --source | grep 'ui\.editor'
361 $VISUAL: ui.editor=e2
362
363 $ VISUAL=e2 hg config --source --config ui.editor=e3 | grep 'ui\.editor'
364 --config: ui.editor=e3
365
366 $ PAGER=p1 hg config --source | grep 'pager\.pager'
367 $PAGER: pager.pager=p1
368
369 $ PAGER=p1 hg config --source --config pager.pager=p2 | grep 'pager\.pager'
370 --config: pager.pager=p2
371
372 verify that aliases are evaluated as well
373
374 $ hg init aliastest
375 $ cd aliastest
376 $ cat > .hg/hgrc << EOF
377 > [ui]
378 > user = repo user
379 > EOF
380 $ touch index
381 $ unset HGUSER
382 $ hg ci -Am test
383 adding index
384 $ hg log --template '{author}\n'
385 repo user
386 $ cd ..
387
388 alias has lower priority
389
390 $ hg init aliaspriority
391 $ cd aliaspriority
392 $ cat > .hg/hgrc << EOF
393 > [ui]
394 > user = alias user
395 > username = repo user
396 > EOF
397 $ touch index
398 $ unset HGUSER
399 $ hg ci -Am test
400 adding index
401 $ hg log --template '{author}\n'
402 repo user
403 $ cd ..
404
405 configs should be read in lexicographical order
406
407 $ mkdir configs
408 $ for i in `$TESTDIR/seq.py 10 99`; do
409 > printf "[section]\nkey=$i" > configs/$i.rc
410 > done
411 $ HGRCPATH=configs hg config section.key
412 99
413
414 Listing all config options
415 ==========================
416
417 The feature is experimental and behavior may varies. This test exists to make sure the code is run. We grep it to avoid too much variability in its current experimental state.
418
419 $ hg config --exp-all-known | grep commit | grep -v ssh
420 commands.commit.interactive.git=False
421 commands.commit.interactive.ignoreblanklines=False
422 commands.commit.interactive.ignorews=False
423 commands.commit.interactive.ignorewsamount=False
424 commands.commit.interactive.ignorewseol=False
425 commands.commit.interactive.nobinary=False
426 commands.commit.interactive.nodates=False
427 commands.commit.interactive.noprefix=False
428 commands.commit.interactive.showfunc=False
429 commands.commit.interactive.unified=None
430 commands.commit.interactive.word-diff=False
431 commands.commit.post-status=False
432 commands.commit.report-head-changes=True
433 convert.git.committeractions=[*'messagedifferent'] (glob)
434 convert.svn.dangerous-set-commit-dates=False
435 experimental.copytrace.sourcecommitlimit=100
436 phases.new-commit=draft
437 ui.allowemptycommit=False
438 ui.commitsubrepos=False
439
440
441 Configuration priority
442 ======================
443
444 setup necessary file
445
446 $ cat > file-A.rc << EOF
447 > [config-test]
448 > basic = value-A
449 > pre-include= value-A
450 > %include ./included.rc
451 > post-include= value-A
452 > [command-templates]
453 > log = "value-A\n"
454 > EOF
455
456 $ cat > file-B.rc << EOF
457 > [config-test]
458 > basic = value-B
459 > [ui]
460 > logtemplate = "value-B\n"
461 > EOF
462
463 $ cat > config-file.rc <<EOF
464 > [config-test]
465 > basic = value-CONFIG-FILE
466 > [ui]
467 > logtemplate = "value-CONFIG-FILE\n"
468 > EOF
469
470 $ cat > config-file2.rc <<EOF
471 > [config-test]
472 > basic = value-CONFIG-FILE-2
473 > [ui]
474 > logtemplate = "value-CONFIG-FILE-2\n"
475 > EOF
476
477
478 $ cat > included.rc << EOF
479 > [config-test]
480 > pre-include= value-included
481 > post-include= value-included
482 > EOF
483
484 $ cat > file-C.rc << EOF
485 > %include ./included-alias-C.rc
486 > [ui]
487 > logtemplate = "value-C\n"
488 > EOF
489
490 $ cat > included-alias-C.rc << EOF
491 > [command-templates]
492 > log = "value-included\n"
493 > EOF
494
495
496 $ cat > file-D.rc << EOF
497 > [command-templates]
498 > log = "value-D\n"
499 > %include ./included-alias-D.rc
500 > EOF
501
502 $ cat > included-alias-D.rc << EOF
503 > [ui]
504 > logtemplate = "value-included\n"
505 > EOF
506
507 Simple order checking
508 ---------------------
509
510 If file B is read after file A, value from B overwrite value from A.
511
512 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic
513 value-B
514
515 Ordering from include
516 ---------------------
517
518 value from an include overwrite value defined before the include, but not the one defined after the include
519
520 $ HGRCPATH="file-A.rc" hg config config-test.pre-include
521 value-included
522 $ HGRCPATH="file-A.rc" hg config config-test.post-include
523 value-A
524
525 command line override
526 ---------------------
527
528 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic --config config-test.basic=value-CLI
529 value-CLI
530
531 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic --config-file config-file.rc
532 value-CONFIG-FILE
533
534 --config-file args are processed in order of appearance
535
536 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic \
537 > --config-file config-file.rc --config-file config-file2.rc
538 value-CONFIG-FILE-2
539
540 --config overrides --config-file, regardless of order
541
542 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic \
543 > --config config-test.basic=value-CLI --config-file config-file.rc
544 value-CLI
545
546 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg config config-test.basic \
547 > --config-file config-file.rc --config config-test.basic=value-CLI
548 value-CLI
549
550 Alias ordering
551 --------------
552
553 The official config is now `command-templates.log`, the historical
554 `ui.logtemplate` is a valid alternative for it.
555
556 When both are defined, The config value read the last "win", this should keep
557 being true if the config have other alias. In other word, the config value read
558 earlier will be considered "lower level" and the config read later would be
559 considered "higher level". And higher level values wins.
560
561 $ HGRCPATH="file-A.rc" hg log -r .
562 value-A
563 $ HGRCPATH="file-B.rc" hg log -r .
564 value-B
565 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg log -r .
566 value-B
567
568 Alias and include
569 -----------------
570
571 The pre/post include priority should also apply when tie-breaking alternatives.
572 See the case above for details about the two config options used.
573
574 $ HGRCPATH="file-C.rc" hg log -r .
575 value-C
576 $ HGRCPATH="file-D.rc" hg log -r .
577 value-included
578
579 command line override
580 ---------------------
581
582 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg log -r . --config ui.logtemplate="value-CLI\n"
583 value-CLI
584
585
586 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg log -r . --config-file config-file.rc
587 value-CONFIG-FILE
588
589 --config overrides --config-file
590
591 $ HGRCPATH=`path_list_var "file-A.rc:file-B.rc"` hg log -r . \
592 > --config ui.logtemplate="value-CLI\n" --config-file config-file.rc
593 value-CLI
594
595
596 Bad --config-file usage
597 -----------------------
598
599 For some reason, chg doesn't honor the detailed-exit-code=True setting, and
600 exits with 255 for these cases that would normally exit with 10 for InputError.
601 The exit code alone can't be conditionalized in the test here, and this failure
602 to honor the setting is also true when passing a malformed --config, so disable
603 the config for now.
604
605 $ cat >> $HGRCPATH <<EOF
606 > [ui]
607 > detailed-exit-code = False
608 > EOF
609
610 $ cat > not-a-config-file.txt <<EOF
611 > this is a bad config file line
612 > EOF
613
614 $ hg config auth --config-file not-a-config-file.txt
615 abort: invalid --config-file content at not-a-config-file.txt:1
616 (unexpected leading whitespace: this is a bad config file line)
617 [255]
618
619 $ hg config auth --config-file non-existent-file.rc
620 abort: missing file "non-existent-file.rc" for --config-file
621 [255]
622
623 $ hg config auth --config-file non-existent-file.rc --cwd ..
624 abort: missing file "non-existent-file.rc" for --config-file
625 (this file is resolved before --cwd is processed)
626 [255]