git-resolve-scripton commit [PATCH] Make sq_expand() available as sq_quote(). (6fb737b)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5# Resolve two trees.
   6#
   7. git-sh-setup-script || die "Not a git archive"
   8
   9head=$(git-rev-parse --revs-only "$1")
  10merge=$(git-rev-parse --revs-only "$2")
  11merge_repo="$3"
  12
  13dropheads() {
  14        rm -f -- "$GIT_DIR/MERGE_HEAD" \
  15                "$GIT_DIR/LAST_MERGE" || exit 1
  16}
  17
  18#
  19# The remote name is just used for the message,
  20# but we do want it.
  21#
  22if [ -z "$head" -o -z "$merge" -o -z "$merge_repo" ]; then
  23        die "git-resolve-script <head> <remote> <merge-repo-name>"
  24fi
  25
  26dropheads
  27echo $head > "$GIT_DIR"/ORIG_HEAD
  28echo $merge > "$GIT_DIR"/LAST_MERGE
  29
  30common=$(git-merge-base $head $merge)
  31if [ -z "$common" ]; then
  32        die "Unable to find common commit between" $merge $head
  33fi
  34
  35if [ "$common" == "$merge" ]; then
  36        echo "Already up-to-date. Yeeah!"
  37        dropheads
  38        exit 0
  39fi
  40if [ "$common" == "$head" ]; then
  41        echo "Updating from $head to $merge."
  42        git-read-tree -u -m $head $merge || exit 1
  43        echo $merge > "$GIT_DIR"/HEAD
  44        git-diff-tree -p $head $merge | git-apply --stat
  45        dropheads
  46        exit 0
  47fi
  48echo "Trying to merge $merge into $head"
  49git-read-tree -u -m $common $head $merge || exit 1
  50merge_msg="Merge $merge_repo"
  51result_tree=$(git-write-tree  2> /dev/null)
  52if [ $? -ne 0 ]; then
  53        echo "Simple merge failed, trying Automatic merge"
  54        git-merge-cache -o git-merge-one-file-script -a
  55        if [ $? -ne 0 ]; then
  56                echo $merge > "$GIT_DIR"/MERGE_HEAD
  57                die "Automatic merge failed, fix up by hand"
  58        fi
  59        result_tree=$(git-write-tree) || exit 1
  60fi
  61result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
  62echo "Committed merge $result_commit"
  63echo $result_commit > "$GIT_DIR"/HEAD
  64git-diff-tree -p $head $result_commit | git-apply --stat
  65dropheads