Skip to content

Commit 6c22d71

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f978d7 commit 6c22d71

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Documentation/git-difftool.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ instead. `--no-symlinks` is the default on Windows.
9090
When 'git-difftool' is invoked with the `-g` or `--gui` option
9191
the default diff tool will be read from the configured
9292
`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.
9496

9597
--[no-]trust-exit-code::
9698
'git-difftool' invokes a diff tool individually on each file.

builtin/difftool.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "object-store.h"
2424
#include "dir.h"
2525

26-
static char *diff_gui_tool;
2726
static int trust_exit_code;
2827

2928
static const char *const builtin_difftool_usage[] = {
@@ -33,11 +32,6 @@ static const char *const builtin_difftool_usage[] = {
3332

3433
static int difftool_config(const char *var, const char *value, void *cb)
3534
{
36-
if (!strcmp(var, "diff.guitool")) {
37-
diff_gui_tool = xstrdup(value);
38-
return 0;
39-
}
40-
4135
if (!strcmp(var, "difftool.trustexitcode")) {
4236
trust_exit_code = git_config_bool(var, value);
4337
return 0;
@@ -733,8 +727,8 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
733727
if (use_gui_tool + !!difftool_cmd + !!extcmd > 1)
734728
die(_("--gui, --tool and --extcmd are mutually exclusive"));
735729

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);
738732
else if (difftool_cmd) {
739733
if (*difftool_cmd)
740734
setenv("GIT_DIFF_TOOL", difftool_cmd, 1);

t/t7800-difftool.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,27 @@ test_expect_success 'difftool + mergetool config variables' '
279279
echo branch >expect &&
280280
git difftool --no-prompt branch >actual &&
281281
test_cmp expect actual &&
282+
git difftool --gui --no-prompt branch >actual &&
283+
test_cmp expect actual &&
282284
283285
# set merge.tool to something bogus, diff.tool to test-tool
284286
test_config merge.tool bogus-tool &&
285287
test_config diff.tool test-tool &&
286288
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 &&
287303
test_cmp expect actual
288304
'
289305

0 commit comments

Comments
 (0)