mergetool: new config guiDefault supports auto-toggling gui by DISPLAY

When no merge.tool or diff.tool is configured or manually selected, the
selection of a default tool is sensitive to the DISPLAY variable; in a
GUI session a gui-specific tool will be proposed if found, and
otherwise a terminal-based one. This "GUI-optimizing" behavior is
important because a GUI can make a huge difference to a user's ability
to understand and correctly complete a non-trivial conflicting merge.

Some time ago the merge.guitool and diff.guitool config options were
introduced to enable users to configure both a GUI tool, and a non-GUI
tool (with fallback if no GUI tool configured), in the same environment.

Unfortunately, the --gui argument introduced to support the selection of
the guitool is still explicit. When using configured tools, there is no
equivalent of the no-tool-configured "propose a GUI tool if we are in a GUI
environment" behavior.

As proposed in <xmqqmtb8jsej.fsf@gitster.g>, introduce new configuration
options, difftool.guiDefault and mergetool.guiDefault, supporting a special
value "auto" which causes the corresponding tool or guitool to be selected
depending on the presence of a non-empty DISPLAY value. Also support "true"
to say "default to the guitool (unless --no-gui is passed on the
commandline)", and "false" as the previous default behavior when these new
configuration options are not specified.

Signed-off-by: Tao Klerks <tao@klerks.biz>
Acked-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Tao Klerks
2023-03-18 15:27:43 +00:00
committed by Junio C Hamano
parent ae73b2c8f1
commit 42943b950e
10 changed files with 179 additions and 14 deletions

View File

@ -34,3 +34,10 @@ See the `--trust-exit-code` option in linkgit:git-difftool[1] for more details.
difftool.prompt::
Prompt before each invocation of the diff tool.
difftool.guiDefault::
Set `true` to use the `diff.guitool` by default (equivalent to specifying
the `--gui` argument), or `auto` to select `diff.guitool` or `diff.tool`
depending on the presence of a `DISPLAY` environment variable value. The
default is `false`, where the `--gui` argument must be provided
explicitly for the `diff.guitool` to be used.

View File

@ -85,3 +85,10 @@ mergetool.writeToTemp::
mergetool.prompt::
Prompt before each invocation of the merge resolution program.
mergetool.guiDefault::
Set `true` to use the `merge.guitool` by default (equivalent to
specifying the `--gui` argument), or `auto` to select `merge.guitool`
or `merge.tool` depending on the presence of a `DISPLAY` environment
variable value. The default is `false`, where the `--gui` argument
must be provided explicitly for the `merge.guitool` to be used.

View File

@ -97,10 +97,12 @@ instead. `--no-symlinks` is the default on Windows.
--[no-]gui::
When 'git-difftool' is invoked with the `-g` or `--gui` option
the default diff tool will be read from the configured
`diff.guitool` variable instead of `diff.tool`. The `--no-gui`
option can be used to override this setting. If `diff.guitool`
is not set, we will fallback in the order of `merge.guitool`,
`diff.tool`, `merge.tool` until a tool is found.
`diff.guitool` variable instead of `diff.tool`. This may be
selected automatically using the configuration variable
`difftool.guiDefault`. The `--no-gui` option can be used to
override these settings. If `diff.guitool` is not set, we will
fallback in the order of `merge.guitool`, `diff.tool`,
`merge.tool` until a tool is found.
--[no-]trust-exit-code::
'git-difftool' invokes a diff tool individually on each file.

View File

@ -85,12 +85,13 @@ success of the resolution after the custom tool has exited.
the default merge tool will be read from the configured
`merge.guitool` variable instead of `merge.tool`. If
`merge.guitool` is not set, we will fallback to the tool
configured under `merge.tool`.
configured under `merge.tool`. This may be autoselected using
the configuration variable `mergetool.guiDefault`.
--no-gui::
This overrides a previous `-g` or `--gui` setting and reads the
default merge tool will be read from the configured `merge.tool`
variable.
This overrides a previous `-g` or `--gui` setting or
`mergetool.guiDefault` configuration and reads the default merge
tool from the configured `merge.tool` variable.
-O<orderfile>::
Process files in the order specified in the