Commit Graph

47 Commits

Author SHA1 Message Date
FUJIWARA Katsunori
503f499347 tests: use "%HG_ARGS%" in shell alias on Windows instead of "$HG_ARGS"
Before this patch, a part of "test-alias.t" fails unexpectedly on
Windows environment, because "cmd.exe" can't evaluate "$HG_ARGS"
expression in shell alias correctly.

This patch uses "%HG_ARGS%" in shell alias on Windows instead of
"$HG_ARGS" to expand it correctly.
2014-10-28 00:19:18 +09:00
Jordi Gutiérrez Hermoso
a7cc108c20 log: do not hide the public phase in debug mode (BC)
When 62900f2373fa introduced phases to the `hg log --debug` output, it
also disabled outputting public phase. At the same time, it always
shows phases in the default template, `hg log --debug -T default`.
Those two should produce the same output, but they don't.

I think it makes a lot more sense to always show all phases. There's
already loss of backwards compatibility in this case when using a
newer hg on an old hg repo, since draft commits will show up in the
output of `hg log --debug`.

Finally, I just don't think that any sort of information should be
hidden with --debug. This flag should be about showing as much
information as possible.
2014-10-04 16:28:28 -04:00
Augie Fackler
a0fd83333c merge with stable 2014-09-09 13:47:50 -04:00
FUJIWARA Katsunori
0d1dc1fcfa dispatch: check shell alias again after loading extensions (issue4355)
Before this patch, the shell alias causes failure when it takes its
specific (= unknown for "hg") options in the command line, because
"_parse()" can't accept them.

This is the regression introduced by 7849ac1dbc57.

It fixed the issue that ambiguity between shell aliases and commands
defined by extensions was ignored. But it also caused that ambiguous
shell alias is handled in "_parse()" even if it takes specific options
in the command line.

To avoid such failure, this patch checks shell alias again after
loading extensions.

All aliases and commands (including ones defined by extensions) are
completely defined before the 2nd (= newly added in this patch)
"_checkshellalias()" invocation, and "cmdutil.findcmd(strict=False)"
can detect ambiguity between them correctly.

For efficiency, this patch does:

  - omit the 2nd "_checkshellalias()" invocation if "[ui] strict= True"

    it causes "cmdutil.findcmd(strict=True)", of which result should
    be equal to one of the 1st invocation before adding aliases

  - avoid removing the 1st "_checkshellalias()" invocation

    it causes "cmdutil.findcmd(strict=True)" invocation preventing
    shell alias execution from loading extensions uselessly
2014-09-10 00:41:44 +09:00
Yuya Nishihara
ea70238e6f alias: exit from bad definition by Abort 2014-08-13 22:22:24 +09:00
Yuya Nishihara
2d19d347a0 alias: show one-line hint for command provided by disabled extension
It will be a hint of Abort exception.  "hg help <alias>" provides the detailed
version as before.
2014-08-13 22:18:28 +09:00
Yuya Nishihara
5ffa20b315 help: provide help of bad alias without executing aliascmd()
The output is slightly changed because of minirst formatting.  Previously,
ui.pushbuffer() had no effect because "badalias" message was written to stderr.

"if not unknowncmd" should no longer be needed because there's no call loop.
2014-08-13 19:38:47 +09:00
Yuya Nishihara
9068ad3b7f alias: add test for alias command provided by disabled extension
This should complete cases where "badalias" is set.
2014-05-17 20:47:31 +09:00
Siddharth Agarwal
4b5c9f694a alias: expand "$@" as list of parameters quoted individually (BC) (issue4200)
Before this patch, there was no way to pass in all the positional parameters as
separate words down to another command.

(1) $@ (without quotes) would expand to all the parameters separated by a space.
    This would work fine for arguments without spaces, but arguments with spaces
    in them would be split up by POSIX shells into separate words.
(2) '$@' (in single quotes) would expand to all the parameters within a pair of
    single quotes. POSIX shells would then treat the entire list of arguments
    as one word.
