[PATCH STABLE] alias: handle shlex error in command aliases
Yuya Nishihara
yuya at tcha.org
Fri May 16 23:37:54 CDT 2014
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1400299576 -32400
# Sat May 17 13:06:16 2014 +0900
# Branch stable
# Node ID 83696824c83f8a8a28ea02bf482c63d9d79a089d
# Parent 54d7657d7d1e6a62315eea53f4498657e766bb60
alias: handle shlex error in command aliases
No command should fail with ValueError just because there is unparseable
alias definition.
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -383,7 +383,16 @@ class cmdalias(object):
self.fn = fn
return
- args = shlex.split(self.definition)
+ try:
+ args = shlex.split(self.definition)
+ except ValueError, inst:
+ def fn(ui, *args):
+ ui.warn(_("error in definition for alias '%s': %s\n")
+ % (self.name, inst))
+ return 1
+ self.fn = fn
+ self.badalias = True
+ return
self.cmdname = cmd = args.pop(0)
args = map(util.expandpath, args)
diff --git a/tests/test-alias.t b/tests/test-alias.t
--- a/tests/test-alias.t
+++ b/tests/test-alias.t
@@ -10,6 +10,7 @@
> ambiguous = s
> recursive = recursive
> nodefinition =
+ > noclosingquotation = '
> no--cwd = status --cwd elsewhere
> no-R = status -R elsewhere
> no--repo = status --repo elsewhere
@@ -86,6 +87,14 @@ no definition
no definition for alias 'nodefinition'
+no closing quotation
+
+ $ hg noclosing
+ error in definition for alias 'noclosingquotation': No closing quotation
+ $ hg help noclosing
+ error in definition for alias 'noclosingquotation': No closing quotation
+
+
invalid options
$ hg no--cwd
More information about the Mercurial-devel
mailing list