# HG changeset patch # User timeless # Date 2016-04-08 18:35:49 # Node ID 3640c1702c433c782251db1e2999e4718d2deb3e # Parent 1e184241de5176c6cebcaa65cbe6a75d7901b754 help: report source of aliases diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -379,7 +379,7 @@ def aliasinterpolate(name, args, cmd): return r.sub(lambda x: replacemap[x.group()], cmd) class cmdalias(object): - def __init__(self, name, definition, cmdtable): + def __init__(self, name, definition, cmdtable, source): self.name = self.cmd = name self.cmdname = '' self.definition = definition @@ -389,6 +389,7 @@ class cmdalias(object): self.help = '' self.badalias = None self.unknowncmd = False + self.source = source try: aliases, entry = cmdutil.findcmd(self.name, cmdtable) @@ -499,7 +500,8 @@ def addaliases(ui, cmdtable): # may use extension commands. Aliases can also use other alias definitions, # but only if they have been defined prior to the current definition. for alias, definition in ui.configitems('alias'): - aliasdef = cmdalias(alias, definition, cmdtable) + source = ui.configsource('alias', alias) + aliasdef = cmdalias(alias, definition, cmdtable, source) try: olddef = cmdtable[aliasdef.cmd][0] diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -336,10 +336,13 @@ def help_(ui, name, unknowncmd=False, fu if not doc: doc = _("(no help text available)") if util.safehasattr(entry[0], 'definition'): # aliased command + source = entry[0].source if entry[0].definition.startswith('!'): # shell alias - doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] + doc = (_('shell alias for::\n\n %s\n\ndefined by: %s\n') % + (entry[0].definition[1:], source)) else: - doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) + doc = (_('alias for: hg %s\n\n%s\n\ndefined by: %s\n') % + (entry[0].definition, doc, source)) doc = doc.splitlines(True) if ui.quiet or not full: rst.append(doc[0]) diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -673,10 +673,50 @@ this is a section and erroring out weird > def nohelp(ui, *args, **kwargs): > pass > + > def uisetup(ui): + > ui.setconfig('alias', 'shellalias', '!echo hi', 'helpext') + > ui.setconfig('alias', 'hgalias', 'summary', 'helpext') + > > EOF $ echo '[extensions]' >> $HGRCPATH $ echo "helpext = `pwd`/helpext.py" >> $HGRCPATH +Test for aliases + + $ hg help hgalias + hg hgalias [--remote] + + alias for: hg summary + + summarize working directory state + + This generates a brief summary of the working directory state, including + parents, branch, commit status, phase and available updates. + + With the --remote option, this will check the default paths for incoming + and outgoing changes. This can be time-consuming. + + Returns 0 on success. + + defined by: helpext + + options: + + --remote check for push and pull + + (some details hidden, use --verbose to show complete help) + + $ hg help shellalias + hg shellalias + + shell alias for: + + echo hi + + defined by: helpext + + (some details hidden, use --verbose to show complete help) + Test command with no help text $ hg help nohelp @@ -2064,6 +2104,13 @@ Dish up an empty repo; serve it cold. show help for a given topic or a help overview + + hgalias + + + summarize working directory state + + identify @@ -2155,6 +2202,13 @@ Dish up an empty repo; serve it cold. print the root (top) of the current working directory + + shellalias + + + (no help text available) + + tag