# Copyright (c) 2005 Junio C Hamano
#
+
+USAGE='[-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+'
. git-sh-setup
LF='
'
-usage () {
- die "git-merge [-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+"
-}
-
all_strategies='recursive octopus resolve stupid ours'
default_strategies='recursive'
use_strategies=
shift
# All the rest are remote heads
+remoteheads=
for remote
do
- git-rev-parse --verify "$remote"^0 >/dev/null ||
+ remotehead=$(git-rev-parse --verify "$remote"^0) ||
die "$remote - not something we can merge"
+ remoteheads="${remoteheads}$remotehead "
done
+set x $remoteheads ; shift
case "$#" in
1)
esac
result_tree= best_cnt=-1 best_strategy= wt_strategy=
+merge_was_ok=
for strategy in $use_strategies
do
test "$wt_strategy" = '' || {
exit=$?
if test "$no_commit" = t && test "$exit" = 0
then
+ merge_was_ok=t
exit=1 ;# pretend it left conflicts.
fi
do
echo $remote
done >"$GIT_DIR/MERGE_HEAD"
-echo $merge_msg >"$GIT_DIR/MERGE_MSG"
+echo "$merge_msg" >"$GIT_DIR/MERGE_MSG"
-die "Automatic merge failed/prevented; fix up by hand"
+if test "$merge_was_ok" = t
+then
+ echo >&2 \
+ "Automatic merge went well; stopped before committing as requested"
+ exit 0
+else
+ {
+ echo '
+Conflicts:
+'
+ git ls-files --unmerged |
+ sed -e 's/^[^ ]* / /' |
+ uniq
+ } >>"$GIT_DIR/MERGE_MSG"
+ if test -d "$GIT_DIR/rr-cache"
+ then
+ git-rerere
+ fi
+ die "Automatic merge failed; fix up by hand"
+fi