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