1#!/bin/sh
2#
3# Resolve two trees.
4#
5head="$1"
6merge="$2"
7merge_repo="$3"
8
9rm -f .git/MERGE_HEAD .git/ORIG_HEAD
10echo $head > .git/ORIG_HEAD
11echo $merge > .git/MERGE_HEAD
12
13#
14# The remote name is just used for the message,
15# but we do want it.
16#
17if [ "$merge_repo" == "" ]; then
18 echo "git-resolve-script <head> <remote> <merge-repo-name>"
19 exit 1
20fi
21
22common=$(git-merge-base $head $merge)
23if [ -z "$common" ]; then
24 echo "Unable to find common commit between" $merge $head
25 exit 1
26fi
27
28if [ "$common" == "$merge" ]; then
29 echo "Already up-to-date. Yeeah!"
30 exit 0
31fi
32if [ "$common" == "$head" ]; then
33 echo "Updating from $head to $merge."
34 echo "Destroying all noncommitted data!"
35 echo "Kill me within 3 seconds.."
36 sleep 3
37 git-read-tree -m $merge && git-checkout-cache -f -a && git-update-cache --refresh
38 echo $merge > .git/HEAD
39 git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1
40 exit 0
41fi
42echo "Trying to merge $merge into $head"
43git-read-tree -m $common $head $merge
44merge_msg="Merge of $merge_repo"
45result_tree=$(git-write-tree 2> /dev/null)
46if [ $? -ne 0 ]; then
47 echo "Simple merge failed, trying Automatic merge"
48 git-merge-cache git-merge-one-file-script -a
49 merge_msg="Automatic merge of $merge_repo"
50 result_tree=$(git-write-tree) || exit 1
51fi
52result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
53echo "Committed merge $result_commit"
54echo $result_commit > .git/HEAD
55git-checkout-cache -f -a && git-update-cache --refresh
56git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1