-
Notifications
You must be signed in to change notification settings - Fork 2
Dev Hooks
Jeremy Pallats/starcraft.man edited this page Sep 15, 2015
·
4 revisions
I may be a bit of a derp regarding pushing sometimes. So I am going to start using git hooks. I'll just list them here, put them in .git/hooks as usual.
pre-push
#!/usr/bin/env bash
# An example hook script to verify what is about to be pushed. Called by "git
# push" after it has checked the remote status, but before anything has been
# pushed. If this script exits with a non-zero status nothing will be pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
#
# If pushing without using a named remote those arguments will be equal.
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <local ref> <local sha1> <remote ref> <remote sha1>
#
# This sample shows how to prevent push of commits where the log message starts
# with "WIP" (work in progress).
# Run the basic test suite, if it fails don't push
echo "Verifying test suite first."
tox
retcode=$?
if [ "$retcode" != "0" ]; then
exit 1
fi
# Prevent me being stupid with master
cur_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ "$cur_branch" == "master" ]; then
read -p "WARNING: PUSH TO MASTER? (y/n) " -n 1 -r < /dev/tty
echo
if [ "${REPLY,,}" == "y"]; then
exit 0 # push will execute
else
exit 1
fi
fi