blob: 77e93121bf8c19714b19097b4739b206230677cb [file] [log] [blame]
Junio C Hamano91063bb2005-09-08 13:47:12 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Linus Torvalds
Junio C Hamano2276aa62005-09-10 17:56:19 -07004# Copyright (c) 2005 Junio C Hamano
Junio C Hamano91063bb2005-09-08 13:47:12 -07005#
Pavel Roskin3dff5372007-02-03 23:49:16 -05006# Resolve two trees, using enhanced multi-base read-tree.
Junio C Hamano91063bb2005-09-08 13:47:12 -07007
Elijah Newren24ba8b72022-07-23 01:53:12 +00008. git-sh-setup
9
10# Abort if index does not match HEAD
11if ! git diff-index --quiet --cached HEAD --
12then
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
16fi
17
Junio C Hamano91063bb2005-09-08 13:47:12 -070018# The first parameters up to -- are merge bases; the rest are heads.
19bases= head= remotes= sep_seen=
20for arg
21do
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
36done
37
Tom Clarke7d3c82a2007-08-30 23:12:44 +020038# Give up if we are given two or more remotes -- not handling octopus.
Junio C Hamano91063bb2005-09-08 13:47:12 -070039case "$remotes" in
40?*' '?*)
41 exit 2 ;;
42esac
43
Fredrik Kuivinen88f8f0a2005-10-03 08:13:09 +020044# Give up if this is a baseless merge.
45if test '' = "$bases"
46then
47 exit 2
48fi
49
Dan Loewenherz7bd93c12009-04-22 21:46:02 -040050git update-index -q --refresh
Junio C Hamano5be60072007-07-02 22:52:14 -070051git read-tree -u -m --aggressive $bases $head $remotes || exit 2
Junio C Hamano91063bb2005-09-08 13:47:12 -070052echo "Trying simple merge."
Dan Loewenherz7bd93c12009-04-22 21:46:02 -040053if result_tree=$(git write-tree 2>/dev/null)
Junio C Hamano91063bb2005-09-08 13:47:12 -070054then
55 exit 0
56else
57 echo "Simple merge failed, trying Automatic merge."
Michael Forney974ce802017-08-04 23:49:05 -070058 if git merge-index -o git-merge-one-file -a
Junio C Hamano91063bb2005-09-08 13:47:12 -070059 then
60 exit 0
61 else
62 exit 1
63 fi
64fi