Skip to content

Instantly share code, notes, and snippets.

@rindek
Created March 28, 2012 12:56
Show Gist options
  • Save rindek/2225907 to your computer and use it in GitHub Desktop.
Save rindek/2225907 to your computer and use it in GitHub Desktop.
pre-commit hook which will check for any binding.pry or invalid files before commiting
#!/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
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