git-resolve-scripton commit git-read-tree: be a lot more careful about merging dirty trees (02ede67)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Linus Torvalds
   4#
   5# Resolve two trees.
   6#
   7head="$1"
   8merge="$2"
   9merge_repo="$3"
  10
  11: ${GIT_DIR=.git}
  12: ${GIT_OBJECT_DIRECTORY="${SHA1_FILE_DIRECTORY-"$GIT_DIR/objects"}"}
  13
  14rm -f "$GIT_DIR"/MERGE_HEAD "$GIT_DIR"/ORIG_HEAD
  15echo $head > "$GIT_DIR"/ORIG_HEAD
  16echo $merge > "$GIT_DIR"/MERGE_HEAD
  17
  18#
  19# The remote name is just used for the message,
  20# but we do want it.
  21#
  22if [ "$merge_repo" == "" ]; then
  23        echo "git-resolve-script <head> <remote> <merge-repo-name>"
  24        exit 1
  25fi
  26
  27common=$(git-merge-base $head $merge)
  28if [ -z "$common" ]; then
  29        echo "Unable to find common commit between" $merge $head
  30        exit 1
  31fi
  32
  33if [ "$common" == "$merge" ]; then
  34        echo "Already up-to-date. Yeeah!"
  35        exit 0
  36fi
  37if [ "$common" == "$head" ]; then
  38        echo "Updating from $head to $merge."
  39        echo "Destroying all noncommitted data!"
  40        echo "Kill me within 3 seconds.."
  41        sleep 3
  42        git-read-tree -m $merge || exit 1
  43        git-checkout-cache -f -u -a
  44        echo $merge > "$GIT_DIR"/HEAD
  45        git-diff-tree -p ORIG_HEAD HEAD | git-apply --stat
  46        exit 0
  47fi
  48echo "Trying to merge $merge into $head"
  49git-read-tree -m $common $head $merge || exit 1
  50merge_msg="Merge of $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 git-merge-one-file-script -a
  55        merge_msg="Automatic merge of $merge_repo"
  56        result_tree=$(git-write-tree) || exit 1
  57fi
  58result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree -p $head -p $merge)
  59echo "Committed merge $result_commit"
  60echo $result_commit > "$GIT_DIR"/HEAD
  61git-checkout-cache -f -u -a
  62git-diff-tree -p ORIG_HEAD HEAD | git-apply --stat