]>
Commit | Line | Data |
---|---|---|
67cc5c4e LT |
1 | #!/bin/sh |
2 | # | |
8ac069ac JH |
3 | # Copyright (c) 2005 Linus Torvalds |
4 | # | |
67cc5c4e LT |
5 | # Resolve two trees. |
6 | # | |
b33e9666 LT |
7 | . git-sh-setup-script || die "Not a git archive" |
8 | ||
f6e1a4d6 JH |
9 | head=$(git-rev-parse --verify "$1") |
10 | merge=$(git-rev-parse --verify "$2") | |
3ba513c3 | 11 | merge_msg="$3" |
67cc5c4e | 12 | |
c591412c | 13 | dropheads() { |
6b38a402 | 14 | rm -f -- "$GIT_DIR/MERGE_HEAD" \ |
c591412c DH |
15 | "$GIT_DIR/LAST_MERGE" || exit 1 |
16 | } | |
67cc5c4e LT |
17 | |
18 | # | |
19 | # The remote name is just used for the message, | |
20 | # but we do want it. | |
21 | # | |
3ba513c3 LT |
22 | if [ -z "$head" -o -z "$merge" -o -z "$merge_msg" ]; then |
23 | die "git-resolve-script <head> <remote> <merge-message>" | |
67cc5c4e LT |
24 | fi |
25 | ||
c591412c DH |
26 | dropheads |
27 | echo $head > "$GIT_DIR"/ORIG_HEAD | |
28 | echo $merge > "$GIT_DIR"/LAST_MERGE | |
29 | ||
67cc5c4e LT |
30 | common=$(git-merge-base $head $merge) |
31 | if [ -z "$common" ]; then | |
b33e9666 | 32 | die "Unable to find common commit between" $merge $head |
67cc5c4e LT |
33 | fi |
34 | ||
35 | if [ "$common" == "$merge" ]; then | |
36 | echo "Already up-to-date. Yeeah!" | |
c591412c | 37 | dropheads |
67cc5c4e LT |
38 | exit 0 |
39 | fi | |
40 | if [ "$common" == "$head" ]; then | |
41 | echo "Updating from $head to $merge." | |
220a0b52 | 42 | git-read-tree -u -m $head $merge || exit 1 |
8ac069ac | 43 | echo $merge > "$GIT_DIR"/HEAD |
6b38a402 | 44 | git-diff-tree -p $head $merge | git-apply --stat |
c591412c | 45 | dropheads |
67cc5c4e LT |
46 | exit 0 |
47 | fi | |
48 | echo "Trying to merge $merge into $head" | |
220a0b52 | 49 | git-read-tree -u -m $common $head $merge || exit 1 |
67cc5c4e LT |
50 | result_tree=$(git-write-tree 2> /dev/null) |
51 | if [ $? -ne 0 ]; then | |
52 | echo "Simple merge failed, trying Automatic merge" | |
e5b905c4 LT |
53 | git-merge-cache -o git-merge-one-file-script -a |
54 | if [ $? -ne 0 ]; then | |
c591412c | 55 | echo $merge > "$GIT_DIR"/MERGE_HEAD |
b33e9666 | 56 | die "Automatic merge failed, fix up by hand" |
e5b905c4 | 57 | fi |
67cc5c4e LT |
58 | result_tree=$(git-write-tree) || exit 1 |
59 | fi | |
d5a72fd6 | 60 | result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge) |
67cc5c4e | 61 | echo "Committed merge $result_commit" |
8ac069ac | 62 | echo $result_commit > "$GIT_DIR"/HEAD |
9c065315 | 63 | git-diff-tree -p $head $result_commit | git-apply --stat |
c591412c | 64 | dropheads |