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 AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' .dotest/info)"
28export AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' .dotest/info)"
29export SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' .dotest/info)"
30
31if [ -n "$signoff" -a -f "$signoff" ]; then
32 cat $signoff >> $MSGFILE
33fi
34
35(echo "[PATCH] $SUBJECT" ; echo ; cat $MSGFILE ) > $final
36
37f=0
38[ -f $query_apply ] || f=1
39
40while [ $f -eq 0 ]; do
41 echo "Commit Body is:"
42 echo "--------------------------"
43 cat $final
44 echo "--------------------------"
45 echo -n "Apply? [y]es/[n]o/[e]dit/[a]ccept all "
46 read reply
47 case $reply in
48 y|Y) f=1;;
49 n|N) exit 2;; # special value to tell dotest to keep going
50 e|E) $EDIT $final;;
51 a|A) rm -f $query_apply
52 f=1;;
53 esac
54done
55
56echo
57echo Applying "'$SUBJECT'"
58echo
59
60check-files $(cat $FILES) || exit 1
61checkout-cache -q $(cat $FILES) || exit 1
62patch -u --no-backup-if-mismatch -f -p1 --fuzz=0 --input=$PATCHFILE || exit 1
63update-cache --add --remove $(cat $FILES) || exit 1
64tree=$(write-tree) || exit 1
65echo Wrote tree $tree
66commit=$(commit-tree $tree -p $(cat .git/HEAD) < $final) || exit 1
67echo Committed: $commit
68echo $commit > .git/HEAD
69