(3) "$@" (in double quotes) would expand similarly to (2).

With this patch, we expand "$@" (in double quotes) as all positional
parameters, quoted individually with util.shellquote, and separated by spaces.
Under standard field-splitting conditions, POSIX shells will tokenize each
argument into exactly one word.

This is a backwards-incompatible change, but the old behavior was arguably a
bug: Bourne-derived shells have expanded "$@" as a tokenized list of positional
parameters for a very long time. I could find this behavior specified in IEEE
Std 1003.1-2001, and this probably goes back to much further before that.
2014-08-13 23:21:52 -07:00
Siddharth Agarwal
a15c76a2c8 test-alias: add some tests to ensure we aren't double-substituting
An earlier iteration of an upcoming patch caused inadvertent
double substitution. Ensure we have test coverage for this.
2014-08-13 22:37:09 -07:00
Matt Mackall
d2e240d48e help: normalize helplist hints 2014-08-12 04:11:32 -05:00
Matt Mackall
106c32f507 help: improve command summary hint
This adds our normal hint parentheses, corrects the command syntax
(consider config), and corrects the fullness of help you'll get.
2014-08-12 03:09:26 -05:00
Yuya Nishihara
bc04e2c6cd alias: change return code of bad definition to 255
We use 255 for general command error.

It can't raise util.Abort because help module executes badalias command to get
error message.
2014-05-17 15:14:18 +09:00
Yuya Nishihara
2827ff321c alias: handle shlex error in command aliases
No command should fail with ValueError just because there is unparseable
alias definition.

It returns 1 like other badalias handlers, but should be changed to 255 in
a later version because we use 255 for general command error.
2014-05-17 13:06:16 +09:00
Yuya Nishihara
c5b2af81b6 alias: fix loss of non-zero return code in command aliases
This also includes test for shell aliases.  It avoid using "false" command
because "man false" does not say "exit with 1" but "exit with a status code
indicating failure."
2014-05-17 14:43:06 +09:00
FUJIWARA Katsunori
0b98e91e90 dispatch: make "_checkshellalias()" invoke "findcmd()" with "strict=True"
Before this patch, shell alias may be executed by abbreviated command
name unexpectedly, even if abbreviated command name matches also
against the command provided by extension.

For example, "rebate" shell alias is executed by "hg reba", even if
rebase extension (= "rebase" command) is enabled. In this case, "hg
reba" should be aborted because of command name ambiguity.

This patch makes "_checkshellalias()" invoke "cmdutil.findcmd()"
always with "strict=True" (default value).

If abbreviated command name matches against only one shell alias even
after loading extensions, such shell alias will be executed via
"_parse()".

This patch doesn't remove "_checkshellalias()" invocation itself,
because it may prevent shell alias from loading extensions uselessly.
2014-01-29 23:47:54 +09:00
Martin Geisler
7316194bdf tests: don't load unnecessary graphlog extension
Since graphlog is in core, we can use 'hg log -G' instead.
2013-11-22 19:14:17 +01:00
Alexander Plavin
829cf92d16 log: fix behavior with empty repositories (issue3497)
Make output in this special case consistent with general case one.
2013-04-17 00:29:54 +04:00
Simon Heimberg
e0c976111f dispatch: also a separate warning message on aliases with --config
As mentioned in bug 2043, --config is also not supported in an alias. So report
this the same way as the other "early" options.

Example with alias.broken = stat --config a.config=1

Before:
  $ hg broken
  abort: Option --config may not be abbreviated!

After:
  $ hg broken
  error in definition for alias 'broken': --config may only be given on the command line
2013-02-12 22:15:31 +01:00
Mads Kiilerich
ef317883c7 export: show 'Date' header in a format that also is readable for humans
'export' is the official export format and used by patchbomb, but it would only
show date as a timestamp that most humans might find it hard to relate to. It
would be very convenient when reviewing a patch to be able to see what
timestamp the patch will end up with.

