]> git.ipfire.org Git - thirdparty/git.git/blame - git-merge-octopus.sh
fast-import: introduce "feature notes" command
[thirdparty/git.git] / git-merge-octopus.sh
CommitLineData
91063bbc
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5# Resolve two or more trees.
6#
7
17cf9397
JH
8LF='
9'
10
d165fa14
JH
11die () {
12 echo >&2 "$*"
13 exit 1
14}
15
91063bbc
JH
16# The first parameters up to -- are merge bases; the rest are heads.
17bases= head= remotes= sep_seen=
18for arg
19do
20 case ",$sep_seen,$head,$arg," in
21 *,--,)
22 sep_seen=yes
23 ;;
24 ,yes,,*)
25 head=$arg
26 ;;
27 ,yes,*)
28 remotes="$remotes$arg "
29 ;;
30 *)
31 bases="$bases$arg "
32 ;;
33 esac
34done
35
36# Reject if this is not an Octopus -- resolve should be used instead.
37case "$remotes" in
38?*' '?*)
39 ;;
40*)
41 exit 2 ;;
42esac
43
44# MRC is the current "merge reference commit"
45# MRT is the current "merge result tree"
46
f08aa017 47MRC=$(git rev-parse --verify -q $head)
5be60078 48MRT=$(git write-tree)
91063bbc 49NON_FF_MERGE=0
98efc8f3 50OCTOPUS_FAILURE=0
91063bbc
JH
51for SHA1 in $remotes
52do
98efc8f3
JH
53 case "$OCTOPUS_FAILURE" in
54 1)
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.
58 echo "Automated merge did not work."
59 echo "Should not be doing an Octopus."
60 exit 2
61 esac
62
81334502 63 eval pretty_name=\${GITHEAD_$SHA1:-$SHA1}
c5dc9a28 64 common=$(git merge-base --all $SHA1 $MRC) ||
81334502 65 die "Unable to find common commit with $pretty_name"
91063bbc 66
c884dd9a
JH
67 case "$LF$common$LF" in
68 *"$LF$SHA1$LF"*)
81334502 69 echo "Already up-to-date with $pretty_name"
91063bbc 70 continue
17cf9397
JH
71 ;;
72 esac
91063bbc 73
91063bbc
JH
74 if test "$common,$NON_FF_MERGE" = "$MRC,0"
75 then
76 # The first head being merged was a fast-forward.
77 # Advance MRC to the head being merged, and use that
78 # tree as the intermediate result of the merge.
79 # We still need to count this as part of the parent set.
80
81334502 81 echo "Fast-forwarding to: $pretty_name"
5be60078
JH
82 git read-tree -u -m $head $SHA1 || exit
83 MRC=$SHA1 MRT=$(git write-tree)
91063bbc
JH
84 continue
85 fi
86
87 NON_FF_MERGE=1
88
81334502 89 echo "Trying simple merge with $pretty_name"
5be60078
JH
90 git read-tree -u -m --aggressive $common $MRT $SHA1 || exit 2
91 next=$(git write-tree 2>/dev/null)
91063bbc
JH
92 if test $? -ne 0
93 then
94 echo "Simple merge did not work, trying automatic merge."
98efc8f3
JH
95 git-merge-index -o git-merge-one-file -a ||
96 OCTOPUS_FAILURE=1
5be60078 97 next=$(git write-tree 2>/dev/null)
91063bbc 98 fi
17cf9397 99
c5dc9a28 100 MRC="$MRC $SHA1"
91063bbc
JH
101 MRT=$next
102done
103
98efc8f3 104exit "$OCTOPUS_FAILURE"