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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Jan 29 08:51:32 CST 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at 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.

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
 


More information about the Mercurial-devel mailing list