Mercurial has always used util.parsedate for parsing these headers. It can
handle 'all' date formats, so we could just as well use a readable one.

'export' will now use the format used by 'log' - which is the format described
as 'Unix date format' in the templating help. We assume that all parsers of '#
HG changeset patch'es can handle that.
2013-02-08 22:54:17 +01:00
Pierre-Yves David
292c83cd65 command: remove phase from the list of basic command
This is not a basic command. There is no reason new user should needs to know
about it. Thanks to Matt Mackall for pointing this.
2012-11-28 11:20:56 +01:00
Mads Kiilerich
ccfffc07ba tests: add missing no-outer-repo requirements
Outer repos (if any) will now never be touched by the tests. But it is better
to run without any repos around the tmp directory.
2012-06-20 23:41:21 +02:00
Mads Kiilerich
a4be6ed644 test-alias: adapt for Windows
The test used 'echo' to test '!' style aliases. On Windows 'echo' is handled
by cmd and thus behaves very differently from the 'normal' echo command.

The simple workaround used here for using the same alias on all platforms
is to use 'printf' instead. Msys 'printf' will also handle sh quoting and
escaping in cmd.

Environment variable expansion with sh syntax is handled by launching sh.
2012-06-16 21:57:42 +02:00
Mads Kiilerich
9355854f8a tests: cleanup of tests that got lost in their own nested directories
Some tests ended up in a directory several directories deeper than $TESTTMP,
usually because some 'cd ..' had been forgotten between different test cases.

Add 'cd ..' where they are missing so the tests get back where they started.
2012-06-11 01:38:32 +02:00
Olav Reinert
54cafa029d help: format command and option list help using RST
This patch changes the function which generates help text about commands and
options to use RST formatting. Tables describing options have been formatted
using RST table markup for some time already, so their appearance does not
change. Command lists, however, change appearance.

To format non-verbose command lists, RST field list markup was chosen, because
it resembles the old format:

<http://docutils.sourceforge.net/docs/user/rst/quickref.html#field-lists>

In the old (hand-coded) format of non-verbose command lists, the left column is
12 characters wide. Our minirst implementation formats field lists with a left
column 14 characters wide, so this patch changes the appearance of help output
correspondingly:

<http://markmail.org/message/krl4cxopsnii7s6z?q=mercurial+reinert+from:%22Olav+Reinert%22&page=2>

The minirst markup most closely resembling the old verbose command lists is
definition lists. But using it would cause a blank line to be inserted between
each command definition, making the output excessively long, and no more
useful than before. To avoid this, I chose to use field lists also for verbose
command help, resulting in output like this example:

 add           add the specified files on the next commit
 annotate, blame
               show changeset information by line for each file
 clone         make a copy of an existing repository
 commit, ci    commit the specified files or all outstanding changes
 diff          diff repository (or selected files)
 export        dump the header and diffs for one or more changesets
 forget        forget the specified files on the next commit
 init          create a new repository in the given directory
 log, history  show revision history of entire repository or files
 merge         merge working directory with another revision
 phase         set or show the current phase name
 pull          pull changes from the specified source
 push          push changes to the specified destination
 qdiff         diff of the current patch and subsequent modifications
 qinit         init a new queue repository (DEPRECATED)
 qnew          create a new patch
 qpop          pop the current patch off the stack
 qpush         push the next patch onto the stack
 qrefresh      update the current patch
 remove, rm    remove the specified files on the next commit
 serve         start stand-alone webserver
 status, st    show changed files in the working directory
 summary, sum  summarize working directory state
 update, up, checkout, co
               update working directory (or switch revisions)

