git-pull-scripton commit [PATCH] simplify Makefile (6ca25ed)
   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
   9
  10echo "Getting object database"
  11rsync -avz --ignore-existing $merge_repo/objects/. .git/objects/.
  12
  13echo "Getting remote head"
  14rsync -L $merge_repo/HEAD .git/MERGE_HEAD || exit 1
  15
  16head=$(cat .git/HEAD)
  17merge_head=$(cat .git/MERGE_HEAD)
  18common=$(merge-base $head $merge_head)
  19if [ -z "$common" ]; then
  20        echo "Unable to find common commit between" $merge_head $head
  21        exit 1
  22fi
  23
  24# Get the trees associated with those commits
  25common_tree=$(cat-file commit $common | sed 's/tree //;q')
  26head_tree=$(cat-file commit $head | sed 's/tree //;q')
  27merge_tree=$(cat-file commit $merge_head | sed 's/tree //;q')
  28
  29if [ "$common" == "$merge_head" ]; then
  30        echo "Already up-to-date. Yeeah!"
  31        exit 0
  32fi
  33if [ "$common" == "$head" ]; then
  34        echo "Updating from $head to $merge_head."
  35        echo "Destroying all noncommitted data!"
  36        echo "Kill me within 3 seconds.."
  37        sleep 3
  38        read-tree -m $merge_tree && checkout-cache -f -a && update-cache --refresh
  39        echo $merge_head > .git/HEAD
  40        exit 0
  41fi
  42echo "Trying to merge $merge_head into $head"
  43read-tree -m $common_tree $head_tree $merge_tree
  44result_tree=$(write-tree) || exit 1
  45result_commit=$(echo "Merge $merge_repo" | commit-tree $result_tree -p $head -p $merge_head)
  46echo "Committed merge $result_commit"
  47echo $result_commit > .git/HEAD
  48checkout-cache -f -a && update-cache --refresh