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