Split "git-pull-script" into two parts
[git/git.git] / git-resolve-script
1 #!/bin/sh
2 #
3 # Resolve two trees.
4 #
5 head="$1"
6 merge="$2"
7 merge_repo="$3"
8
9 rm -f .git/MERGE_HEAD .git/ORIG_HEAD
10 echo $head > .git/ORIG_HEAD
11 echo $merge > .git/MERGE_HEAD
12
13 #
14 # The remote name is just used for the message,
15 # but we do want it.
16 #
17 if [ "$merge_repo" == "" ]; then
18 echo "git-resolve-script <head> <remote> <merge-repo-name>"
19 exit 1
20 fi
21
22 common=$(git-merge-base $head $merge)
23 if [ -z "$common" ]; then
24 echo "Unable to find common commit between" $merge $head
25 exit 1
26 fi
27
28 if [ "$common" == "$merge" ]; then
29 echo "Already up-to-date. Yeeah!"
30 exit 0
31 fi
32 if [ "$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
41 fi
42 echo "Trying to merge $merge into $head"
43 git-read-tree -m $common $head $merge
44 merge_msg="Merge of $merge_repo"
45 result_tree=$(git-write-tree 2> /dev/null)
46 if [ $? -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
51 fi
52 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge_head)
53 echo "Committed merge $result_commit"
54 echo $result_commit > .git/HEAD
55 git-checkout-cache -f -a && git-update-cache --refresh
56 git-diff-tree -p ORIG_HEAD HEAD | diffstat -p1