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