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