Skip to content

Commit 7f978d7

Browse files
Denton-Lgitster
authored andcommitted
difftool: make --gui, --tool and --extcmd mutually exclusive
In git-difftool, these options specify which tool to ultimately run. As a result, they are logically conflicting. Explicitly disallow these options from being used together. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 60aced3 commit 7f978d7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

builtin/difftool.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
730730
setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
731731
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
732732

733+
if (use_gui_tool + !!difftool_cmd + !!extcmd > 1)
734+
die(_("--gui, --tool and --extcmd are mutually exclusive"));
735+
733736
if (use_gui_tool && diff_gui_tool && *diff_gui_tool)
734737
setenv("GIT_DIFF_TOOL", diff_gui_tool, 1);
735738
else if (difftool_cmd) {

t/t7800-difftool.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,4 +705,12 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
705705
test_cmp expect actual
706706
'
707707

708+
test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive' '
709+
difftool_test_setup &&
710+
test_must_fail git difftool --gui --tool=test-tool &&
711+
test_must_fail git difftool --gui --extcmd=cat &&
712+
test_must_fail git difftool --tool=test-tool --extcmd=cat &&
713+
test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
714+
'
715+
708716
test_done

0 commit comments

Comments
 (0)