Fix SIGSEGV on unmerged files in git-diff-files -p
[git/vmiklos.git] / git-resolve-script
blobda79a973eaafa1b8b7e21b719698762896e13569
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
5 # Resolve two trees.
7 head="$1"
8 merge="$2"
9 merge_repo="$3"
11 : ${GIT_DIR=.git}
12 : ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
14 rm -f "$GIT_DIR"/MERGE_HEAD "$GIT_DIR"/ORIG_HEAD
15 echo $head > "$GIT_DIR"/ORIG_HEAD
16 echo $merge > "$GIT_DIR"/MERGE_HEAD
19 # The remote name is just used for the message,
20 # but we do want it.
22 if [ "$merge_repo" == "" ]; then
23 echo "git-resolve-script <head> <remote> <merge-repo-name>"
24 exit 1
27 common=$(git-merge-base $head $merge)
28 if [ -z "$common" ]; then
29 echo "Unable to find common commit between" $merge $head
30 exit 1
33 if [ "$common" == "$merge" ]; then
34 echo "Already up-to-date. Yeeah!"
35 exit 0
37 if [ "$common" == "$head" ]; then
38 echo "Updating from $head to $merge."
39 git-read-tree -u -m $head $merge || exit 1
40 echo $merge > "$GIT_DIR"/HEAD
41 git-diff-tree -p ORIG_HEAD HEAD | git-apply --stat
42 exit 0
44 echo "Trying to merge $merge into $head"
45 git-read-tree -u -m $common $head $merge || exit 1
46 merge_msg="Merge $merge_repo"
47 result_tree=$(git-write-tree 2> /dev/null)
48 if [ $? -ne 0 ]; then
49 echo "Simple merge failed, trying Automatic merge"
50 git-merge-cache -o git-merge-one-file-script -a
51 if [ $? -ne 0 ]; then
52 echo "Automatic merge failed, fix up by hand"
53 exit 1
55 result_tree=$(git-write-tree) || exit 1
57 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
58 echo "Committed merge $result_commit"
59 echo $result_commit > "$GIT_DIR"/HEAD
60 git-diff-tree -p ORIG_HEAD HEAD | git-apply --stat