Skip to content

Instantly share code, notes, and snippets.

@karthiks
Forked from holysugar/pre-commit
Created October 27, 2011 03:28
Show Gist options
  • Save karthiks/1318718 to your computer and use it in GitHub Desktop.
Save karthiks/1318718 to your computer and use it in GitHub Desktop.
git pre-commit warning to trailing whitespaces
#!/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