This change is a move towards generating all help text as a list of strings
marked up with RST.
2012-06-02 11:25:40 +02:00
Patrick Mezard
9c5568246f alias: inherit command optionalrepo flag (issue3298)
Commands working without a repository, like "init", are listed in
commands.norepo. Commands optionally using a repository, like "showconfig", are
listed in commands.optionalrepo. Command aliases were inheriting the former but
not the latter.
2012-05-05 12:21:22 +02:00
Matt Mackall
3eb6e77c5e alias: abort on missing positional args (issue3331) 2012-03-27 16:13:59 -05:00
Olav Reinert
c5f1adceef help: fix column alignment in "hg help" output
The output of "hg help" is changed to ensure that the column containing
descriptions of commands, extensions, and other topics is correctly alignmened.
2012-01-11 18:14:55 +01:00
Pierre-Yves David
a2fe028df9 phases: add a phases command to display and manipulate phases 2012-01-10 19:45:35 +01:00
Matt Mackall
9e27ec8fc4 merge with stable 2011-12-01 15:57:10 -06:00
Matt Mackall
720ed4fcd7 alias: shortcut command matching show shadowing works properly (issue3104)
An alias for 'log' was stored in the same command table as
'^log|history'. If the hash function happens to give the latter first,
the alias is effectively ignored when matching 'log'.
2011-12-01 15:51:36 -06:00
Mads Kiilerich
a144f886ca tests: use 'hghave system-sh' to guard tests that requires sh in system() 2011-11-07 03:14:55 +01:00
Augie Fackler
b0cd40af6a alias: don't shadow commands that we only partially matched (issue2993) (BC)
Previously, if you set an alias for "ci", it'd also shadow "commit"
even though you didn't specify that. This occurred for all commands
with explicit short variations.
2011-10-11 17:20:03 -05:00
Matt Mackall
6435383b32 help: generate command help into a single RST string for formatting 2011-10-07 17:08:24 -05:00
Matt Mackall
ca599a1af2 alias: fix up test results 2011-07-18 14:53:52 -05:00
Matt Mackall
5ce8f05f45 dispatch: move shell alias handling after early arg handling
--cwd, --repo, and --config obviously should be handled first
2011-07-15 16:06:53 -05:00
Alexander Solovyov
325788efb7 add positional arguments to non-shell aliases 2011-05-01 12:29:32 +02:00
Adrian Buehlmann
3efb31d590 help: do not show full help text for command on option errors
Example

  $ hg clone --jump foo bar
  hg clone: option --jump not recognized
  hg clone [OPTION]... SOURCE [DEST]

  make a copy of an existing repository

  options:

   -U --noupdate           the clone will include an empty working copy (only a
                           repository)
   -u --updaterev REV      revision, tag or branch to check out
   -r --rev REV [+]        include the specified changeset
   -b --branch BRANCH [+]  clone only the specified branch
      --pull               use pull protocol to copy metadata
      --uncompressed       use uncompressed transfer (fast over LAN)
   -e --ssh CMD            specify ssh command to use
      --remotecmd CMD      specify hg command to run on the remote side
      --insecure           do not verify server certificate (ignoring
                           web.cacerts config)

  [+] marked option can be specified multiple times

  use "hg help clone" to show the full help text

Motivation for this change

  If the user already has specified the command, he probably already knows
  the command to some extent. Apparently, he has a problem with the options,
  so we show him just the synopsis with the short help and the details about
  the options, with a hint on the last line how to get the full help text.

Why is Mercurial better with this change?

  Experts who just forgot about the details of an option don't get that
  much text thrown at them, while the newbies still get a hint on the last
  line how to get the full help text.
2011-04-17 11:37:11 +02:00
Steve Losh
41f29dd66c alias: add test cases for $ escaping in shell aliases 2011-02-17 17:15:32 -05:00
Steve Losh
3171599307 alias: fall back to normal error handling for ambigious commands (fixes issue2475) 2010-11-05 15:54:32 -04:00
Steve Losh
0224e99d28 alias: fail gracefully when invalid global options are given (issue2442)
This patch modifies the check for shell aliases to prevent crashing when an invalid
global option is given.

