Created
February 20, 2015 15:54
-
-
Save martinos/03cf2ecb103896544791 to your computer and use it in GitHub Desktop.
pre-commit hook for forbidding syntax error to be committed
This file contains 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
#! /usr/bin/env bash | |
ruby_files=`git diff --name-only --diff-filter=MA --cached| grep '\.rb$'` | |
while read -r file; do | |
result=`grep -rn 'binding\.pry\|debugger' $file` | |
if [ -n "$result" ] | |
then | |
echo "Cannot be commited because: $result ." | |
exit 1 | |
fi | |
ruby_syntax=`ruby -c $file 2>&1` | |
if [ $? -ne 0 ] | |
then | |
echo "Cannot be commited because ruby syntax error:" | |
echo "$ruby_syntax" | |
exit 1 | |
fi | |
done <<< "$ruby_files" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this in your .git/hooks directory and chmod u+x pre_commit