Skip to content

Commit

Permalink
Merge branch 'pb/mergetool-errors' into seen
Browse files Browse the repository at this point in the history
* pb/mergetool-errors:
  git-difftool--helper.sh: exit upon initialize_merge_tool errors
  git-mergetool--lib.sh: add error message for unknown tool variant
  git-mergetool--lib.sh: add error message in 'setup_user_tool'
  git-mergetool--lib.sh: use TOOL_MODE when erroring about unknown tool
  completion: complete '--tool-help' in 'git mergetool'
  • Loading branch information
gitster committed Nov 13, 2024
2 parents 871392d + cf5a972 commit a35aba8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ _git_mergetool ()
return
;;
--*)
__gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
__gitcomp "--tool= --tool-help --prompt --no-prompt --gui --no-gui"
return
;;
esac
Expand Down
8 changes: 2 additions & 6 deletions git-difftool--helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ launch_merge_tool () {
export BASE
eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
else
initialize_merge_tool "$merge_tool"
# ignore the error from the above --- run_merge_tool
# will diagnose unusable tool by itself
initialize_merge_tool "$merge_tool" || exit 1
run_merge_tool "$merge_tool"
fi
}
Expand All @@ -87,9 +85,7 @@ if test -n "$GIT_DIFFTOOL_DIRDIFF"
then
LOCAL="$1"
REMOTE="$2"
initialize_merge_tool "$merge_tool"
# ignore the error from the above --- run_merge_tool
# will diagnose unusable tool by itself
initialize_merge_tool "$merge_tool" || exit 1
run_merge_tool "$merge_tool" false

status=$?
Expand Down
13 changes: 9 additions & 4 deletions git-mergetool--lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,18 @@ check_unchanged () {
}

valid_tool () {
setup_tool "$1" && return 0
setup_tool "$1" 2>/dev/null && return 0
cmd=$(get_merge_tool_cmd "$1")
test -n "$cmd"
}

setup_user_tool () {
merge_tool_cmd=$(get_merge_tool_cmd "$tool")
test -n "$merge_tool_cmd" || return 1
if test -z "$merge_tool_cmd"
then
echo >&2 "error: ${TOOL_MODE}tool.$tool.cmd not set for tool '$tool'"
return 1
fi

diff_cmd () {
( eval $merge_tool_cmd )
Expand Down Expand Up @@ -255,10 +259,11 @@ setup_tool () {

# Now let the user override the default command for the tool. If
# they have not done so then this will return 1 which we ignore.
setup_user_tool
setup_user_tool 2>/dev/null

if ! list_tool_variants | grep -q "^$tool$"
then
echo "error: unknown ${tool%[0-9]} variant '$tool'" >&2
return 1
fi

Expand Down Expand Up @@ -474,7 +479,7 @@ get_merge_tool_path () {
merge_tool="$1"
if ! valid_tool "$merge_tool"
then
echo >&2 "Unknown merge tool $merge_tool"
echo >&2 "Unknown $TOOL_MODE tool $merge_tool"
exit 1
fi
if diff_mode
Expand Down
8 changes: 8 additions & 0 deletions t/t7610-mergetool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -898,4 +898,12 @@ test_expect_success 'mergetool with guiDefault' '
git commit -m "branch1 resolved with mergetool"
'

test_expect_success 'mergetool with non-existent tool' '
test_when_finished "git reset --hard" &&
git checkout -b test$test_count branch1 &&
test_must_fail git merge main &&
yes "" | test_must_fail git mergetool --tool=absent >out 2>&1 &&
test_grep -i "not set for tool" out
'

test_done

0 comments on commit a35aba8

Please sign in to comment.