mergetool: Add prompt to continue after failing to merge a file

This option stops git mergetool from aborting at the first failed merge.
After a failed merge the user will be prompted to indicated whether he
wishes to continue with attempting to merge subsequent paths or to
abort.

This allows some additional use patterns. Merge conflicts can now be
previewed one at time and merges can also be skipped so that they can be
performed in a later pass.

Signed-off-by: Charles Bailey <charles@hashpling.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Charles Bailey 2008-12-12 21:48:40 +00:00 committed by Junio C Hamano
parent 682b451f84
commit b0169d84df
1 changed files with 43 additions and 9 deletions

View File

@ -70,16 +70,16 @@ resolve_symlink_merge () {
git checkout-index -f --stage=2 -- "$MERGED" git checkout-index -f --stage=2 -- "$MERGED"
git add -- "$MERGED" git add -- "$MERGED"
cleanup_temp_files --save-backup cleanup_temp_files --save-backup
return return 0
;; ;;
[rR]*) [rR]*)
git checkout-index -f --stage=3 -- "$MERGED" git checkout-index -f --stage=3 -- "$MERGED"
git add -- "$MERGED" git add -- "$MERGED"
cleanup_temp_files --save-backup cleanup_temp_files --save-backup
return return 0
;; ;;
[aA]*) [aA]*)
exit 1 return 1
;; ;;
esac esac
done done
@ -97,15 +97,15 @@ resolve_deleted_merge () {
[mMcC]*) [mMcC]*)
git add -- "$MERGED" git add -- "$MERGED"
cleanup_temp_files --save-backup cleanup_temp_files --save-backup
return return 0
;; ;;
[dD]*) [dD]*)
git rm -- "$MERGED" > /dev/null git rm -- "$MERGED" > /dev/null
cleanup_temp_files cleanup_temp_files
return return 0
;; ;;
[aA]*) [aA]*)
exit 1 return 1
;; ;;
esac esac
done done
@ -137,7 +137,7 @@ merge_file () {
else else
echo "$MERGED: file does not need merging" echo "$MERGED: file does not need merging"
fi fi
exit 1 return 1
fi fi


ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')" ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')"
@ -269,7 +269,7 @@ merge_file () {
if test "$status" -ne 0; then if test "$status" -ne 0; then
echo "merge of $MERGED failed" 1>&2 echo "merge of $MERGED failed" 1>&2
mv -- "$BACKUP" "$MERGED" mv -- "$BACKUP" "$MERGED"
exit 1 return 1
fi fi


if test "$merge_keep_backup" = "true"; then if test "$merge_keep_backup" = "true"; then
@ -280,6 +280,7 @@ merge_file () {


git add -- "$MERGED" git add -- "$MERGED"
cleanup_temp_files cleanup_temp_files
return 0
} }


prompt=$(git config --bool mergetool.prompt || echo true) prompt=$(git config --bool mergetool.prompt || echo true)
@ -350,6 +351,22 @@ init_merge_tool_path() {
fi fi
} }


prompt_after_failed_merge() {
while true; do
printf "Continue merging other unresolved paths (y/n) ? "
read ans
case "$ans" in

[yY]*)
return 0
;;

[nN]*)
return 1
;;
esac
done
}


if test -z "$merge_tool"; then if test -z "$merge_tool"; then
merge_tool=`git config merge.tool` merge_tool=`git config merge.tool`
@ -409,6 +426,8 @@ else
fi fi
fi fi


last_status=0
rollup_status=0


if test $# -eq 0 ; then if test $# -eq 0 ; then
files=`git ls-files -u | sed -e 's/^[^ ]* //' | sort -u` files=`git ls-files -u | sed -e 's/^[^ ]* //' | sort -u`
@ -422,14 +441,29 @@ if test $# -eq 0 ; then
sort -u | sort -u |
while IFS= read i while IFS= read i
do do
if test $last_status -ne 0; then
prompt_after_failed_merge < /dev/tty || exit 1
fi
printf "\n" printf "\n"
merge_file "$i" < /dev/tty > /dev/tty merge_file "$i" < /dev/tty > /dev/tty
last_status=$?
if test $last_status -ne 0; then
rollup_status=1
fi
done done
else else
while test $# -gt 0; do while test $# -gt 0; do
if test $last_status -ne 0; then
prompt_after_failed_merge || exit 1
fi
printf "\n" printf "\n"
merge_file "$1" merge_file "$1"
last_status=$?
if test $last_status -ne 0; then
rollup_status=1
fi
shift shift
done done
fi fi
exit 0
exit $rollup_status