difftool: fallback on merge.guitool

In git-difftool.txt, it says 'git difftool' falls back to 'git mergetool' config variables when the difftool equivalents have not been defined. However, when `diff.guitool` is missing, it doesn't fallback to anything. Make git-difftool fallback to `merge.guitool` when `diff.guitool` is missing. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Apr 29, 2019 at 02:21 UTC 6c22d715e7b4067a6865ff3fbceab991d0042c12
3 files changed +21 -9
Documentation/git-difftool.txt
+3 -1
@@ -90,7 +90,9 @@ instead. `--no-symlinks` is the default on Windows.
90 When 'git-difftool' is invoked with the `-g` or `--gui` option
91 the default diff tool will be read from the configured
92 `diff.guitool` variable instead of `diff.tool`. The `--no-gui`
93 - option can be used to override this setting.
93 + option can be used to override this setting. If `diff.guitool`
94 + is not set, we will fallback in the order of `merge.guitool`,
95 + `diff.tool`, `merge.tool` until a tool is found.
96
97 --[no-]trust-exit-code::
98 'git-difftool' invokes a diff tool individually on each file.
builtin/difftool.c
+2 -8
@@ -23,7 +23,6 @@
23 #include "object-store.h"
24 #include "dir.h"
25
26 -static char *diff_gui_tool;
26 static int trust_exit_code;
27
28 static const char *const builtin_difftool_usage[] = {
@@ -33,11 +32,6 @@ static const char *const builtin_difftool_usage[] = {
32
33 static int difftool_config(const char *var, const char *value, void *cb)
34 {
36 - if (!strcmp(var, "diff.guitool")) {
37 - diff_gui_tool = xstrdup(value);
38 - return 0;
39 - }
40 -
35 if (!strcmp(var, "difftool.trustexitcode")) {
36 trust_exit_code = git_config_bool(var, value);
37 return 0;
@@ -733,8 +727,8 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
727 if (use_gui_tool + !!difftool_cmd + !!extcmd > 1)
728 die(_("--gui, --tool and --extcmd are mutually exclusive"));
729
736 - if (use_gui_tool && diff_gui_tool && *diff_gui_tool)
737 - setenv("GIT_DIFF_TOOL", diff_gui_tool, 1);
730 + if (use_gui_tool)
731 + setenv("GIT_MERGETOOL_GUI", "true", 1);
732 else if (difftool_cmd) {
733 if (*difftool_cmd)
734 setenv("GIT_DIFF_TOOL", difftool_cmd, 1);
t/t7800-difftool.sh
+16
@@ -279,11 +279,27 @@ test_expect_success 'difftool + mergetool config variables' '
279 echo branch >expect &&
280 git difftool --no-prompt branch >actual &&
281 test_cmp expect actual &&
282 + git difftool --gui --no-prompt branch >actual &&
283 + test_cmp expect actual &&
284
285 # set merge.tool to something bogus, diff.tool to test-tool
286 test_config merge.tool bogus-tool &&
287 test_config diff.tool test-tool &&
288 git difftool --no-prompt branch >actual &&
289 + test_cmp expect actual &&
290 + git difftool --gui --no-prompt branch >actual &&
291 + test_cmp expect actual &&
292 +
293 + # set merge.tool, diff.tool to something bogus, merge.guitool to test-tool
294 + test_config diff.tool bogus-tool &&
295 + test_config merge.guitool test-tool &&
296 + git difftool --gui --no-prompt branch >actual &&
297 + test_cmp expect actual &&
298 +
299 + # set merge.tool, diff.tool, merge.guitool to something bogus, diff.guitool to test-tool
300 + test_config merge.guitool bogus-tool &&
301 + test_config diff.guitool test-tool &&
302 + git difftool --gui --no-prompt branch >actual &&
303 test_cmp expect actual
304 '
305