sapling/tests/test-dispatch.t

220 lines
5.8 KiB
Perl
Raw Normal View History

2010-09-02 19:13:23 +04:00
test command parsing and dispatch
$ hg init a
$ cd a
Redundant options used to crash (issue436):
$ hg -v log -v
$ hg -v log -v x
2010-09-02 19:13:23 +04:00
$ echo a > a
$ hg ci -Ama
adding a
Missing arg:
$ hg cat
hg cat: invalid arguments
hg cat [OPTION]... FILE...
output the current or given revision of files
options ([+] can be repeated):
2010-09-02 19:13:23 +04:00
2011-09-21 22:00:48 +04:00
-o --output FORMAT print output to file with formatted name
-r --rev REV print the given revision
help: backout 6f89f03ad369 (mark boolean flags with [no-] in help) for now The ability to negate any boolean flags itself is great, but I think we are not ready to expose the help side of it yet. First, while there exist a handful of such flags whose default value can be changed (eg: git diff, patchwork confirmation), there is only a few of them. The users who benefit the most from this change are alias users and large installation that can deploy extension to change behavior (eg: facebook tweakdefault). So the majority of user who will be affected by a large change to command help that is not yet relevant to them. (I expect this to become relevant when ui.progressive start to exists). Below is an example of the impact of the new help on 'hg help diff': -r --rev REV [+] revision -c --change REV change made by revision -a --[no-]text treat all files as text -g --[no-]git use git extended diff format --[no-]nodates omit dates from diff headers --[no-]noprefix omit a/ and b/ prefixes from filenames -p --[no-]show-function show which function each change is in --[no-]reverse produce a diff that undoes the changes -w --[no-]ignore-all-space ignore white space when comparing lines -b --[no-]ignore-space-change ignore changes in the amount of white space -B --[no-]ignore-blank-lines ignore changes whose lines are all blank -U --unified NUM number of lines of context to show --[no-]stat output diffstat-style summary of changes --root DIR produce diffs relative to subdirectory -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns -S --[no-]subrepos recurse into subrepositories Another issue with the current state of help, the default value for the flag is not conveyed to the user. For example in the 'backout' help, there is no real distinction between "--[no-]backup" (default to True) and "--[no-]keep" (default) to False: --[no-]backup no backups --[no-]keep do not modify working directory during strip In addition, I've discussed with Augie Fackler and the last batch of the work on this have burned him out quite some. Therefore he is not intending to perform any more work on this topic. Quoting him, he would rather see the help part backed out than spending more time on it. I do not think we are ready to expose this to users in 4.0 (freeze in a week), especially because we cannot expect quick improvement on these aspect as this topic no longer have an owner. We should be able to reintroduce that change in the future when someone get back on it and the main issues are solves: * Introduction of ui.progressive makes it relevant for a majority of user, * Current default value are efficiently conveyed to the user. (In addition, the excerpt from diff help show that we still have some issue with some negative option like '--nodates' so further improvement are probably welcome there.)
2016-10-09 04:11:18 +03:00
--decode apply any matching decode filter
2011-09-21 22:00:48 +04:00
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
2010-09-02 19:13:23 +04:00
2016-09-21 02:47:46 +03:00
(use 'hg cat -h' to show more help)
2010-09-17 02:51:32 +04:00
[255]
2010-09-02 19:13:23 +04:00
Missing parameter for early option:
$ hg log -R 2>&1 | grep 'hg log'
hg log: option -R requires argument
hg log [OPTION]... [FILE]
(use 'hg log -h' to show more help)
"--" may be an option value:
$ hg -R -- log
abort: repository -- not found!
[255]
$ hg log -R --
abort: repository -- not found!
[255]
$ hg log -T --
-- (no-eol)
$ hg log -T -- -k nomatch
Parsing of early options should stop at "--":
$ hg cat -- --config=hooks.pre-cat=false
--config=hooks.pre-cat=false: no such file in rev cb9a9f314b8b
[1]
$ hg cat -- --debugger
--debugger: no such file in rev cb9a9f314b8b
[1]
Unparsable form of early options:
$ hg cat --debugg
abort: option --debugger may not be abbreviated!
[255]
Parsing failure of early options should be detected before executing the
command:
$ hg log -b '--config=hooks.pre-log=false' default
abort: option --config may not be abbreviated!
[255]
$ hg log -b -R. default
abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo!
[255]
$ hg log --cwd .. -b --cwd=. default
abort: option --cwd may not be abbreviated!
[255]
However, we can't prevent it from loading extensions and configs:
$ cat <<EOF > bad.py
> raise Exception('bad')
> EOF
$ hg log -b '--config=extensions.bad=bad.py' default
*** failed to import extension bad from bad.py: bad
abort: option --config may not be abbreviated!
[255]
$ mkdir -p badrepo/.hg
$ echo 'invalid-syntax' > badrepo/.hg/hgrc
$ hg log -b -Rbadrepo default
hg: parse error at badrepo/.hg/hgrc:1: invalid-syntax
[255]
$ hg log -b --cwd=inexistent default
abort: $ENOENT$: 'inexistent'
[255]
$ hg log -b '--config=ui.traceback=yes' 2>&1 | grep '^Traceback'
Traceback (most recent call last):
$ hg log -b '--config=profiling.enabled=yes' 2>&1 | grep -i sample
Sample count: .*|No samples recorded\. (re)
Early options can't be specified in [aliases] and [defaults] because they are
applied before the command name is resolved:
$ hg log -b '--config=alias.log=log --config=hooks.pre-log=false'
hg log: option -b not recognized
error in definition for alias 'log': --config may only be given on the command
line
[255]
$ hg log -b '--config=defaults.log=--config=hooks.pre-log=false'
abort: option --config may not be abbreviated!
[255]
Shell aliases bypass any command parsing rules but for the early one:
$ hg log -b '--config=alias.log=!echo howdy'
howdy
Early options must come first if HGPLAIN=+strictflags is specified:
(BUG: chg cherry-picks early options to pass them as a server command)
#if no-chg
$ HGPLAIN=+strictflags hg log -b --config='hooks.pre-log=false' default
abort: unknown revision '--config=hooks.pre-log=false'!
[255]
$ HGPLAIN=+strictflags hg log -b -R. default
abort: unknown revision '-R.'!
[255]
$ HGPLAIN=+strictflags hg log -b --cwd=. default
abort: unknown revision '--cwd=.'!
[255]
#endif
$ HGPLAIN=+strictflags hg log -b --debugger default
abort: unknown revision '--debugger'!
[255]
$ HGPLAIN=+strictflags hg log -b --config='alias.log=!echo pwned' default
abort: unknown revision '--config=alias.log=!echo pwned'!
[255]
$ HGPLAIN=+strictflags hg log --config='hooks.pre-log=false' -b default
abort: option --config may not be abbreviated!
[255]
$ HGPLAIN=+strictflags hg log -q --cwd=.. -b default
abort: option --cwd may not be abbreviated!
[255]
$ HGPLAIN=+strictflags hg log -q -R . -b default
abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo!
[255]
$ HGPLAIN=+strictflags hg --config='hooks.pre-log=false' log -b default
abort: pre-log hook exited with status 1
[255]
$ HGPLAIN=+strictflags hg --cwd .. -q -Ra log -b default
0:cb9a9f314b8b
$ HGPLAIN=+strictflags hg --cwd .. -q --repository a log -b default
0:cb9a9f314b8b
$ HGPLAIN=+strictflags hg --cwd .. -q --repo a log -b default
0:cb9a9f314b8b
For compatibility reasons, HGPLAIN=+strictflags is not enabled by plain HGPLAIN:
$ HGPLAIN= hg log --config='hooks.pre-log=false' -b default
abort: pre-log hook exited with status 1
[255]
$ HGPLAINEXCEPT= hg log --cwd .. -q -Ra -b default
0:cb9a9f314b8b
2010-09-02 19:13:23 +04:00
[defaults]
$ hg cat a
a
$ cat >> $HGRCPATH <<EOF
> [defaults]
> cat = -r null
> EOF
$ hg cat a
a: no such file in rev 000000000000
2010-09-17 02:51:32 +04:00
[1]
2010-09-02 19:13:23 +04:00
$ cd "$TESTTMP"
OSError "No such file or directory" / "The system cannot find the path
specified" should include filename even when it is empty
$ hg -R a archive ''
abort: *: '' (glob)
[255]
#if no-outer-repo
2010-09-02 19:13:23 +04:00
No repo:
$ hg cat
abort: no repository found in '$TESTTMP' (.hg not found)!
2010-09-17 02:51:32 +04:00
[255]
2010-09-02 19:13:23 +04:00
#endif
#if rmcwd
Current directory removed:
$ mkdir $TESTTMP/repo1
$ cd $TESTTMP/repo1
$ rm -rf $TESTTMP/repo1
The output could be one of the following and something else:
chg: abort: failed to getcwd (errno = *) (glob)
abort: error getting current working directory: * (glob)
sh: 0: getcwd() failed: $ENOENT$
Since the exact behavior depends on the shell, only check it returns non-zero.
$ HGDEMANDIMPORT=disable hg version -q 2>/dev/null || false
[1]
#endif