Git fork

Merge branch 'pb/mergetool-errors'

End-user experience of "git mergetool" when the command errors out
has been improved.

* 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 if 'setup_user_tool' fails
git-mergetool--lib.sh: use TOOL_MODE when erroring about unknown tool
completion: complete '--tool-help' in 'git mergetool'

+20 -10
+1 -1
contrib/completion/git-completion.bash
··· 2331 2331 return 2332 2332 ;; 2333 2333 --*) 2334 - __gitcomp "--tool= --prompt --no-prompt --gui --no-gui" 2334 + __gitcomp "--tool= --tool-help --prompt --no-prompt --gui --no-gui" 2335 2335 return 2336 2336 ;; 2337 2337 esac
+2 -6
git-difftool--helper.sh
··· 61 61 export BASE 62 62 eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"' 63 63 else 64 - initialize_merge_tool "$merge_tool" 65 - # ignore the error from the above --- run_merge_tool 66 - # will diagnose unusable tool by itself 64 + initialize_merge_tool "$merge_tool" || exit 1 67 65 run_merge_tool "$merge_tool" 68 66 fi 69 67 } ··· 87 85 then 88 86 LOCAL="$1" 89 87 REMOTE="$2" 90 - initialize_merge_tool "$merge_tool" 91 - # ignore the error from the above --- run_merge_tool 92 - # will diagnose unusable tool by itself 88 + initialize_merge_tool "$merge_tool" || exit 1 93 89 run_merge_tool "$merge_tool" false 94 90 95 91 status=$?
+9 -3
git-mergetool--lib.sh
··· 159 159 } 160 160 161 161 valid_tool () { 162 - setup_tool "$1" && return 0 162 + setup_tool "$1" 2>/dev/null && return 0 163 163 cmd=$(get_merge_tool_cmd "$1") 164 164 test -n "$cmd" 165 165 } ··· 250 250 . "$MERGE_TOOLS_DIR/${tool%[0-9]}" 251 251 else 252 252 setup_user_tool 253 - return $? 253 + rc=$? 254 + if test $rc -ne 0 255 + then 256 + echo >&2 "error: ${TOOL_MODE}tool.$tool.cmd not set for tool '$tool'" 257 + fi 258 + return $rc 254 259 fi 255 260 256 261 # Now let the user override the default command for the tool. If ··· 259 264 260 265 if ! list_tool_variants | grep -q "^$tool$" 261 266 then 267 + echo "error: unknown tool variant '$tool'" >&2 262 268 return 1 263 269 fi 264 270 ··· 474 480 merge_tool="$1" 475 481 if ! valid_tool "$merge_tool" 476 482 then 477 - echo >&2 "Unknown merge tool $merge_tool" 483 + echo >&2 "Unknown $TOOL_MODE tool $merge_tool" 478 484 exit 1 479 485 fi 480 486 if diff_mode
+8
t/t7610-mergetool.sh
··· 898 898 git commit -m "branch1 resolved with mergetool" 899 899 ' 900 900 901 + test_expect_success 'mergetool with non-existent tool' ' 902 + test_when_finished "git reset --hard" && 903 + git checkout -b test$test_count branch1 && 904 + test_must_fail git merge main && 905 + yes "" | test_must_fail git mergetool --tool=absent >out 2>&1 && 906 + test_grep "mergetool.absent.cmd not set for tool" out 907 + ' 908 + 901 909 test_done