Skip to content

Instantly share code, notes, and snippets.

@tigluiz
Created January 17, 2013 00:05
Show Gist options
  • Save tigluiz/4552224 to your computer and use it in GitHub Desktop.
Save tigluiz/4552224 to your computer and use it in GitHub Desktop.
pre commit hook
#!/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