3 # Copyright (c) 2005 Linus Torvalds
8 USAGE='<head> <remote> <merge-message>'
12 rm -f -- "$GIT_DIR/MERGE_HEAD" \
13 "$GIT_DIR/LAST_MERGE" || exit 1
16 head=$(git-rev-parse --verify "$1"^0) &&
17 merge=$(git-rev-parse --verify "$2"^0) &&
18 merge_msg="$3" || usage
21 # The remote name is just used for the message,
24 if [ -z "$head" -o -z "$merge" -o -z "$merge_msg" ]; then
29 echo $head > "$GIT_DIR"/ORIG_HEAD
30 echo $merge > "$GIT_DIR"/LAST_MERGE
32 common=$(git-merge-base $head $merge)
33 if [ -z "$common" ]; then
34 die "Unable to find common commit between" $merge $head
39 echo "Already up-to-date. Yeeah!"
44 echo "Updating from $head to $merge"
45 git-read-tree -u -m $head $merge || exit 1
46 git-update-ref HEAD "$merge" "$head"
47 git-diff-tree -p $head $merge | git-apply --stat
53 # We are going to make a new commit.
54 git var GIT_COMMITTER_IDENT >/dev/null || exit
56 # Find an optimum merge base if there are more than one candidates.
59 common=$(git-merge-base -a $head $merge)
62 echo "Trying to find the optimum merge base."
69 GIT_INDEX_FILE=$G git-read-tree -m $c $head $merge \
70 2>/dev/null || continue
71 # Count the paths that are unmerged.
72 cnt=`GIT_INDEX_FILE=$G git-ls-files --unmerged | wc -l`
73 if test $best_cnt -le 0 -o $cnt -le $best_cnt
77 if test "$best_cnt" -eq 0
79 # Cannot do any better than all trivial merge.
88 echo "Trying to merge $merge into $head using $common."
89 git-update-index --refresh 2>/dev/null
90 git-read-tree -u -m $common $head $merge || exit 1
91 result_tree=$(git-write-tree 2> /dev/null)
93 echo "Simple merge failed, trying Automatic merge"
94 git-merge-index -o git-merge-one-file -a
96 echo $merge > "$GIT_DIR"/MERGE_HEAD
97 die "Automatic merge failed, fix up by hand"
99 result_tree=$(git-write-tree) || exit 1
101 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
102 echo "Committed merge $result_commit"
103 git-update-ref HEAD "$result_commit" "$head"
104 git-diff-tree -p $head $result_commit | git-apply --stat