git-pull-scripton commit [PATCH] show-diff.c: -R option for reverse diff. (4789576)
   1#!/bin/sh
   2#
   3# use "$1" or something in a real script, this 
   4# just hard-codes it.
   5#
   6merge_repo=$1
   7
   8echo "Getting object database"
   9rsync -avz --ignore-existing $merge_repo/ .git/
  10
  11echo "Getting remote head"
  12rsync -avz $merge_repo/HEAD .git/MERGE_HEAD
  13
  14head=$(cat .git/HEAD)
  15merge_head=$(cat .git/MERGE_HEAD)
  16common=$(merge-base $head $merge_head)
  17if [ -z "$common" ]; then
  18        echo "Unable to find common commit between" $merge_head $head
  19        exit 1
  20fi
  21
  22# Get the trees associated with those commits
  23common_tree=$(cat-file commit $common | sed 's/tree //;q')
  24head_tree=$(cat-file commit $head | sed 's/tree //;q')
  25merge_tree=$(cat-file commit $merge_head | sed 's/tree //;q')
  26
  27if [ "$common" == "$merge_head" ]; then
  28        echo "Already up-to-date. Yeeah!"
  29        exit 0
  30fi
  31if [ "$common" == "$head" ]; then
  32        echo "Updating from $head to $merge_head."
  33        echo "Destroying all noncommitted data!"
  34        echo "Kill me within 3 seconds.."
  35        sleep 3
  36        read-tree $merge_tree && checkout-cache -f -a && update-cache --refresh
  37        echo $merge_head > .git/HEAD
  38        exit 0
  39fi
  40echo "Trying to merge $merge_head into $head"
  41read-tree -m $common_tree $head_tree $merge_tree
  42result_tree=$(write-tree) || exit 1
  43result_commit=$(echo "Merge $merge_repo" | commit-tree $result_tree -p $head -p $merge_head)
  44echo "Committed merge $result_commit"
  45echo $result_commit > .git/HEAD
  46read-tree $result_tree && checkout-cache -f -a && update-cache --refresh