From 0bc46caf491b62adf938f40d05d812c06fc27a62 Mon Sep 17 00:00:00 2001 From: nstbayless Date: Sat, 26 Aug 2017 23:45:34 -0700 Subject: [PATCH] pre-commit hook no longer generates patch; it fails if patch.ips is out of date. --- .gitignore | 2 ++ hooks/pre-commit | 27 ++++++++++++++++++++++----- make-patch.sh | 17 +++++++++++------ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 1c3376f..b63fe3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ base.nes +working.nes edit.nes +.patch-prev.ips diff --git a/hooks/pre-commit b/hooks/pre-commit index 3cf08ba..f1ed441 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -19,12 +19,29 @@ then fi # generate patch -./make-patch.sh +./make-patch.sh .patch-prev.ips -# pause to read input if successful: -if [ $? -eq 0 ] +if [ ! $? -eq 0 ] then - sleep 0.5 + chmod +wrx .patch-prev.ips + rm .patch-prev.ips + exit 2; fi -exit $? +test=`diff patch.ips .patch-prev.ips` + +chmod +wrx .patch-prev.ips +rm .patch-prev.ips + +if [ ! -z test ] +then + echo "Cannot commit while patch.ips is not up-to-date!" + echo "(Either run ./apply.sh to bring patch.ips up to date, or commit again with --no-verify)" + exit 1; +fi + +# pause to read input if successful: +sleep 0.5 + +exit 0 + diff --git a/make-patch.sh b/make-patch.sh index 1ad3636..b515f0c 100755 --- a/make-patch.sh +++ b/make-patch.sh @@ -3,6 +3,11 @@ # find flips patcher: flips="./flips/flips.exe" +outdir="patch.ips" +if [ $# -eq 1 ] +then + outdir="$1" +fi if [ "$op" = "Linux" ] then @@ -15,16 +20,16 @@ then exit 2; fi -echo "Generating patch.ips..." +echo "Generating $outdir..." -chmod u+w patch.ips +chmod u+w $outdir 2>/dev/null -rm patch.ips +rm $outdir 2>/dev/null -$flips --create --ips base.nes working.nes patch.ips +$flips --create --ips base.nes working.nes $outdir err=$? -chmod u+r patch.ips -chmod a-wx patch.ips +chmod u+r $outdir +chmod a-wx $outdir exit $?