# HG changeset patch # User Augie Fackler # Date 2017-02-21 19:20:05 # Node ID ab20491b1760f725cf45bc9a1c735a9e3bfce86d # Parent 2a0c8e3636b0fea03c9062c91563ec14431cd597 dispatch: rearrange 'unknown command' code to better employ pager dispatch calls help like a ninja if you give it a truly unknown command, and that might want to be paged. If it gets paged, then the 'hg: unknown command' text gets eaten by a grue, unless we call the pager first. This change rearranges the codepaths so we can safely only invoke the pager in the case where we'll have long output from the help command code, rather than just a short message like "did you mean stat instead of start" or "fetch is provided by the fetch extension". diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -33,6 +33,7 @@ from . import ( extensions, fancyopts, fileset, + help, hg, hook, profiling, @@ -242,19 +243,24 @@ def callcatch(ui, func): _formatparse(ui.warn, inst) return -1 except error.UnknownCommand as inst: - ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) + nocmdmsg = _("hg: unknown command '%s'\n") % inst.args[0] try: # check if the command is in a disabled extension # (but don't check for extensions themselves) - commands.help_(ui, inst.args[0], unknowncmd=True) + formatted = help.formattedhelp(ui, inst.args[0], unknowncmd=True) + ui.warn(nocmdmsg) + ui.write(formatted) except (error.UnknownCommand, error.Abort): suggested = False if len(inst.args) == 2: sim = _getsimilar(inst.args[1], inst.args[0]) if sim: + ui.warn(nocmdmsg) _reportsimilar(ui.warn, sim) suggested = True if not suggested: + ui.pager('help') + ui.warn(nocmdmsg) commands.help_(ui, 'shortlist') except IOError: raise