Skip to content

Commit 7c10605

Browse files
davvidgitster
authored andcommitted
mergetool: honor mergetool.$tool.trustExitCode for built-in tools
Built-in merge tools contain a hard-coded assumption about whether or not a tool's exit code can be trusted to determine the success or failure of a merge. Tools whose exit codes are not trusted contain calls to check_unchanged() in their merge_cmd() functions. A problem with this is that the trustExitCode configuration is not honored for built-in tools. Teach built-in tools to honor the trustExitCode configuration. Extend run_merge_cmd() so that it is responsible for calling check_unchanged() when a tool's exit code cannot be trusted. Remove check_unchanged() calls from scriptlets since they are no longer responsible for calling it. When no configuration is present, exit_code_trustable() is checked to see whether the exit code should be trusted. The default implementation returns false. Tools whose exit codes can be trusted override exit_code_trustable() to true. Reported-by: Dun Peal <dunpealer@gmail.com> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ac84098 commit 7c10605

File tree

20 files changed

+71
-38
lines changed

20 files changed

+71
-38
lines changed

git-mergetool--lib.sh

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,7 @@ setup_user_tool () {
125125
}
126126

127127
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-
check_unchanged
135-
else
136-
( eval $merge_tool_cmd )
137-
fi
128+
( eval $merge_tool_cmd )
138129
}
139130
}
140131

@@ -162,6 +153,28 @@ setup_tool () {
162153
echo "$1"
163154
}
164155

156+
# Most tools' exit codes cannot be trusted, so By default we ignore
157+
# their exit code and check the merged file's modification time in
158+
# check_unchanged() to determine whether or not the merge was
159+
# successful. The return value from run_merge_cmd, by default, is
160+
# determined by check_unchanged().
161+
#
162+
# When a tool's exit code can be trusted then the return value from
163+
# run_merge_cmd is simply the tool's exit code, and check_unchanged()
164+
# is not called.
165+
#
166+
# The return value of exit_code_trustable() tells us whether or not we
167+
# can trust the tool's exit code.
168+
#
169+
# User-defined and built-in tools default to false.
170+
# Built-in tools advertise that their exit code is trustable by
171+
# redefining exit_code_trustable() to true.
172+
173+
exit_code_trustable () {
174+
false
175+
}
176+
177+
165178
if ! test -f "$MERGE_TOOLS_DIR/$tool"
166179
then
167180
setup_user_tool
@@ -197,6 +210,19 @@ get_merge_tool_cmd () {
197210
fi
198211
}
199212

213+
trust_exit_code () {
214+
if git config --bool "mergetool.$1.trustExitCode"
215+
then
216+
:; # OK
217+
elif exit_code_trustable
218+
then
219+
echo true
220+
else
221+
echo false
222+
fi
223+
}
224+
225+
200226
# Entry point for running tools
201227
run_merge_tool () {
202228
# If GIT_PREFIX is empty then we cannot use it in tools
@@ -225,7 +251,15 @@ run_diff_cmd () {
225251

226252
# Run a either a configured or built-in merge tool
227253
run_merge_cmd () {
228-
merge_cmd "$1"
254+
mergetool_trust_exit_code=$(trust_exit_code "$1")
255+
if test "$mergetool_trust_exit_code" = "true"
256+
then
257+
merge_cmd "$1"
258+
else
259+
touch "$BACKUP"
260+
merge_cmd "$1"
261+
check_unchanged
262+
fi
229263
}
230264

231265
list_merge_tool_candidates () {

mergetools/araxis

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ diff_cmd () {
33
}
44

55
merge_cmd () {
6-
touch "$BACKUP"
76
if $base_present
87
then
98
"$merge_tool_path" -wait -merge -3 -a1 \
@@ -12,7 +11,6 @@ merge_cmd () {
1211
"$merge_tool_path" -wait -2 \
1312
"$LOCAL" "$REMOTE" "$MERGED" >/dev/null 2>&1
1413
fi
15-
check_unchanged
1614
}
1715

1816
translate_merge_tool_path() {

mergetools/bc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ diff_cmd () {
33
}
44

55
merge_cmd () {
6-
touch "$BACKUP"
76
if $base_present
87
then
98
"$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
@@ -12,7 +11,6 @@ merge_cmd () {
1211
"$merge_tool_path" "$LOCAL" "$REMOTE" \
1312
-mergeoutput="$MERGED"
1413
fi
15-
check_unchanged
1614
}
1715

1816
translate_merge_tool_path() {

mergetools/codecompare

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ diff_cmd () {
33
}
44

55
merge_cmd () {
6-
touch "$BACKUP"
76
if $base_present
87
then
98
"$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" -BF="$BASE" \
@@ -12,7 +11,6 @@ merge_cmd () {
1211
"$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" \
1312
-RF="$MERGED"
1413
fi
15-
check_unchanged
1614
}
1715

1816
translate_merge_tool_path() {

mergetools/deltawalker

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ merge_cmd () {
1616
fi >/dev/null 2>&1
1717
}
1818

19-
translate_merge_tool_path() {
19+
translate_merge_tool_path () {
2020
echo DeltaWalker
2121
}
22+
23+
exit_code_trustable () {
24+
true
25+
}

mergetools/diffmerge

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ merge_cmd () {
1212
--result="$MERGED" "$LOCAL" "$REMOTE"
1313
fi
1414
}
15+
16+
exit_code_trustable () {
17+
true
18+
}

mergetools/diffuse

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ diff_cmd () {
33
}
44

55
merge_cmd () {
6-
touch "$BACKUP"
76
if $base_present
87
then
98
"$merge_tool_path" \
@@ -13,5 +12,4 @@ merge_cmd () {
1312
"$merge_tool_path" \
1413
"$LOCAL" "$MERGED" "$REMOTE" | cat
1514
fi
16-
check_unchanged
1715
}

mergetools/ecmerge

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ diff_cmd () {
33
}
44

55
merge_cmd () {
6-
touch "$BACKUP"
76
if $base_present
87
then
98
"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \
@@ -12,5 +11,4 @@ merge_cmd () {
1211
"$merge_tool_path" "$LOCAL" "$REMOTE" \
1312
--default --mode=merge2 --to="$MERGED"
1413
fi
15-
check_unchanged
1614
}

mergetools/emerge

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ merge_cmd () {
2020
translate_merge_tool_path() {
2121
echo emacs
2222
}
23+
24+
exit_code_trustable () {
25+
true
26+
}

mergetools/examdiff

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ diff_cmd () {
33
}
44

55
merge_cmd () {
6-
touch "$BACKUP"
76
if $base_present
87
then
98
"$merge_tool_path" -merge "$LOCAL" "$BASE" "$REMOTE" -o:"$MERGED" -nh
109
else
1110
"$merge_tool_path" -merge "$LOCAL" "$REMOTE" -o:"$MERGED" -nh
1211
fi
13-
check_unchanged
1412
}
1513

1614
translate_merge_tool_path() {

0 commit comments

Comments
 (0)