3 # Copyright (c) 2005 Linus Torvalds
7 . git-sh-setup || die
"Not a git archive"
10 die
"git-resolve <head> <remote> <merge-message>"
14 rm -f -- "$GIT_DIR/MERGE_HEAD" \
15 "$GIT_DIR/LAST_MERGE" ||
exit 1
18 head=$
(git-rev-parse
--verify "$1"^
0) &&
19 merge
=$
(git-rev-parse
--verify "$2"^
0) &&
20 merge_msg
="$3" || usage
23 # The remote name is just used for the message,
26 if [ -z "$head" -o -z "$merge" -o -z "$merge_msg" ]; then
31 echo $head > "$GIT_DIR"/ORIG_HEAD
32 echo $merge > "$GIT_DIR"/LAST_MERGE
34 common
=$
(git-merge-base
$head $merge)
35 if [ -z "$common" ]; then
36 die
"Unable to find common commit between" $merge $head
41 echo "Already up-to-date. Yeeah!"
46 echo "Updating from $head to $merge."
47 git-read-tree
-u -m $head $merge ||
exit 1
48 git-update-ref HEAD
"$merge" "$head"
49 git-diff-tree
-p $head $merge | git-apply
--stat
55 # Find an optimum merge base if there are more than one candidates.
58 common
=$
(git-merge-base
-a $head $merge)
61 echo "Trying to find the optimum merge base."
68 GIT_INDEX_FILE
=$G git-read-tree
-m $c $head $merge \
69 2>/dev
/null ||
continue
70 # Count the paths that are unmerged.
71 cnt
=`GIT_INDEX_FILE=$G git-ls-files --unmerged | wc -l`
72 if test $best_cnt -le 0 -o $cnt -le $best_cnt
76 if test "$best_cnt" -eq 0
78 # Cannot do any better than all trivial merge.
87 echo "Trying to merge $merge into $head using $common."
88 git-update-index
--refresh 2>/dev
/null
89 git-read-tree
-u -m $common $head $merge ||
exit 1
90 result_tree
=$
(git-write-tree
2> /dev
/null
)
92 echo "Simple merge failed, trying Automatic merge"
93 git-merge-index
-o git-merge-one-file
-a
95 echo $merge > "$GIT_DIR"/MERGE_HEAD
96 die
"Automatic merge failed, fix up by hand"
98 result_tree
=$
(git-write-tree
) ||
exit 1
100 result_commit
=$
(echo "$merge_msg" | git-commit-tree
$result_tree -p $head -p $merge)
101 echo "Committed merge $result_commit"
102 git-update-ref HEAD
"$result_commit" "$head"
103 git-diff-tree
-p $head $result_commit | git-apply
--stat