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:

committed by
Junio C Hamano

parent
ae73b2c8f1
commit
42943b950e
@ -685,7 +685,7 @@ static int run_file_diff(int prompt, const char *prefix,
|
||||
|
||||
int cmd_difftool(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
int use_gui_tool = 0, dir_diff = 0, prompt = -1, symlinks = 0,
|
||||
int use_gui_tool = -1, dir_diff = 0, prompt = -1, symlinks = 0,
|
||||
tool_help = 0, no_index = 0;
|
||||
static char *difftool_cmd = NULL, *extcmd = NULL;
|
||||
struct option builtin_difftool_options[] = {
|
||||
@ -735,13 +735,21 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
|
||||
} else if (dir_diff)
|
||||
die(_("options '%s' and '%s' cannot be used together"), "--dir-diff", "--no-index");
|
||||
|
||||
die_for_incompatible_opt3(use_gui_tool, "--gui",
|
||||
die_for_incompatible_opt3(use_gui_tool == 1, "--gui",
|
||||
!!difftool_cmd, "--tool",
|
||||
!!extcmd, "--extcmd");
|
||||
|
||||
if (use_gui_tool)
|
||||
/*
|
||||
* Explicitly specified GUI option is forwarded to git-mergetool--lib.sh;
|
||||
* empty or unset means "use the difftool.guiDefault config or default to
|
||||
* false".
|
||||
*/
|
||||
if (use_gui_tool == 1)
|
||||
setenv("GIT_MERGETOOL_GUI", "true", 1);
|
||||
else if (difftool_cmd) {
|
||||
else if (use_gui_tool == 0)
|
||||
setenv("GIT_MERGETOOL_GUI", "false", 1);
|
||||
|
||||
if (difftool_cmd) {
|
||||
if (*difftool_cmd)
|
||||
setenv("GIT_DIFF_TOOL", difftool_cmd, 1);
|
||||
else
|
||||
|
Reference in New Issue
Block a user