When an invalid global option is given the check will simply return and let the
normal error handling for this case happen.
2010-10-17 13:24:37 -04:00
Adrian Buehlmann
9614229975 tests: add testcase for 2933824cb30c to test-alias.t
The testsuite lacks a testcase for the bug introduced in 2933824cb30c.

This patch amends 91db5130b446 (which fixed 2933824cb30c) by adding a
testcase for that bug.

With 2933824cb30c, test-alias.t (as modified by this patch) fails
with "hg tglog: invalid arguments".
2010-10-09 11:16:35 +02:00
Steve Losh
0ec78824a3 alias: only allow global options before a shell alias, pass later ones through
This patch refactors the dispatch code to change how arguments to shell aliases
are handled.

A separate "pass" to determine whether a command is a shell alias has been
added. The rough steps dispatch now performs when a command is given are these:

* Parse all arguments up to the command name.

* If any arguments such as --repository or --cwd are given (which could change
  the config file used, and therefore the definition of aliases), they are
  taken into account.

* We determine whether the command is a shell alias.

    * If so, execute the alias. The --repo and --cwd arguments are still in effect.
      Any arguments *after* the command name are passed unchanged through to the
      shell command (and interpolated as normal.

    * If the command is *not* a shell alias, the dispatching is effectively "reset"
      and reparsed as normal in its entirety.

The net effect of this patch is to make shell alias commands behave as you
would expect.

Any arguments you give to a shell alias *after* the alias name are passed
through unchanged. This lets you do something like the following:

    [alias]
    filereleased = !$HG log -r 'descendants(adds("$1")) and tagged()' -l1 $2 $3 $4 $5

    $ hg filereleased hgext/bookmarks.py --style compact

Previously the `--style compact` part would fail because Mercurial would
interpret those arguments as arguments to the alias command itself (which
doesn't take any arguments).

Also: running something like `hg -R ~/src/hg-crew filereleased
hgext/bookmarks.py` when `filereleased` is only defined in that repo's config
will now work.

These global arguments can *only* be given to a shell alias *before* the alias
name.  For example, this will *not* work in the above situation:

    $ hg filereleased -R ~/src/hg-crew hgext/bookmarks.py

The reason for this is that you may want to pass arguments like --repository to
the alias (or, more likely, their short versions like -R):

    [alias]
    own = !chown $@ `$HG root`

    $ hg own steve
    $ hg own -R steve
2010-08-24 18:25:33 -04:00
Matt Mackall
bf9417da11 tests: exit 0 no longer needed on unified tests 2010-09-17 17:03:04 -05:00
Matt Mackall
08439e0f2d tests: add exit codes to unified tests 2010-09-16 17:51:32 -05:00
Steve Losh
51f95d13a2 aliases: provide more flexible ways to work with shell alias arguments
This patch changes the functionality of shell aliases to add more powerful
options for working with shell alias arguments.

First: the alias name + arguments to a shell alias are set as an HG_ARGS
environment variable, delimited by spaces. This matches the behavior of hooks.

Second: any occurrences of "$@" (without quotes) are replaced with the
arguments, separated by spaces. This happens *before* the alias gets to the shell.

Third: any positive numeric variables ("$1", "$2", etc) are replaced with the
appropriate argument, indexed from 1. "$0" is replaced with the name of the
alias. Any "extra" numeric variables are replaced with an empty string.  This
happens *before* the alias gets to the shell.

These changes allow for more flexible shell aliases:

    [alias]
    echo = !echo $@
    count = !hg log -r "$@" --template='.' | wc -c | sed -e 's/ //g'
    qqueuemv = !mv "`hg root`/.hg/patches-$1" "`hg root`/.hg/patches-$2"

In action:

    $ hg echo foo
    foo

    $ hg count 'branch(default)'
    901

    $ hg count 'branch(stable) and keyword(fixes)'
    102

    $ hg qqueuemv myfeature somefeature
2010-08-18 18:56:44 -04:00
Nicolas Dumazet
051d3b42b9 tests: unify test-alias 2010-08-12 23:46:56 +09:00