Skip to content

Commit 62957be

Browse files
johnkeepinggitster
authored andcommitted
mergetool--lib: don't call "exit" in setup_tool
This will make it easier to use setup_tool in places where we expect that the selected tool will not support the current mode. We need to introduce a new return code for setup_tool to differentiate between the case of "the selected tool is invalid" and "the selected tool is not a built-in" since we must call setup_tool when a custom 'merge.<tool>.path' is configured for a built-in tool but avoid failing when the configured tool is not a built-in. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 88d3406 commit 62957be

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

git-mergetool--lib.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ setup_tool () {
5858
. "$mergetools/defaults"
5959
if ! test -f "$mergetools/$tool"
6060
then
61-
return 1
61+
# Use a special return code for this case since we want to
62+
# source "defaults" even when an explicit tool path is
63+
# configured since the user can use that to override the
64+
# default path in the scriptlet.
65+
return 2
6266
fi
6367

6468
# Load the redefined functions
@@ -67,11 +71,11 @@ setup_tool () {
6771
if merge_mode && ! can_merge
6872
then
6973
echo "error: '$tool' can not be used to resolve merges" >&2
70-
exit 1
74+
return 1
7175
elif diff_mode && ! can_diff
7276
then
7377
echo "error: '$tool' can only be used to resolve merges" >&2
74-
exit 1
78+
return 1
7579
fi
7680
return 0
7781
}
@@ -101,6 +105,19 @@ run_merge_tool () {
101105

102106
# Bring tool-specific functions into scope
103107
setup_tool "$1"
108+
exitcode=$?
109+
case $exitcode in
110+
0)
111+
:
112+
;;
113+
2)
114+
# The configured tool is not a built-in tool.
115+
test -n "$merge_tool_path" || return 1
116+
;;
117+
*)
118+
return $exitcode
119+
;;
120+
esac
104121

105122
if merge_mode
106123
then

0 commit comments

Comments
 (0)