Created
March 20, 2012 21:08
-
-
Save callumacrae/2141321 to your computer and use it in GitHub Desktop.
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 | |
# Compile a list of changed files | |
FILES=`git diff --name-only HEAD^` | |
# Attempt to fix whitespace issues | |
for FILE in `egrep -l '(\s$| {1,3}\t)' $FILES` | |
do | |
# Remove trailing whitespace | |
(sed -i 's/[ ]*$//' $FILE > /dev/null 2>&1 || sed -i '' -E 's/[ ]*$//' $FILE) | |
# Remove spaces before tabs | |
(sed -i 's/ {1,3} / /' $FILE > /dev/null 2>&1 || sed -i '' -E 's/ {1,3} / /' $FILE) | |
# Add to git | |
git add $FILE | |
echo "Automatically fixed whitespace in $FILE" | |
done | |
# Check for new lines at end of file, add if it is not there | |
for FILE in $FILES | |
do | |
if ! tail -c1 $FILE | read _ | |
then | |
echo >> $FILE | |
git add $FILE | |
echo "Added new line to end of $FILE" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment