[PATCH] clone-pack.c:write_one_ref() - Create leading directories.
[alt-git.git] / git-resolve-script
blobbf2fb2d431da4702cd2b5fe3f414ce22c7ab284d
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
5 # Resolve two trees.
7 head=$(git-rev-parse --revs-only "$1")
8 merge=$(git-rev-parse --revs-only "$2")
9 merge_repo="$3"
11 : ${GIT_DIR=.git}
12 : ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
14 dropheads() {
15 rm -f -- "$GIT_DIR/MERGE_HEAD" \
16 "$GIT_DIR/LAST_MERGE" || exit 1
20 # The remote name is just used for the message,
21 # but we do want it.
23 if [ -z "$head" -o -z "$merge" -o -z "$merge_repo" ]; then
24 echo "git-resolve-script <head> <remote> <merge-repo-name>"
25 exit 1
28 dropheads
29 echo $head > "$GIT_DIR"/ORIG_HEAD
30 echo $merge > "$GIT_DIR"/LAST_MERGE
32 common=$(git-merge-base $head $merge)
33 if [ -z "$common" ]; then
34 echo "Unable to find common commit between" $merge $head
35 exit 1
38 if [ "$common" == "$merge" ]; then
39 echo "Already up-to-date. Yeeah!"
40 dropheads
41 exit 0
43 if [ "$common" == "$head" ]; then
44 echo "Updating from $head to $merge."
45 git-read-tree -u -m $head $merge || exit 1
46 echo $merge > "$GIT_DIR"/HEAD
47 git-diff-tree -p $head $merge | git-apply --stat
48 dropheads
49 exit 0
51 echo "Trying to merge $merge into $head"
52 git-read-tree -u -m $common $head $merge || exit 1
53 merge_msg="Merge $merge_repo"
54 result_tree=$(git-write-tree 2> /dev/null)
55 if [ $? -ne 0 ]; then
56 echo "Simple merge failed, trying Automatic merge"
57 git-merge-cache -o git-merge-one-file-script -a
58 if [ $? -ne 0 ]; then
59 echo $merge > "$GIT_DIR"/MERGE_HEAD
60 echo "Automatic merge failed, fix up by hand"
61 exit 1
63 result_tree=$(git-write-tree) || exit 1
65 result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
66 echo "Committed merge $result_commit"
67 echo $result_commit > "$GIT_DIR"/HEAD
68 git-diff-tree -p $head $result_commit | git-apply --stat
69 dropheads