Mercurial > public > mercurial-scm > hg-stable
diff hgext/extdiff.py @ 52050:d1b54c152673
extdiff: don't run gui programs when in a cli-only environment
In order to provide a useful error message to override the behavior, we also
need to slightly change the way that tool.gui is found in the config. Before,
it had to be where tool.diffargs is located, which might not exist. Now,
tool.isgui can exist on its own.
A test is added for the new error message. We also need to force
procutil.isgui() to return true, so we set $DISPLAY to a non-empty value
before running any test expecting to have a gui.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 04 Feb 2019 23:32:20 -0800 |
parents | f4733654f144 |
children | 4cb75772818d |
line wrap: on
line diff
--- a/hgext/extdiff.py Wed Dec 28 21:33:44 2022 -0800 +++ b/hgext/extdiff.py Mon Feb 04 23:32:20 2019 -0800 @@ -729,16 +729,24 @@ to its parent. """ - def __init__(self, path, cmdline, isgui): + def __init__(self, cmd, path, cmdline, isgui): # We can't pass non-ASCII through docstrings (and path is # in an unknown encoding anyway), but avoid double separators on # Windows docpath = stringutil.escapestr(path).replace(b'\\\\', b'\\') self.__doc__ %= {'path': pycompat.sysstr(stringutil.uirepr(docpath))} + self._name = cmd self._cmdline = cmdline self._isgui = isgui def __call__(self, ui, repo, *pats, **opts): + if self._isgui and not procutil.gui(): + msg = _(b"tool '%s' requires a GUI") % self._name + hint = ( + _(b"to override, use: --config diff-tools.%s.gui=False") + % self._name + ) + raise error.Abort(msg, hint=hint) opts = pycompat.byteskwargs(opts) options = b' '.join(map(procutil.shellquote, opts[b'option'])) if options: @@ -798,9 +806,15 @@ args = ui.config(section, key) if args: cmdline += b' ' + args - if isgui is None: - isgui = ui.configbool(section, cmd + b'.gui') or False break + if isgui is None: + key = cmd + b'.gui' + for section in (b'diff-tools', b'merge-tools'): + isgui = ui.configbool(section, key) + if isgui is not None: + break + if isgui is None: + isgui = False return cmd, path, cmdline, isgui @@ -815,7 +829,7 @@ _(b'hg %s [OPTION]... [FILE]...') % cmd, helpcategory=command.CATEGORY_FILE_CONTENTS, inferrepo=True, - )(savedcmd(path, cmdline, isgui)) + )(savedcmd(cmd, path, cmdline, isgui)) # tell hggettext to extract docstrings from these functions: