changeset 21556:5e13507a3b4e stable

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."
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 May 2014 14:43:06 +0900
parents 565d45919db8
children 5d048061f222 2e91d4964ecd
files mercurial/dispatch.py tests/test-alias.t
diffstat 2 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Thu May 15 23:53:21 2014 -0700
+++ b/mercurial/dispatch.py	Sat May 17 14:43:06 2014 +0900
@@ -445,7 +445,7 @@
             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))
--- a/tests/test-alias.t	Thu May 15 23:53:21 2014 -0700
+++ b/tests/test-alias.t	Sat May 17 14:43:06 2014 +0900
@@ -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 @@
 
   $ hg unknown
   alias 'unknown' resolves to unknown command 'bargle'
+  [1]
   $ hg help unknown
   alias 'unknown' resolves to unknown command 'bargle'
 
@@ -66,6 +69,7 @@
 
   $ hg ambiguous
   alias 'ambiguous' resolves to ambiguous command 's'
+  [1]
   $ hg help ambiguous
   alias 'ambiguous' resolves to ambiguous command 's'
 
@@ -74,6 +78,7 @@
 
   $ hg recursive
   alias 'recursive' resolves to unknown command 'recursive'
+  [1]
   $ hg help recursive
   alias 'recursive' resolves to unknown command 'recursive'
 
@@ -82,6 +87,7 @@
 
   $ hg nodef
   no definition for alias 'nodefinition'
+  [1]
   $ hg help nodef
   no definition for alias 'nodefinition'
 
@@ -90,22 +96,27 @@
 
   $ 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 @@
 
   $ hg nousage
   no rollback information available
+  [1]
 
   $ echo foo > foo
   $ hg commit -Amfoo
@@ -442,3 +454,11 @@
   $ hg --config alias.log='id' history
 
   $ cd ../..
+
+return code of command and shell aliases:
+
+  $ hg mycommit -R alias
+  nothing changed
+  [1]
+  $ hg exit1
+  [1]