git-merge-resolve.sh 944 Bytes
Newer Older
1 2 3
#!/bin/sh
#
# Copyright (c) 2005 Linus Torvalds
4
# Copyright (c) 2005 Junio C Hamano
5
#
Pavel Roskin's avatar
Pavel Roskin committed
6
# Resolve two trees, using enhanced multi-base read-tree.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

# The first parameters up to -- are merge bases; the rest are heads.
bases= head= remotes= sep_seen=
for arg
do
	case ",$sep_seen,$head,$arg," in
	*,--,)
		sep_seen=yes
		;;
	,yes,,*)
		head=$arg
		;;
	,yes,*)
		remotes="$remotes$arg "
		;;
	*)
		bases="$bases$arg "
		;;
	esac
done

28
# Give up if we are given two or more remotes -- not handling octopus.
29 30 31 32 33
case "$remotes" in
?*' '?*)
	exit 2 ;;
esac

34 35 36 37 38 39
# Give up if this is a baseless merge.
if test '' = "$bases"
then
	exit 2
fi

40
git update-index -q --refresh
41
git read-tree -u -m --aggressive $bases $head $remotes || exit 2
42
echo "Trying simple merge."
43
if result_tree=$(git write-tree 2>/dev/null)
44 45 46 47
then
	exit 0
else
	echo "Simple merge failed, trying Automatic merge."
48
	if git merge-index -o git-merge-one-file -a
49 50 51 52 53 54
	then
		exit 0
	else
		exit 1
	fi
fi