Skip to content

Commit

Permalink
contrib exit messages
Browse files Browse the repository at this point in the history
clean up the error messages in the contrib script. well... to be more
precise, actually _add_ some error messages to the script.
  • Loading branch information
JohnMurray committed Nov 10, 2015
1 parent aaa6143 commit 81fb339
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions contrib/pre-commit-hook-static-dba-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/../.."
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 81fb339

Please sign in to comment.