tools / git-applypatchon commit Rename the "tools" programs to also have the "git-" prefix (fd1fcd9)
   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 - "info" file with Author, email and subject
  11##      $4 - optional file containing signoff to add
  12##
  13signoff="$4"
  14final=.dotest/final-commit
  15##
  16## If this file exists, we ask before applying
  17##
  18query_apply=.dotest/.query_apply
  19MSGFILE=$1
  20PATCHFILE=$2
  21INFO=$3
  22EDIT=${VISUAL:-$EDITOR}
  23EDIT=${EDIT:-vi}
  24
  25export GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' .dotest/info)"
  26export GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' .dotest/info)"
  27export GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' .dotest/info)"
  28export SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' .dotest/info)"
  29
  30if [ -n "$signoff" -a -f "$signoff" ]; then
  31        cat $signoff >> $MSGFILE
  32fi
  33
  34(echo "[PATCH] $SUBJECT" ; if [ -s $MSGFILE ]; then echo ; cat $MSGFILE; fi ) > $final
  35
  36f=0
  37[ -f $query_apply ] || f=1
  38
  39while [ $f -eq 0 ]; do
  40        echo "Commit Body is:"
  41        echo "--------------------------"
  42        cat $final
  43        echo "--------------------------"
  44        echo -n "Apply? [y]es/[n]o/[e]dit/[a]ccept all "
  45        read reply
  46        case $reply in
  47                y|Y) f=1;;
  48                n|N) exit 2;;   # special value to tell dotest to keep going
  49                e|E) $EDIT $final;;
  50                a|A) rm -f $query_apply
  51                     f=1;;
  52        esac
  53done
  54
  55echo
  56echo Applying "'$SUBJECT'"
  57echo
  58
  59git-apply --index $PATCHFILE || exit 1
  60tree=$(git-write-tree) || exit 1
  61echo Wrote tree $tree
  62commit=$(git-commit-tree $tree -p $(cat .git/HEAD) < $final) || exit 1
  63echo Committed: $commit
  64echo $commit > .git/HEAD