Patchwork [Bug,4355] New: [urgent] Regression when executing abbreviated shell aliases with arguments

mail settings
Date Sept. 4, 2014, 7:10 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/5695/
State Not Applicable
Headers show

Comments - Sept. 4, 2014, 7:10 a.m.

          Priority: normal
            Bug ID: 4355
           Summary: [urgent] Regression when executing abbreviated shell
                    aliases with arguments
          Severity: bug
    Classification: Unclassified
                OS: Linux
          Hardware: PC
            Status: UNCONFIRMED
           Version: 3.1
         Component: Mercurial
           Product: Mercurial

[originally reported at,
turned into bug report on advise of Matt Mackall]

Commit 03d345da0579 introduced a regression when executing shell
aliases with arguments through an abbreviated form of the alias.

changeset:   20328:03d345da0579
branch:      stable
user:        FUJIWARA Katsunori <>
date:        Wed Jan 29 23:47:54 2014 +0900
summary:     dispatch: make "_checkshellalias()" invoke "findcmd()"
with "strict=True"

Following test shows the problem:

$ cat tests/test-blaat.t
  $ cat >> $HGRCPATH <<EOF
  > [alias]
  > args_foo = !echo foo \$HG_ARGS
  > EOF

abbreviated alias with arguments
  $ hg args
  foo args_foo
  $ hg args --bar
  foo args_foo --bar

Output at commit 03d345da0579:

$ (cd tests; python test-blaat.t)

ERROR: /home/tdescham/repo/contrib/hg-dev/tests/test-blaat.t output changed
Failed test-blaat.t: output changed
# Ran 1 tests, 0 skipped, 1 failed.
python hash seed: 4280300372

while output at commit 03d345da0579^:

$ (cd tests; python test-blaat.t)
# Ran 1 tests, 0 skipped, 0 failed.

I already did some analysis and found that due to the mentioned
commit, abbreviated invocations of shell aliases are not captured by
the __checkshellalias function, but instead by the later invoked
_parse method of mercurial/

In that method there are these lines:

    # combine global options into local
    for o in commands.globalopts:
        c.append((o[0], o[1], options[o[1]], o[3]))

        args = fancyopts.fancyopts(args, c, cmdoptions, True)
    except fancyopts.getopt.GetoptError, inst:
        raise error.CommandError(cmd, inst)

and the 'args' argument to fancyopts is '--bar' at this moment. The
knowledge about the alias command 'args_foo' is gone here.
fancyopts then throws the error 'unrecognized option'.


--- /home/tdescham/repo/contrib/hg-dev/tests/test-blaat.t
+++ /home/tdescham/repo/contrib/hg-dev/tests/test-blaat.t.err
@@ -7,4 +7,10 @@ 
   $ hg args
   foo args_foo
   $ hg args --bar
-  foo args_foo --bar
+  hg args_foo: option --bar not recognized
+  hg args_foo
+  shell alias for:
+  use "hg help args_foo" to show the full help text
+  [255]