[PATCH 2 of 3 STABLE V2] alias: handle shlex error in command aliases

Yuya Nishihara yuya at tcha.org
Sat May 17 02:24:30 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 720d61883ab5965725a01dcad31241e74478b785
# Parent  4150225f465f99f7cf07fefd0b03933bed380efa
alias: handle shlex error in command aliases

No command should fail with ValueError just because there is unparseable
alias definition.

It returns 1 like other badalias handlers, but should be changed to 255 in
a later version because we use 255 for general command error.

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
@@ -11,6 +11,7 @@
   > ambiguous = s
   > recursive = recursive
   > nodefinition =
+  > noclosingquotation = '
   > no--cwd = status --cwd elsewhere
   > no-R = status -R elsewhere
   > no--repo = status --repo elsewhere
@@ -92,6 +93,15 @@ no definition
   no definition for alias 'nodefinition'
 
 
+no closing quotation
+
+  $ hg noclosing
+  error in definition for alias 'noclosingquotation': No closing quotation
+  [1]
+  $ 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