Last active
May 16, 2017 08:17
-
-
Save sfate/34eb39347e0175a0a182501250eed467 to your computer and use it in GitHub Desktop.
Git pre-commit hook
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
#!/bin/bash | |
# | |
# Pre-commit hook script to avoid debug statements to be commited. | |
# Place under `$PROJECT_DIR/.git/hooks/pre-commit` | |
# Make script executable `chmod +x $PROJECT_DIR/.git/hooks/pre-commit` | |
# | |
# https://github.com/sfate | |
STATEMENTS="puts\|debugger\|binding.pry\|alert(\|console.log(" | |
OUTPUT=$(git diff --cached --name-only | xargs git grep -wnH " $STATEMENTS" | awk '$0="\t"$0') | |
if [ -n "$OUTPUT" ]; then | |
echo "On branch $(git rev-parse --abbrev-ref HEAD)" | |
echo 'Changes staged for commit with debug statements:' | |
echo ' (remove debug statements first)' | |
echo | |
echo -en "\033[0;31m$OUTPUT\033[0m" | |
echo | |
echo | |
echo 'no changes were commited! (remove debug lines and stage files back)' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment