Created
December 15, 2011 07:50
-
-
Save yesmeck/1480264 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/sh | |
# | |
# A git hook script to find and fix trailing whitespace | |
# in your commits. Bypass it with the --no-verify option | |
# to git-commit | |
# | |
# Find files with trailing whitespace | |
for file in `git diff --check --cached | grep '^[^+-]' | grep -o '^.*[0-9]\+:'` ; do | |
file_name=`echo ${file} | grep -o '^[^:]\+'` | |
line_number=`echo ${file} | grep -oP '(?<=:)[0-9]+(?=:)'` | |
(sed -i "${line_number}s/\s*$//" ${file_name} > /dev/null 2>&1 \ | |
|| sed -i '' -E "${line_number}s/\s*$//" ${file_name}) | |
git add ${file_name} | |
done | |
# Now we can commit | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment