git-pull-scripton commit [PATCH] GIT: Honour SHA1_FILE_DIRECTORY env var in git-pull-script (d840b3b)
   1#!/bin/sh
   2#
   3# use "$1" or something in a real script, this 
   4# just hard-codes it.
   5#
   6merge_repo=$1
   7
   8rm -f .git/MERGE_HEAD .git/ORIG_HEAD
   9cp .git/HEAD .git/ORIG_HEAD
  10
  11echo "Getting object database"
  12rsync -avz --ignore-existing $merge_repo/objects/. ${SHA1_FILE_DIRECTORY:-.git/objects}/.
  13
  14echo "Getting remote head"
  15rsync -L $merge_repo/HEAD .git/MERGE_HEAD || exit 1
  16
  17head=$(cat .git/HEAD)
  18merge_head=$(cat .git/MERGE_HEAD)
  19common=$(merge-base $head $merge_head)
  20if [ -z "$common" ]; then
  21        echo "Unable to find common commit between" $merge_head $head
  22        exit 1
  23fi
  24
  25# Get the trees associated with those commits
  26common_tree=$(cat-file commit $common | sed 's/tree //;q')
  27head_tree=$(cat-file commit $head | sed 's/tree //;q')
  28merge_tree=$(cat-file commit $merge_head | sed 's/tree //;q')
  29
  30if [ "$common" == "$merge_head" ]; then
  31        echo "Already up-to-date. Yeeah!"
  32        exit 0
  33fi
  34if [ "$common" == "$head" ]; then
  35        echo "Updating from $head to $merge_head."
  36        echo "Destroying all noncommitted data!"
  37        echo "Kill me within 3 seconds.."
  38        sleep 3
  39        read-tree -m $merge_tree && checkout-cache -f -a && update-cache --refresh
  40        echo $merge_head > .git/HEAD
  41        exit 0
  42fi
  43echo "Trying to merge $merge_head into $head"
  44read-tree -m $common_tree $head_tree $merge_tree
  45merge_msg="Merge of $merge_repo"
  46result_tree=$(write-tree  2> /dev/null)
  47if [ $? -ne 0 ]; then
  48        echo "Simple merge failed, trying Automatic merge"
  49        merge-cache git-merge-one-file-script -a
  50        merge_msg="Automatic merge of $merge_repo"
  51        result_tree=$(write-tree) || exit 1
  52fi
  53result_commit=$(echo "$merge_msg" | commit-tree $result_tree -p $head -p $merge_head)
  54echo "Committed merge $result_commit"
  55echo $result_commit > .git/HEAD
  56checkout-cache -f -a && update-cache --refresh