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>
John Keeping committed
Jan 26, 2013 at 16:40 UTC
62957bea0c7637ae1db4452fc165c59d9408585b
1 file changed
+20
-3
git-mergetool--lib.sh
+20
-3
@@ -58,7 +58,11 @@ setup_tool () {
58
. "$mergetools/defaults"
59
if ! test -f "$mergetools/$tool"
60
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
66
fi
67
68
# Load the redefined functions
@@ -67,11 +71,11 @@ setup_tool () {
71
if merge_mode && ! can_merge
72
then
73
echo "error: '$tool' can not be used to resolve merges" >&2
70
- exit 1
74
+ return 1
75
elif diff_mode && ! can_diff
76
then
77
echo "error: '$tool' can only be used to resolve merges" >&2
74
- exit 1
78
+ return 1
79
fi
80
return 0
81
}
@@ -101,6 +105,19 @@ run_merge_tool () {
105
106
# Bring tool-specific functions into scope
107
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
121
122
if merge_mode
123
then