1#!/bin/sh 2# 3# Copyright (c) 2005 Junio C Hamano 4# 5# Resolve two or more trees. 6# 7 8LF=' 9' 10 11die () { 12echo>&2"$*" 13exit1 14} 15 16# The first parameters up to -- are merge bases; the rest are heads. 17bases=head= remotes= sep_seen= 18for arg 19do 20case",$sep_seen,$head,$arg,"in 21*,--,) 22 sep_seen=yes 23;; 24,yes,,*) 25head=$arg 26;; 27,yes,*) 28 remotes="$remotes$arg" 29;; 30*) 31 bases="$bases$arg" 32;; 33esac 34done 35 36# Reject if this is not an Octopus -- resolve should be used instead. 37case"$remotes"in 38?*' '?*) 39;; 40*) 41exit2;; 42esac 43 44# MRC is the current "merge reference commit" 45# MRT is the current "merge result tree" 46 47MRC=$(git rev-parse --verify -q $head) 48MRT=$(git write-tree) 49NON_FF_MERGE=0 50OCTOPUS_FAILURE=0 51for SHA1 in$remotes 52do 53case"$OCTOPUS_FAILURE"in 541) 55# We allow only last one to have a hand-resolvable 56# conflicts. Last round failed and we still had 57# a head to merge. 58echo"Automated merge did not work." 59echo"Should not be doing an Octopus." 60exit2 61esac 62 63eval pretty_name=\${GITHEAD_$SHA1:-$SHA1} 64iftest"$SHA1"="$pretty_name" 65then 66 SHA1_UP="$(echo "$SHA1" | tr a-z A-Z)" 67eval pretty_name=\${GITHEAD_$SHA1_UP:-$pretty_name} 68fi 69 common=$(git merge-base --all $SHA1 $MRC)|| 70 die "Unable to find common commit with$pretty_name" 71 72case"$LF$common$LF"in 73*"$LF$SHA1$LF"*) 74echo"Already up-to-date with$pretty_name" 75continue 76;; 77esac 78 79iftest"$common,$NON_FF_MERGE"="$MRC,0" 80then 81# The first head being merged was a fast-forward. 82# Advance MRC to the head being merged, and use that 83# tree as the intermediate result of the merge. 84# We still need to count this as part of the parent set. 85 86echo"Fast-forwarding to:$pretty_name" 87 git read-tree -u -m$head $SHA1||exit 88 MRC=$SHA1 MRT=$(git write-tree) 89continue 90fi 91 92 NON_FF_MERGE=1 93 94echo"Trying simple merge with$pretty_name" 95 git read-tree -u -m --aggressive$common $MRT $SHA1||exit2 96 next=$(git write-tree 2>/dev/null) 97iftest $? -ne0 98then 99echo"Simple merge did not work, trying automatic merge." 100 git-merge-index -o git-merge-one-file -a|| 101 OCTOPUS_FAILURE=1 102 next=$(git write-tree 2>/dev/null) 103fi 104 105 MRC="$MRC$SHA1" 106 MRT=$next 107done 108 109exit"$OCTOPUS_FAILURE"