From 81fb339180b5fa77e5b9b2f84aa4d8f619c17257 Mon Sep 17 00:00:00 2001 From: John Murray Date: Tue, 10 Nov 2015 03:59:54 -0500 Subject: [PATCH] contrib exit messages clean up the error messages in the contrib script. well... to be more precise, actually _add_ some error messages to the script. --- contrib/pre-commit-hook-static-dba-files.sh | 29 ++++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/contrib/pre-commit-hook-static-dba-files.sh b/contrib/pre-commit-hook-static-dba-files.sh index f6b2474..3311d67 100755 --- a/contrib/pre-commit-hook-static-dba-files.sh +++ b/contrib/pre-commit-hook-static-dba-files.sh @@ -19,20 +19,23 @@ echoerr() { echo "$@" 1>&2; } # Utility function to exit if last command exited non-zero. -exit_if_err() { - if [[ $? -ne 0 ]] - then +ensure() { + if [[ $? -ne 0 ]] ; then + echoerr "Could not execute task: $1" + echoerr "Exiting..." exit 1 fi } -# The schema-tool has to be run from the directory where config.json lives, -# which may not be the same location as where the root of the project. So, we -# have to move the working directory of the script to the location of -# config.json (which is the same real path as this hook), but before doing so -# save the current working directory to a variable so that Git operations can -# be performed. +# This part is a bit tricky. In terms of getting the correct directories to +# work with. This makes the assumption that the alters sit in the root of the +# directory. This may not always be the case, but we can't reliably call `pwd` +# from this context. Sometimes git (seemingly) changes up the root directory +# of where the hooks are called from. Because of this we have to be limited +# to this assumption. +# +# If you need to change this, simply edit ORIG_DIR below HOOK_DIR="$( cd "$(dirname "$0")" ; pwd -P )" ORIG_DIR="$HOOK_DIR/../.." @@ -79,17 +82,17 @@ do SEEN+=($NODE) UP_RESULT=$(schema gen-sql -q -w $NODE) - exit_if_err + ensure "Generate UP alter for $NODE" DOWN_RESULT=$(schema gen-sql -q -w -d $NODE) - exit_if_err + ensure "Generate DOWN alter for $NODE" # Add the up and down files to git ADD_UP=$(cd $ORIG_DIR && git add "$UP_RESULT") - exit_if_err + ensure "Add $UP_RESULT to git" ADD_DOWN=$(cd $ORIG_DIR && git add "$DOWN_RESULT") - exit_if_err + ensure "Add $DOWN_RESULT to git" echo "Added file to commit (up): $UP_RESULT" echo "Added file to commit (down): $DOWN_RESULT"