blob: 93bcfc2f5dce418d00f26257788932d5c738785c [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
8# The first parameters up to -- are merge bases; the rest are heads.
9bases= head= remotes= sep_seen=
10for arg
11do
12 case ",$sep_seen,$head,$arg," in
13 *,--,)
14 sep_seen=yes
15 ;;
16 ,yes,,*)
17 head=$arg
18 ;;
19 ,yes,*)
20 remotes="$remotes$arg "
21 ;;
22 *)
23 bases="$bases$arg "
24 ;;
25 esac
26done
27
Tom Clarke7d3c82a2007-08-30 23:12:44 +020028# Give up if we are given two or more remotes -- not handling octopus.
Junio C Hamano91063bb2005-09-08 13:47:12 -070029case "$remotes" in
30?*' '?*)
31 exit 2 ;;
32esac
33
Fredrik Kuivinen88f8f0a2005-10-03 08:13:09 +020034# Give up if this is a baseless merge.
35if test '' = "$bases"
36then
37 exit 2
38fi
39
Junio C Hamano5be60072007-07-02 22:52:14 -070040git update-index --refresh 2>/dev/null
41git read-tree -u -m --aggressive $bases $head $remotes || exit 2
Junio C Hamano91063bb2005-09-08 13:47:12 -070042echo "Trying simple merge."
Junio C Hamano5be60072007-07-02 22:52:14 -070043if result_tree=$(git write-tree 2>/dev/null)
Junio C Hamano91063bb2005-09-08 13:47:12 -070044then
45 exit 0
46else
47 echo "Simple merge failed, trying Automatic merge."
48 if git-merge-index -o git-merge-one-file -a
49 then
50 exit 0
51 else
52 exit 1
53 fi
54fi