Skip to content

Instantly share code, notes, and snippets.

@dominikkukacka
Created June 2, 2014 09:02
Show Gist options
  • Save dominikkukacka/dbbe95929958ecc8f5de to your computer and use it in GitHub Desktop.
Save dominikkukacka/dbbe95929958ecc8f5de to your computer and use it in GitHub Desktop.
Git Hooks
#!/bin/bash
# prevents direct commits to develop and master branch
forbidden_branches=('develop' 'master')
function current_branch() {
echo `git rev-parse --abbrev-ref=strict HEAD | sed -n 1,1p`
}
branch=$(current_branch)
match=$(echo "${forbidden_branches[@]:0}" | grep -o $branch)
if [[ ! -z $match ]]; then
echo
echo " STOP THE PRESS!"
echo " You are trying to commit on the *$branch* branch."
echo " Surely you don't mean that?"
echo
echo " If you really do, force the commit by adding --no-verify to the command."
echo
exit 1
fi
#!/bin/bash
# prevent failing stuff to be pushed
grunt test > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo
echo " OH SNAP!"
echo " You are trying to commit something which is not passing the tests."
echo " Surely you don't mean that?"
echo
echo " If you really do, force the commit by adding --no-verify to the command."
echo
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment