Skip to content

Instantly share code, notes, and snippets.

@martinos
Created February 20, 2015 15:54
Show Gist options
  • Save martinos/03cf2ecb103896544791 to your computer and use it in GitHub Desktop.
Save martinos/03cf2ecb103896544791 to your computer and use it in GitHub Desktop.
pre-commit hook for forbidding syntax error to be committed
#! /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"
@martinos
Copy link
Author

Put this in your .git/hooks directory and chmod u+x pre_commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment