applypatchon commit applypatch: use the new git-apply to apply patches (97b865b)
   1#!/bin/sh
   2##
   3## applypatch takes four file arguments, and uses those to
   4## apply the unpacked patch (surprise surprise) that they
   5## represent to the current tree.
   6##
   7## The arguments are:
   8##      $1 - file with commit message
   9##      $2 - file with the actual patch
  10##      $3 - file with list of filenames the patch touches
  11##      $4 - "info" file with Author, email and subject
  12##      $5 - optional file containing signoff to add
  13##
  14signoff="$5"
  15final=.dotest/final-commit
  16##
  17## If this file exists, we ask before applying
  18##
  19query_apply=.dotest/.query_apply
  20MSGFILE=$1
  21PATCHFILE=$2
  22FILES=$3
  23INFO=$4
  24EDIT=${VISUAL:-$EDITOR}
  25EDIT=${EDIT:-vi}
  26
  27export GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' .dotest/info)"
  28export GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' .dotest/info)"
  29export GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' .dotest/info)"
  30export SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' .dotest/info)"
  31
  32if [ -n "$signoff" -a -f "$signoff" ]; then
  33        cat $signoff >> $MSGFILE
  34fi
  35
  36(echo "[PATCH] $SUBJECT" ; if [ -s $MSGFILE ]; then echo ; cat $MSGFILE; fi ) > $final
  37
  38f=0
  39[ -f $query_apply ] || f=1
  40
  41while [ $f -eq 0 ]; do
  42        echo "Commit Body is:"
  43        echo "--------------------------"
  44        cat $final
  45        echo "--------------------------"
  46        echo -n "Apply? [y]es/[n]o/[e]dit/[a]ccept all "
  47        read reply
  48        case $reply in
  49                y|Y) f=1;;
  50                n|N) exit 2;;   # special value to tell dotest to keep going
  51                e|E) $EDIT $final;;
  52                a|A) rm -f $query_apply
  53                     f=1;;
  54        esac
  55done
  56
  57echo
  58echo Applying "'$SUBJECT'"
  59echo
  60
  61git-apply $PATCHFILE || exit 1
  62tree=$(git-write-tree) || exit 1
  63echo Wrote tree $tree
  64commit=$(git-commit-tree $tree -p $(cat .git/HEAD) < $final) || exit 1
  65echo Committed: $commit
  66echo $commit > .git/HEAD