Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Linus Torvalds |
Junio C Hamano | 2276aa6 | 2005-09-10 17:56:19 -0700 | [diff] [blame] | 4 | # Copyright (c) 2005 Junio C Hamano |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 5 | # |
Pavel Roskin | 3dff537 | 2007-02-03 23:49:16 -0500 | [diff] [blame] | 6 | # Resolve two trees, using enhanced multi-base read-tree. |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 7 | |
Elijah Newren | 24ba8b7 | 2022-07-23 01:53:12 +0000 | [diff] [blame] | 8 | . git-sh-setup |
| 9 | |
| 10 | # Abort if index does not match HEAD |
| 11 | if ! git diff-index --quiet --cached HEAD -- |
| 12 | then |
| 13 | gettextln "Error: Your local changes to the following files would be overwritten by merge" |
| 14 | git diff-index --cached --name-only HEAD -- | sed -e 's/^/ /' |
| 15 | exit 2 |
| 16 | fi |
| 17 | |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 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 | |
Tom Clarke | 7d3c82a | 2007-08-30 23:12:44 +0200 | [diff] [blame] | 38 | # Give up if we are given two or more remotes -- not handling octopus. |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 39 | case "$remotes" in |
| 40 | ?*' '?*) |
| 41 | exit 2 ;; |
| 42 | esac |
| 43 | |
Fredrik Kuivinen | 88f8f0a | 2005-10-03 08:13:09 +0200 | [diff] [blame] | 44 | # Give up if this is a baseless merge. |
| 45 | if test '' = "$bases" |
| 46 | then |
| 47 | exit 2 |
| 48 | fi |
| 49 | |
Dan Loewenherz | 7bd93c1 | 2009-04-22 21:46:02 -0400 | [diff] [blame] | 50 | git update-index -q --refresh |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 51 | git read-tree -u -m --aggressive $bases $head $remotes || exit 2 |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 52 | echo "Trying simple merge." |
Dan Loewenherz | 7bd93c1 | 2009-04-22 21:46:02 -0400 | [diff] [blame] | 53 | if result_tree=$(git write-tree 2>/dev/null) |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 54 | then |
| 55 | exit 0 |
| 56 | else |
| 57 | echo "Simple merge failed, trying Automatic merge." |
Michael Forney | 974ce80 | 2017-08-04 23:49:05 -0700 | [diff] [blame] | 58 | if git merge-index -o git-merge-one-file -a |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 59 | then |
| 60 | exit 0 |
| 61 | else |
| 62 | exit 1 |
| 63 | fi |
| 64 | fi |