[PATCH 1 of 3 STABLE V2] alias: fix loss of non-zero return code in command aliases

Yuya Nishihara yuya at tcha.org
Sat May 17 02:24:29 CDT 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1400305386 -32400
#      Sat May 17 14:43:06 2014 +0900
# Branch stable
# Node ID 4150225f465f99f7cf07fefd0b03933bed380efa
# Parent  54d7657d7d1e6a62315eea53f4498657e766bb60
alias: fix loss of non-zero return code in command aliases

This also includes test for shell aliases.  It avoid using "false" command
because "man false" does not say "exit with 1" but "exit with a status code
indicating failure."

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -445,7 +445,7 @@ class cmdalias(object):
             return self.fn(ui, *args, **opts)
         else:
             try:
-                util.checksignature(self.fn)(ui, *args, **opts)
+                return util.checksignature(self.fn)(ui, *args, **opts)
             except error.SignatureError:
                 args = ' '.join([self.cmdname] + self.args)
                 ui.debug("alias '%s' expands to '%s'\n" % (self.name, args))
diff --git a/tests/test-alias.t b/tests/test-alias.t
--- a/tests/test-alias.t
+++ b/tests/test-alias.t
@@ -4,6 +4,7 @@
   > # should clobber ci but not commit (issue2993)
   > ci = version
   > myinit = init
+  > mycommit = commit
   > optionalrepo = showconfig alias.myinit
   > cleanstatus = status -c
   > unknown = bargle
@@ -41,6 +42,7 @@
   > escaped2 = !sh -c 'echo "HGFOO is \$\$HGFOO"'
   > escaped3 = !sh -c 'echo "\$1 is \$\$\$1"'
   > escaped4 = !printf '\$\$0 \$\$@\n'
+  > exit1 = !sh -c 'exit 1'
   > 
   > [defaults]
   > mylog = -q
@@ -58,6 +60,7 @@ unknown
 
   $ hg unknown
   alias 'unknown' resolves to unknown command 'bargle'
+  [1]
   $ hg help unknown
   alias 'unknown' resolves to unknown command 'bargle'
 
@@ -66,6 +69,7 @@ ambiguous
 
   $ hg ambiguous
   alias 'ambiguous' resolves to ambiguous command 's'
+  [1]
   $ hg help ambiguous
   alias 'ambiguous' resolves to ambiguous command 's'
 
@@ -74,6 +78,7 @@ recursive
 
   $ hg recursive
   alias 'recursive' resolves to unknown command 'recursive'
+  [1]
   $ hg help recursive
   alias 'recursive' resolves to unknown command 'recursive'
 
@@ -82,6 +87,7 @@ no definition
 
   $ hg nodef
   no definition for alias 'nodefinition'
+  [1]
   $ hg help nodef
   no definition for alias 'nodefinition'
 
@@ -90,22 +96,27 @@ invalid options
 
   $ hg no--cwd
   error in definition for alias 'no--cwd': --cwd may only be given on the command line
+  [1]
   $ hg help no--cwd
   error in definition for alias 'no--cwd': --cwd may only be given on the command line
   $ hg no-R
   error in definition for alias 'no-R': -R may only be given on the command line
+  [1]
   $ hg help no-R
   error in definition for alias 'no-R': -R may only be given on the command line
   $ hg no--repo
   error in definition for alias 'no--repo': --repo may only be given on the command line
+  [1]
   $ hg help no--repo
   error in definition for alias 'no--repo': --repo may only be given on the command line
   $ hg no--repository
   error in definition for alias 'no--repository': --repository may only be given on the command line
+  [1]
   $ hg help no--repository
   error in definition for alias 'no--repository': --repository may only be given on the command line
   $ hg no--config
   error in definition for alias 'no--config': --config may only be given on the command line
+  [1]
 
 optional repository
 
@@ -125,6 +136,7 @@ no usage
 
   $ hg nousage
   no rollback information available
+  [1]
 
   $ echo foo > foo
   $ hg commit -Amfoo
@@ -442,3 +454,11 @@ This shouldn't:
   $ hg --config alias.log='id' history
 
   $ cd ../..
+
+return code of command and shell aliases:
+
+  $ hg mycommit -R alias
+  nothing changed
+  [1]
+  $ hg exit1
+  [1]


More information about the Mercurial-devel mailing list