Patchwork [STABLE] dispatch: make "_checkshellalias()" invoke "findcmd()" with "strict=True"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 29, 2014, 2:51 p.m.
Message ID <cda58885721d2da2490b.1391007092@juju>
Download mbox | patch
Permalink /patch/3419/
State Accepted
Commit 03d345da0579e20be357e438d0a4fe5cb9d80a8a
Headers show

Comments

Katsunori FUJIWARA - Jan. 29, 2014, 2:51 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1391006874 -32400
#      Wed Jan 29 23:47:54 2014 +0900
# Branch stable
# Node ID cda58885721d2da2490ba1397ebaf8e1bbe94eac
# Parent  427d672c0e4e07642d2400a28946cefde11e04ff
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.
Matt Mackall - Jan. 30, 2014, 8:27 p.m.
On Wed, 2014-01-29 at 23:51 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1391006874 -32400
> #      Wed Jan 29 23:47:54 2014 +0900
> # Branch stable
> # Node ID cda58885721d2da2490ba1397ebaf8e1bbe94eac
> # Parent  427d672c0e4e07642d2400a28946cefde11e04ff
> dispatch: make "_checkshellalias()" invoke "findcmd()" with "strict=True"

Queued for stable, thanks.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -635,8 +635,7 @@ 
 
     cmd = args[0]
     try:
-        aliases, entry = cmdutil.findcmd(cmd, cmdtable,
-                                         lui.configbool("ui", "strict"))
+        aliases, entry = cmdutil.findcmd(cmd, cmdtable)
     except (error.AmbiguousCommand, error.UnknownCommand):
         restorecommands()
         return
diff --git a/tests/test-alias.t b/tests/test-alias.t
--- a/tests/test-alias.t
+++ b/tests/test-alias.t
@@ -324,6 +324,21 @@ 
   $ hg escaped4 test
   $0 $@
 
+abbreviated name, which matches against both shell alias and the
+command provided extension, should be aborted.
+
+  $ cat >> .hg/hgrc <<EOF
+  > [extensions]
+  > hgext.rebase =
+  > [alias]
+  > rebate = !echo this is rebate
+  > EOF
+  $ hg reba
+  hg: command 'reba' is ambiguous:
+      rebase rebate
+  [255]
+  $ hg rebat
+  this is rebate
 
 invalid arguments