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