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

login
register
mail settings
Submitter mercurial-bugs@selenic.com
Date Sept. 4, 2014, 7:10 a.m.
Message ID <bug-4355-285@http.bz.selenic.com/>
Download mbox | patch
Permalink /patch/5695/
State Not Applicable
Headers show

Comments

mercurial-bugs@selenic.com - Sept. 4, 2014, 7:10 a.m.
http://bz.selenic.com/show_bug.cgi?id=4355

          Priority: normal
            Bug ID: 4355
                CC: mercurial-devel@selenic.com
          Assignee: bugzilla@selenic.com
           Summary: [urgent] Regression when executing abbreviated shell
                    aliases with arguments
          Severity: bug
    Classification: Unclassified
                OS: Linux
          Reporter: patrickdepinguin+mercurial@gmail.com
          Hardware: PC
            Status: UNCONFIRMED
           Version: 3.1
         Component: Mercurial
           Product: Mercurial

[originally reported at
http://www.selenic.com/pipermail/mercurial-devel/2014-September/061345.html,
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 <foozy@lares.dti.ne.jp>
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 run-tests.py 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 run-tests.py 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/dispatch.py.

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]))

    try:
        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'.

Patch

--- /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]