-
-
Save karthiks/1318718 to your computer and use it in GitHub Desktop.
git pre-commit warning to trailing whitespaces
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/sh | |
function error() { | |
echo "'$1' has trailing spaces.\n" >&2 | |
} | |
git diff --cached --name-only | (while read f; do | |
ERROR=0 | |
if grep -n '[[:space:]]$' "$f" ; then | |
error $f | |
ERROR=1 | |
fi | |
done; exit $ERROR) | |
if [ $? -eq 0 -o "$IGNORE_WHITESPACE" ]; then | |
exit | |
else | |
echo "if you know what you are doing, use 'IGNORE_WHITESPACE=1 git commit'" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment