changeset 22378:c828b61e0635

merge with stable
author Augie Fackler <raf@durin42.com>
date Tue, 09 Sep 2014 13:47:50 -0400
parents 308ab71207ff (current diff) f98abe3146b2 (diff)
children 38a393d59e77
files mercurial/dispatch.py tests/test-alias.t
diffstat 2 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Tue Sep 02 11:28:44 2014 +0200
+++ b/mercurial/dispatch.py	Tue Sep 09 13:47:50 2014 -0400
@@ -636,7 +636,12 @@
 
     return path, lui
 
-def _checkshellalias(lui, ui, args):
+def _checkshellalias(lui, ui, args, precheck=True):
+    """Return the function to run the shell alias, if it is required
+
+    'precheck' is whether this function is invoked before adding
+    aliases or not.
+    """
     options = {}
 
     try:
@@ -647,18 +652,24 @@
     if not args:
         return
 
-    norepo = commands.norepo
-    optionalrepo = commands.optionalrepo
-    def restorecommands():
-        commands.norepo = norepo
-        commands.optionalrepo = optionalrepo
-
-    cmdtable = commands.table.copy()
-    addaliases(lui, cmdtable)
+    if precheck:
+        strict = True
+        norepo = commands.norepo
+        optionalrepo = commands.optionalrepo
+        def restorecommands():
+            commands.norepo = norepo
+            commands.optionalrepo = optionalrepo
+        cmdtable = commands.table.copy()
+        addaliases(lui, cmdtable)
+    else:
+        strict = False
+        def restorecommands():
+            pass
+        cmdtable = commands.table
 
     cmd = args[0]
     try:
-        aliases, entry = cmdutil.findcmd(cmd, cmdtable)
+        aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict)
     except (error.AmbiguousCommand, error.UnknownCommand):
         restorecommands()
         return
@@ -715,6 +726,14 @@
 
     addaliases(lui, commands.table)
 
+    if not lui.configbool("ui", "strict"):
+        # All aliases and commands are completely defined, now.
+        # Check abbreviation/ambiguity of shell alias again, because shell
+        # alias may cause failure of "_parse" (see issue4355)
+        shellaliasfn = _checkshellalias(lui, ui, args, precheck=False)
+        if shellaliasfn:
+            return shellaliasfn()
+
     # check for fallback encoding
     fallback = lui.config('ui', 'fallbackencoding')
     if fallback:
--- a/tests/test-alias.t	Tue Sep 02 11:28:44 2014 +0200
+++ b/tests/test-alias.t	Tue Sep 09 13:47:50 2014 -0400
@@ -394,7 +394,7 @@
   > [extensions]
   > hgext.rebase =
   > [alias]
-  > rebate = !echo this is rebate
+  > rebate = !echo this is \$HG_ARGS
   > EOF
   $ hg reba
   hg: command 'reba' is ambiguous:
@@ -402,6 +402,8 @@
   [255]
   $ hg rebat
   this is rebate
+  $ hg rebat --foo-bar
+  this is rebate --foo-bar
 
 invalid arguments