Work around an RPM build problem.
[alt-git.git] / git-merge-octopus.sh
blobaa1cd2f10667baa7eeb4db34a0bce2e6c31a1c79
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
5 # Resolve two or more trees.
8 # The first parameters up to -- are merge bases; the rest are heads.
9 bases= head= remotes= sep_seen=
10 for arg
12 case ",$sep_seen,$head,$arg," in
13 *,--,)
14 sep_seen=yes
16 ,yes,,*)
17 head=$arg
19 ,yes,*)
20 remotes="$remotes$arg "
23 bases="$bases$arg "
25 esac
26 done
28 # Reject if this is not an Octopus -- resolve should be used instead.
29 case "$remotes" in
30 ?*' '?*)
33 exit 2 ;;
34 esac
36 # MRC is the current "merge reference commit"
37 # MRT is the current "merge result tree"
39 MRC=$head MSG= PARENT="-p $head"
40 MRT=$(git-write-tree)
41 CNT=1 ;# counting our head
42 NON_FF_MERGE=0
43 for SHA1 in $remotes
45 common=$(git-merge-base $MRC $SHA1) ||
46 die "Unable to find common commit with $SHA1"
48 if test "$common" = $SHA1
49 then
50 echo "Already up-to-date with $SHA1"
51 continue
54 CNT=`expr $CNT + 1`
55 PARENT="$PARENT -p $SHA1"
57 if test "$common,$NON_FF_MERGE" = "$MRC,0"
58 then
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.
64 echo "Fast forwarding to: $SHA1"
65 git-read-tree -u -m $head $SHA1 || exit
66 MRC=$SHA1 MRT=$(git-write-tree)
67 continue
70 NON_FF_MERGE=1
72 echo "Trying simple merge with $SHA1"
73 git-read-tree -u -m $common $MRT $SHA1 || exit 2
74 next=$(git-write-tree 2>/dev/null)
75 if test $? -ne 0
76 then
77 echo "Simple merge did not work, trying automatic merge."
78 git-merge-index -o git-merge-one-file -a ||
79 exit 2 ; # Automatic merge failed; should not be doing Octopus
80 next=$(git-write-tree 2>/dev/null)
82 MRC=$common
83 MRT=$next
84 done
86 exit 0