提交 b3dac9c0 编写于 作者: J Junio C Hamano

Merge branch 'da/mergetool-trust-exit-code' into maint

mergetool.<tool>.trustExitCode configuration variable did not apply
to built-in tools, but now it does.

* da/mergetool-trust-exit-code:
  mergetools/vimdiff: trust Vim's exit code
  mergetool: honor mergetool.$tool.trustExitCode for built-in tools
...@@ -125,16 +125,7 @@ setup_user_tool () { ...@@ -125,16 +125,7 @@ setup_user_tool () {
} }
merge_cmd () { merge_cmd () {
trust_exit_code=$(git config --bool \ ( eval $merge_tool_cmd )
"mergetool.$1.trustExitCode" || echo false)
if test "$trust_exit_code" = "false"
then
touch "$BACKUP"
( eval $merge_tool_cmd )
check_unchanged
else
( eval $merge_tool_cmd )
fi
} }
} }
...@@ -162,6 +153,28 @@ setup_tool () { ...@@ -162,6 +153,28 @@ setup_tool () {
echo "$1" echo "$1"
} }
# Most tools' exit codes cannot be trusted, so By default we ignore
# their exit code and check the merged file's modification time in
# check_unchanged() to determine whether or not the merge was
# successful. The return value from run_merge_cmd, by default, is
# determined by check_unchanged().
#
# When a tool's exit code can be trusted then the return value from
# run_merge_cmd is simply the tool's exit code, and check_unchanged()
# is not called.
#
# The return value of exit_code_trustable() tells us whether or not we
# can trust the tool's exit code.
#
# User-defined and built-in tools default to false.
# Built-in tools advertise that their exit code is trustable by
# redefining exit_code_trustable() to true.
exit_code_trustable () {
false
}
if ! test -f "$MERGE_TOOLS_DIR/$tool" if ! test -f "$MERGE_TOOLS_DIR/$tool"
then then
setup_user_tool setup_user_tool
...@@ -197,6 +210,19 @@ get_merge_tool_cmd () { ...@@ -197,6 +210,19 @@ get_merge_tool_cmd () {
fi fi
} }
trust_exit_code () {
if git config --bool "mergetool.$1.trustExitCode"
then
:; # OK
elif exit_code_trustable
then
echo true
else
echo false
fi
}
# Entry point for running tools # Entry point for running tools
run_merge_tool () { run_merge_tool () {
# If GIT_PREFIX is empty then we cannot use it in tools # If GIT_PREFIX is empty then we cannot use it in tools
...@@ -225,7 +251,15 @@ run_diff_cmd () { ...@@ -225,7 +251,15 @@ run_diff_cmd () {
# Run a either a configured or built-in merge tool # Run a either a configured or built-in merge tool
run_merge_cmd () { run_merge_cmd () {
merge_cmd "$1" mergetool_trust_exit_code=$(trust_exit_code "$1")
if test "$mergetool_trust_exit_code" = "true"
then
merge_cmd "$1"
else
touch "$BACKUP"
merge_cmd "$1"
check_unchanged
fi
} }
list_merge_tool_candidates () { list_merge_tool_candidates () {
......
...@@ -3,7 +3,6 @@ diff_cmd () { ...@@ -3,7 +3,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" -wait -merge -3 -a1 \ "$merge_tool_path" -wait -merge -3 -a1 \
...@@ -12,7 +11,6 @@ merge_cmd () { ...@@ -12,7 +11,6 @@ merge_cmd () {
"$merge_tool_path" -wait -2 \ "$merge_tool_path" -wait -2 \
"$LOCAL" "$REMOTE" "$MERGED" >/dev/null 2>&1 "$LOCAL" "$REMOTE" "$MERGED" >/dev/null 2>&1
fi fi
check_unchanged
} }
translate_merge_tool_path() { translate_merge_tool_path() {
......
...@@ -3,7 +3,6 @@ diff_cmd () { ...@@ -3,7 +3,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \ "$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
...@@ -12,7 +11,6 @@ merge_cmd () { ...@@ -12,7 +11,6 @@ merge_cmd () {
"$merge_tool_path" "$LOCAL" "$REMOTE" \ "$merge_tool_path" "$LOCAL" "$REMOTE" \
-mergeoutput="$MERGED" -mergeoutput="$MERGED"
fi fi
check_unchanged
} }
translate_merge_tool_path() { translate_merge_tool_path() {
......
...@@ -3,7 +3,6 @@ diff_cmd () { ...@@ -3,7 +3,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" -BF="$BASE" \ "$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" -BF="$BASE" \
...@@ -12,7 +11,6 @@ merge_cmd () { ...@@ -12,7 +11,6 @@ merge_cmd () {
"$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" \ "$merge_tool_path" -MF="$LOCAL" -TF="$REMOTE" \
-RF="$MERGED" -RF="$MERGED"
fi fi
check_unchanged
} }
translate_merge_tool_path() { translate_merge_tool_path() {
......
...@@ -16,6 +16,10 @@ merge_cmd () { ...@@ -16,6 +16,10 @@ merge_cmd () {
fi >/dev/null 2>&1 fi >/dev/null 2>&1
} }
translate_merge_tool_path() { translate_merge_tool_path () {
echo DeltaWalker echo DeltaWalker
} }
exit_code_trustable () {
true
}
...@@ -12,3 +12,7 @@ merge_cmd () { ...@@ -12,3 +12,7 @@ merge_cmd () {
--result="$MERGED" "$LOCAL" "$REMOTE" --result="$MERGED" "$LOCAL" "$REMOTE"
fi fi
} }
exit_code_trustable () {
true
}
...@@ -3,7 +3,6 @@ diff_cmd () { ...@@ -3,7 +3,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" \ "$merge_tool_path" \
...@@ -13,5 +12,4 @@ merge_cmd () { ...@@ -13,5 +12,4 @@ merge_cmd () {
"$merge_tool_path" \ "$merge_tool_path" \
"$LOCAL" "$MERGED" "$REMOTE" | cat "$LOCAL" "$MERGED" "$REMOTE" | cat
fi fi
check_unchanged
} }
...@@ -3,7 +3,6 @@ diff_cmd () { ...@@ -3,7 +3,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \ "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \
...@@ -12,5 +11,4 @@ merge_cmd () { ...@@ -12,5 +11,4 @@ merge_cmd () {
"$merge_tool_path" "$LOCAL" "$REMOTE" \ "$merge_tool_path" "$LOCAL" "$REMOTE" \
--default --mode=merge2 --to="$MERGED" --default --mode=merge2 --to="$MERGED"
fi fi
check_unchanged
} }
...@@ -20,3 +20,7 @@ merge_cmd () { ...@@ -20,3 +20,7 @@ merge_cmd () {
translate_merge_tool_path() { translate_merge_tool_path() {
echo emacs echo emacs
} }
exit_code_trustable () {
true
}
...@@ -3,14 +3,12 @@ diff_cmd () { ...@@ -3,14 +3,12 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" -merge "$LOCAL" "$BASE" "$REMOTE" -o:"$MERGED" -nh "$merge_tool_path" -merge "$LOCAL" "$BASE" "$REMOTE" -o:"$MERGED" -nh
else else
"$merge_tool_path" -merge "$LOCAL" "$REMOTE" -o:"$MERGED" -nh "$merge_tool_path" -merge "$LOCAL" "$REMOTE" -o:"$MERGED" -nh
fi fi
check_unchanged
} }
translate_merge_tool_path() { translate_merge_tool_path() {
......
...@@ -21,3 +21,7 @@ merge_cmd () { ...@@ -21,3 +21,7 @@ merge_cmd () {
>/dev/null 2>&1 >/dev/null 2>&1
fi fi
} }
exit_code_trustable () {
true
}
...@@ -5,3 +5,7 @@ can_merge () { ...@@ -5,3 +5,7 @@ can_merge () {
diff_cmd () { diff_cmd () {
"$merge_tool_path" "$LOCAL" "$REMOTE" "$merge_tool_path" "$LOCAL" "$REMOTE"
} }
exit_code_trustable () {
true
}
...@@ -7,7 +7,7 @@ merge_cmd () { ...@@ -7,7 +7,7 @@ merge_cmd () {
then then
check_meld_for_output_version check_meld_for_output_version
fi fi
touch "$BACKUP"
if test "$meld_has_output_option" = true if test "$meld_has_output_option" = true
then then
"$merge_tool_path" --output "$MERGED" \ "$merge_tool_path" --output "$MERGED" \
...@@ -15,7 +15,6 @@ merge_cmd () { ...@@ -15,7 +15,6 @@ merge_cmd () {
else else
"$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE" "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
fi fi
check_unchanged
} }
# Check whether we should use 'meld --output <file>' # Check whether we should use 'meld --output <file>'
......
...@@ -3,7 +3,6 @@ diff_cmd () { ...@@ -3,7 +3,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" "$LOCAL" "$REMOTE" \ "$merge_tool_path" "$LOCAL" "$REMOTE" \
...@@ -12,5 +11,4 @@ merge_cmd () { ...@@ -12,5 +11,4 @@ merge_cmd () {
"$merge_tool_path" "$LOCAL" "$REMOTE" \ "$merge_tool_path" "$LOCAL" "$REMOTE" \
-merge "$MERGED" | cat -merge "$MERGED" | cat
fi fi
check_unchanged
} }
...@@ -20,14 +20,12 @@ diff_cmd () { ...@@ -20,14 +20,12 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if ! $base_present if ! $base_present
then then
cp -- "$LOCAL" "$BASE" cp -- "$LOCAL" "$BASE"
create_virtual_base "$BASE" "$REMOTE" create_virtual_base "$BASE" "$REMOTE"
fi fi
"$merge_tool_path" "$BASE" "$REMOTE" "$LOCAL" "$MERGED" "$merge_tool_path" "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
check_unchanged
} }
create_empty_file () { create_empty_file () {
......
...@@ -10,3 +10,7 @@ merge_cmd () { ...@@ -10,3 +10,7 @@ merge_cmd () {
"$merge_tool_path" -o "$MERGED" "$LOCAL" "$REMOTE" "$merge_tool_path" -o "$MERGED" "$LOCAL" "$REMOTE"
fi fi
} }
exit_code_trustable () {
true
}
...@@ -5,7 +5,6 @@ can_diff () { ...@@ -5,7 +5,6 @@ can_diff () {
merge_cmd () { merge_cmd () {
if $base_present if $base_present
then then
touch "$BACKUP"
basename="$(basename "$merge_tool_path" .exe)" basename="$(basename "$merge_tool_path" .exe)"
if test "$basename" = "tortoisegitmerge" if test "$basename" = "tortoisegitmerge"
then then
...@@ -17,7 +16,6 @@ merge_cmd () { ...@@ -17,7 +16,6 @@ merge_cmd () {
-base:"$BASE" -mine:"$LOCAL" \ -base:"$BASE" -mine:"$LOCAL" \
-theirs:"$REMOTE" -merged:"$MERGED" -theirs:"$REMOTE" -merged:"$MERGED"
fi fi
check_unchanged
else else
echo "$merge_tool_path cannot be used without a base" 1>&2 echo "$merge_tool_path cannot be used without a base" 1>&2
return 1 return 1
......
...@@ -4,7 +4,6 @@ diff_cmd () { ...@@ -4,7 +4,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
case "$1" in case "$1" in
gvimdiff|vimdiff) gvimdiff|vimdiff)
if $base_present if $base_present
...@@ -31,7 +30,6 @@ merge_cmd () { ...@@ -31,7 +30,6 @@ merge_cmd () {
fi fi
;; ;;
esac esac
check_unchanged
} }
translate_merge_tool_path() { translate_merge_tool_path() {
...@@ -44,3 +42,7 @@ translate_merge_tool_path() { ...@@ -44,3 +42,7 @@ translate_merge_tool_path() {
;; ;;
esac esac
} }
exit_code_trustable () {
true
}
...@@ -6,10 +6,8 @@ diff_cmd () { ...@@ -6,10 +6,8 @@ diff_cmd () {
merge_cmd () { merge_cmd () {
# mergetool.winmerge.trustExitCode is implicitly false. # mergetool.winmerge.trustExitCode is implicitly false.
# touch $BACKUP so that we can check_unchanged. # touch $BACKUP so that we can check_unchanged.
touch "$BACKUP"
"$merge_tool_path" -u -e -dl Local -dr Remote \ "$merge_tool_path" -u -e -dl Local -dr Remote \
"$LOCAL" "$REMOTE" "$MERGED" "$LOCAL" "$REMOTE" "$MERGED"
check_unchanged
} }
translate_merge_tool_path() { translate_merge_tool_path() {
......
...@@ -6,7 +6,6 @@ diff_cmd () { ...@@ -6,7 +6,6 @@ diff_cmd () {
} }
merge_cmd () { merge_cmd () {
touch "$BACKUP"
if $base_present if $base_present
then then
"$merge_tool_path" -X --show-merged-pane \ "$merge_tool_path" -X --show-merged-pane \
...@@ -21,5 +20,4 @@ merge_cmd () { ...@@ -21,5 +20,4 @@ merge_cmd () {
-R 'Accel.SearchForward: "Ctrl-G"' \ -R 'Accel.SearchForward: "Ctrl-G"' \
--merged-file "$MERGED" "$LOCAL" "$REMOTE" --merged-file "$MERGED" "$LOCAL" "$REMOTE"
fi fi
check_unchanged
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册