Created
January 17, 2013 00:05
-
-
Save tigluiz/4552224 to your computer and use it in GitHub Desktop.
pre commit hook
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/bash | |
## START PRECOMMIT HOOK | |
files_modified=`git status --porcelain | egrep "^(A |M |R ).*" | awk ' { if ($3 == "->") print $4; else print $2 } '` | |
[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm" | |
## use ruby defined in project | |
source .rvmrc | |
for f in $files_modified; do | |
echo "Checking ${f}..." | |
if [[ $f == *.rb ]]; then | |
ruby -c $f | |
if [ $? != 0 ]; then | |
echo "File ${f} failed" | |
exit 1 | |
fi | |
if grep --color -n "binding.pry" $f; then | |
echo "File ${f} failed - found 'binding.pry'" | |
exit 1 | |
fi | |
if grep --color -n "debugger" $f; then | |
echo "File ${f} failed - found 'debugger'" | |
exit 1 | |
fi | |
elif [[ $f == *.haml ]]; then | |
bundle exec haml --check $f | |
elif [[ $f == *.sass ]]; then | |
bundle exec sass --check $f | |
fi | |
if [ $? != 0 ]; then | |
echo "File ${f} failed" | |
exit 1 | |
fi | |
done | |
exit | |
## END PRECOMMIT HOOK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment