# HG changeset patch # User Augie Fackler # Date 1410284870 14400 # Node ID c828b61e06355748cca92890ab7f137cbdc42966 # Parent 308ab71207ffeacc9f0a911cb0245c6949bbce73# Parent f98abe3146b24a1e50e1c554850fbe5a8994d4fc merge with stable diff -r 308ab71207ff -r c828b61e0635 mercurial/dispatch.py --- 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: diff -r 308ab71207ff -r c828b61e0635 tests/test-alias.t --- 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