]> git.ipfire.org Git - thirdparty/git.git/blame - git-merge-resolve.sh
Documentation/RelNotes/2.45.0.txt: fix typo
[thirdparty/git.git] / git-merge-resolve.sh
CommitLineData
91063bbc
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Linus Torvalds
2276aa6c 4# Copyright (c) 2005 Junio C Hamano
91063bbc 5#
3dff5379 6# Resolve two trees, using enhanced multi-base read-tree.
91063bbc 7
24ba8b70
EN
8. 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
91063bbc
JH
18# 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
7d3c82a7 38# Give up if we are given two or more remotes -- not handling octopus.
91063bbc
JH
39case "$remotes" in
40?*' '?*)
41 exit 2 ;;
42esac
43
88f8f0a5
FK
44# Give up if this is a baseless merge.
45if test '' = "$bases"
46then
47 exit 2
48fi
49
7bd93c1c 50git update-index -q --refresh
5be60078 51git read-tree -u -m --aggressive $bases $head $remotes || exit 2
91063bbc 52echo "Trying simple merge."
7bd93c1c 53if result_tree=$(git write-tree 2>/dev/null)
91063bbc
JH
54then
55 exit 0
56else
57 echo "Simple merge failed, trying Automatic merge."
974ce807 58 if git merge-index -o git-merge-one-file -a
91063bbc
JH
59 then
60 exit 0
61 else
62 exit 1
63 fi
64fi