Skip to content

Instantly share code, notes, and snippets.

@karuna
Created September 22, 2017 02:24
Show Gist options
  • Save karuna/c26835188568efcc6c59354f6362fbee to your computer and use it in GitHub Desktop.
Save karuna/c26835188568efcc6c59354f6362fbee to your computer and use it in GitHub Desktop.
Pre commit hook for rails app. put this inside .git
#!/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