Skip to content

Instantly share code, notes, and snippets.

@epintos
Last active August 29, 2015 14:22
Show Gist options
  • Save epintos/c22ad6acc87bfdcc5cc2 to your computer and use it in GitHub Desktop.
Save epintos/c22ad6acc87bfdcc5cc2 to your computer and use it in GitHub Desktop.
Pre push github hook

Run:

  • chmod +x pre-push.sh
  • ln -s ../../pre-push.sh .git/hooks/pre-push

and the script will be executed before each git push. You can skip the hook by adding --no-verify to your git push.

#!/bin/sh
echo 'Running Rspec tests'
RUN_CHECK_CMD='bundle exec rspec spec -fd'
RUN_TESTS_OUTPUT=`${RUN_CHECK_CMD}`
if [ $? -eq 1 ]
then
echo "Can't commit! You've broken Rspec tests!!!"
exit 1
fi
echo 'Running SCSS Lint'
RUN_CHECK_CMD='bundle exec scss-lint app/assets/stylesheets/'
RUN_TESTS_OUTPUT=`${RUN_CHECK_CMD}`
if [ $? -eq 1 ]
then
echo "Can't commit! You have scss lint offences!!!"
exit 1
fi
echo 'Running Rubocop'
RUN_CHECK_CMD='bundle exec rubocop app spec -R --format simple'
RUN_TESTS_OUTPUT=`${RUN_CHECK_CMD}`
if [ $? -eq 1 ]
then
echo "Can't commit! You have rubocop offences!!!"
exit 1
fi
echo "All checks passed. Congrats!\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment