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