Created
September 28, 2016 12:41
-
-
Save vjwilson/35e4f19fb82232e7685c00f78c1fad68 to your computer and use it in GitHub Desktop.
Git pre-commit hook
This file contains hidden or 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/sh | |
if git rev-parse --verify HEAD >/dev/null 2>&1; then | |
against=HEAD | |
else | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
echo 'Checking against ref ' $against | |
# Use git diff-index to check for whitespace errors | |
echo "pre-commit: Testing for whitespace errors..." | |
if ! git diff-index --check --cached $against | |
then | |
echo "pre-commit: Aborting commit due to whitespace errors" | |
exit 1 | |
else | |
echo "pre-commit: No whitespace errors :)" | |
fi | |
echo "pre-commit: Testing for unwanted log statements..." | |
for FILE in `git diff-index --name-status $against -- | cut -c3-` ; do | |
# Check if the file contains 'console.log' | |
if [ "grep 'console.log' $FILE" ] | |
then | |
echo $FILE ' contains console.log!' | |
exit 1 | |
fi | |
done | |
echo "pre-commit: No unwanted console.log statements :)" | |
echo "pre-commit: Running test suite..." | |
npm test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment