Skip to content

Commit 6f37238

Browse files
committed
Merge branch 'jk/mergetool-lib-refactor'
Code cleanup. * jk/mergetool-lib-refactor: mergetool--lib: refactor {diff,merge}_cmd logic
2 parents c47d438 + d2512fc commit 6f37238

File tree

1 file changed

+35
-47
lines changed

1 file changed

+35
-47
lines changed

git-mergetool--lib.sh

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,33 @@ valid_tool () {
114114
test -n "$cmd"
115115
}
116116

117+
setup_user_tool () {
118+
merge_tool_cmd=$(get_merge_tool_cmd "$tool")
119+
test -n "$merge_tool_cmd" || return 1
120+
121+
diff_cmd () {
122+
( eval $merge_tool_cmd )
123+
status=$?
124+
return $status
125+
}
126+
127+
merge_cmd () {
128+
trust_exit_code=$(git config --bool \
129+
"mergetool.$1.trustExitCode" || echo false)
130+
if test "$trust_exit_code" = "false"
131+
then
132+
touch "$BACKUP"
133+
( eval $merge_tool_cmd )
134+
status=$?
135+
check_unchanged
136+
else
137+
( eval $merge_tool_cmd )
138+
status=$?
139+
fi
140+
return $status
141+
}
142+
}
143+
117144
setup_tool () {
118145
tool="$1"
119146

@@ -142,15 +169,15 @@ setup_tool () {
142169

143170
if ! test -f "$MERGE_TOOLS_DIR/$tool"
144171
then
145-
# Use a special return code for this case since we want to
146-
# source "defaults" even when an explicit tool path is
147-
# configured since the user can use that to override the
148-
# default path in the scriptlet.
149-
return 2
172+
setup_user_tool
173+
return $?
150174
fi
151175

152176
# Load the redefined functions
153177
. "$MERGE_TOOLS_DIR/$tool"
178+
# Now let the user override the default command for the tool. If
179+
# they have not done so then this will return 1 which we ignore.
180+
setup_user_tool
154181

155182
if merge_mode && ! can_merge
156183
then
@@ -187,20 +214,7 @@ run_merge_tool () {
187214
status=0
188215

189216
# Bring tool-specific functions into scope
190-
setup_tool "$1"
191-
exitcode=$?
192-
case $exitcode in
193-
0)
194-
:
195-
;;
196-
2)
197-
# The configured tool is not a built-in tool.
198-
test -n "$merge_tool_path" || return 1
199-
;;
200-
*)
201-
return $exitcode
202-
;;
203-
esac
217+
setup_tool "$1" || return 1
204218

205219
if merge_mode
206220
then
@@ -213,38 +227,12 @@ run_merge_tool () {
213227

214228
# Run a either a configured or built-in diff tool
215229
run_diff_cmd () {
216-
merge_tool_cmd=$(get_merge_tool_cmd "$1")
217-
if test -n "$merge_tool_cmd"
218-
then
219-
( eval $merge_tool_cmd )
220-
status=$?
221-
return $status
222-
else
223-
diff_cmd "$1"
224-
fi
230+
diff_cmd "$1"
225231
}
226232

227233
# Run a either a configured or built-in merge tool
228234
run_merge_cmd () {
229-
merge_tool_cmd=$(get_merge_tool_cmd "$1")
230-
if test -n "$merge_tool_cmd"
231-
then
232-
trust_exit_code=$(git config --bool \
233-
"mergetool.$1.trustExitCode" || echo false)
234-
if test "$trust_exit_code" = "false"
235-
then
236-
touch "$BACKUP"
237-
( eval $merge_tool_cmd )
238-
status=$?
239-
check_unchanged
240-
else
241-
( eval $merge_tool_cmd )
242-
status=$?
243-
fi
244-
return $status
245-
else
246-
merge_cmd "$1"
247-
fi
235+
merge_cmd "$1"
248236
}
249237

250238
list_merge_tool_candidates () {

0 commit comments

Comments
 (0)