diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -64,9 +64,15 @@ def _pythonhook(ui, repo, name, hname, f ui.warn(_('exception from second failed import ' 'attempt:\n')) ui.traceback(e2) + + if not ui.tracebackflag: + tracebackhint = _( + 'run with --traceback for stack trace') + else: + tracebackhint = None raise error.HookLoadError( _('%s hook is invalid: import of "%s" failed') % - (hname, modname)) + (hname, modname), hint=tracebackhint) sys.path = oldpaths try: for p in funcname.split('.')[1:]: diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -505,6 +505,7 @@ test python hooks pulling from ../a searching for changes abort: preoutgoing.badmodule hook is invalid: import of "nomodule" failed + (run with --traceback for stack trace) [255] $ echo '[hooks]' > ../a/.hg/hgrc @@ -513,6 +514,7 @@ test python hooks pulling from ../a searching for changes abort: preoutgoing.unreachable hook is invalid: import of "hooktests.container" failed + (run with --traceback for stack trace) [255] $ echo '[hooks]' > ../a/.hg/hgrc