Created
September 22, 2017 02:24
-
-
Save karuna/c26835188568efcc6c59354f6362fbee to your computer and use it in GitHub Desktop.
Pre commit hook for rails app. put this inside .git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# this hook is in SCM so that it can be shared | |
# to install it, create a symbolic link in the projects .git/hooks folder | |
# | |
# i.e. - from the .git/hooks directory, run | |
# $ ln -s ../../git-hooks/pre-commit.sh pre-commit | |
# | |
# to skip the tests, run with the --no-verify argument | |
# i.e. - $ 'git commit --no-verify' | |
FILES='(js|css|rb)' | |
FORBIDDEN='(binding.pry|console.log|\!important|focus\: true)' | |
GREP_COLOR='4;5;37;41' | |
if [[ $(git diff --cached --name-only | grep -E $FILES) ]]; then | |
git diff --cached --name-only | grep -E $FILES | \ | |
xargs grep --color --with-filename -n -E $FORBIDDEN && \ | |
echo "Looks like you are trying to commit something you shouldn't. Please fix your diff, or run 'git commit --no-verify' to skip this check, if you must." && \ | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment