From patchwork Thu Sep 4 07:10:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Bug, 4355] New: [urgent] Regression when executing abbreviated shell aliases with arguments From: mercurial-bugs@selenic.com X-Patchwork-Id: 5695 Message-Id: To: mercurial-devel@selenic.com Date: Thu, 04 Sep 2014 07:10:33 +0000 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 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 < [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'. --- /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]