Skip to content

Commit

Permalink
difftool: make --gui, --tool and --extcmd mutually exclusive
Browse files Browse the repository at this point in the history
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 <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Denton-L authored and gitster committed May 13, 2019
1 parent 60aced3 commit 7f978d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);

if (use_gui_tool + !!difftool_cmd + !!extcmd > 1)
die(_("--gui, --tool and --extcmd are mutually exclusive"));

if (use_gui_tool && diff_gui_tool && *diff_gui_tool)
setenv("GIT_DIFF_TOOL", diff_gui_tool, 1);
else if (difftool_cmd) {
Expand Down
8 changes: 8 additions & 0 deletions t/t7800-difftool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -705,4 +705,12 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
test_cmp expect actual
'

test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive' '
difftool_test_setup &&
test_must_fail git difftool --gui --tool=test-tool &&
test_must_fail git difftool --gui --extcmd=cat &&
test_must_fail git difftool --tool=test-tool --extcmd=cat &&
test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
'

test_done

0 comments on commit 7f978d7

Please sign in to comment.