[PATCH 1 of 2] help: don't display bogus help messages for invalid aliases
Brodie Rao
dackze at gmail.com
Sun Dec 6 01:12:05 CST 2009
# HG changeset patch
# User Brodie Rao <me+hg at dackz.net>
# Date 1260073587 18000
# Node ID 29df34f954641a1e0b348cb8484bc8bb67d7aba3
# Parent 253d0da256b2b4becf68cc2c5a877e41e6a19abe
help: don't display bogus help messages for invalid aliases
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1486,6 +1486,11 @@ def help_(ui, name=None, with_version=Fa
helplist(_('list of commands:\n\n'), select)
return
+ # check if it's an invalid alias and display its error if it is
+ if getattr(entry[0], 'badalias', False):
+ entry[0](ui)
+ return
+
# synopsis
if len(entry) > 2:
if entry[2].startswith('hg'):
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -177,6 +177,7 @@ class cmdalias(object):
self.opts = []
self.help = ''
self.norepo = True
+ self.badalias = False
try:
cmdutil.findcmd(self.name, cmdtable, True)
@@ -189,6 +190,7 @@ class cmdalias(object):
ui.warn(_("no definition for alias '%s'\n") % self.name)
return 1
self.fn = fn
+ self.badalias = True
return
@@ -217,12 +219,14 @@ class cmdalias(object):
% (self.name, cmd))
return 1
self.fn = fn
+ self.badalias = True
except error.AmbiguousCommand:
def fn(ui, *args):
ui.warn(_("alias '%s' resolves to ambiguous command '%s'\n") \
% (self.name, cmd))
return 1
self.fn = fn
+ self.badalias = True
def __call__(self, ui, *args, **opts):
if self.shadows:
diff --git a/tests/test-alias b/tests/test-alias
--- a/tests/test-alias
+++ b/tests/test-alias
@@ -25,15 +25,19 @@ hg myinit alias
echo '% unknown'
hg unknown
+hg help unknown
echo '% ambiguous'
hg ambiguous
+hg help ambiguous
echo '% recursive'
hg recursive
+hg help recursive
echo '% no definition'
hg nodef
+hg help nodef
cd alias
diff --git a/tests/test-alias.out b/tests/test-alias.out
--- a/tests/test-alias.out
+++ b/tests/test-alias.out
@@ -1,12 +1,16 @@
% basic
% unknown
alias 'unknown' resolves to unknown command 'bargle'
+alias 'unknown' resolves to unknown command 'bargle'
% ambiguous
alias 'ambiguous' resolves to ambiguous command 's'
+alias 'ambiguous' resolves to ambiguous command 's'
% recursive
alias 'recursive' resolves to unknown command 'recursive'
+alias 'recursive' resolves to unknown command 'recursive'
% no definition
no definition for alias 'nodefinition'
+no definition for alias 'nodefinition'
% no usage
no rollback information available
adding foo
More information about the Mercurial-devel
mailing list