1#!/bin/sh 2# 3# Copyright (c) 2005 Junio C Hamano 4# 5# Resolve two or more trees. 6# 7 8# The first parameters up to -- are merge bases; the rest are heads. 9bases=head= remotes= sep_seen= 10for arg 11do 12case",$sep_seen,$head,$arg,"in 13*,--,) 14 sep_seen=yes 15;; 16,yes,,*) 17head=$arg 18;; 19,yes,*) 20 remotes="$remotes$arg" 21;; 22*) 23 bases="$bases$arg" 24;; 25esac 26done 27 28# Reject if this is not an Octopus -- resolve should be used instead. 29case"$remotes"in 30?*' '?*) 31;; 32*) 33exit2;; 34esac 35 36# MRC is the current "merge reference commit" 37# MRT is the current "merge result tree" 38 39MRC=$head MSG= PARENT="-p$head" 40MRT=$(git-write-tree) 41CNT=1;# counting our head 42NON_FF_MERGE=0 43for SHA1 in$remotes 44do 45 common=$(git-merge-base $MRC $SHA1)|| 46 die "Unable to find common commit with$SHA1" 47 48iftest"$common"=$SHA1 49then 50echo"Already up-to-date with$SHA1" 51continue 52fi 53 54 CNT=`expr$CNT+ 1` 55 PARENT="$PARENT-p$SHA1" 56 57iftest"$common,$NON_FF_MERGE"="$MRC,0" 58then 59# The first head being merged was a fast-forward. 60# Advance MRC to the head being merged, and use that 61# tree as the intermediate result of the merge. 62# We still need to count this as part of the parent set. 63 64echo"Fast forwarding to:$SHA1" 65 git-read-tree -u -m$head $SHA1||exit 66 MRC=$SHA1 MRT=$(git-write-tree) 67continue 68fi 69 70 NON_FF_MERGE=1 71 72echo"Trying simple merge with$SHA1" 73 git-read-tree -u -m$common $MRT $SHA1||exit2 74 next=$(git-write-tree 2>/dev/null) 75iftest $? -ne0 76then 77echo"Simple merge did not work, trying automatic merge." 78 git-merge-index -o git-merge-one-file -a|| 79exit2;# Automatic merge failed; should not be doing Octopus 80 next=$(git-write-tree 2>/dev/null) 81fi 82 MRC=$common 83 MRT=$next 84done 85 86exit0