3 # Copyright (c) 2005 Linus Torvalds
7 . git-sh-setup-script || die "Not a git archive"
9 head=$(git-rev-parse --verify "$1"^0) || exit
10 merge=$(git-rev-parse --verify "$2"^0) || exit
14 rm -f -- "$GIT_DIR/MERGE_HEAD" \
15 "$GIT_DIR/LAST_MERGE" || exit 1
19 # The remote name is just used for the message,
22 if [ -z "$head" -o -z "$merge" -o -z "$merge_msg" ]; then
23 die "git-resolve-script <head> <remote> <merge-message>"
27 echo $head > "$GIT_DIR"/ORIG_HEAD
28 echo $merge > "$GIT_DIR"/LAST_MERGE
30 common=$(git-merge-base $head $merge)
31 if [ -z "$common" ]; then
32 die "Unable to find common commit between" $merge $head
35 if [ "$common" == "$merge" ]; then
36 echo "Already up-to-date. Yeeah!"
40 if [ "$common" == "$head" ]; then
41 echo "Updating from $head to $merge."
42 git-read-tree -u -m $head $merge || exit 1
43 echo $merge > "$GIT_DIR"/HEAD
44 git-diff-tree -p $head $merge | git-apply --stat
48 echo "Trying to merge $merge into $head"
49 git-read-tree -u -m $common $head $merge || exit 1
50 result_tree=$(git-write-tree 2> /dev/null)
52 echo "Simple merge failed, trying Automatic merge"
53 git-merge-cache -o git-merge-one-file-script -a
55 echo $merge > "$GIT_DIR"/MERGE_HEAD
56 die "Automatic merge failed, fix up by hand"
58 result_tree=$(git-write-tree) || exit 1
60 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
61 echo "Committed merge $result_commit"
62 echo $result_commit > "$GIT_DIR"/HEAD
63 git-diff-tree -p $head $result_commit | git-apply --stat