Last active
March 30, 2018 19:09
-
-
Save rraallvv/4f5709a8c69c443e9864b4f600dd2210 to your computer and use it in GitHub Desktop.
Git hook to convert hard tabs and remove spaces before line ending
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 | |
git diff --diff-filter=d --name-only --cached | grep -v "Resource.designer.cs" -E | grep -E "\.cs$|\.xml$|\.xaml$|\.axml$" | while read -r file; do | |
# Convert soft tabs to hard ones | |
perl -pi -e "s/\G {4}/\t/g" $file | |
# Remove additional spaces before the end of line | |
perl -pi -e "s/[ \t]$//g" $file | |
# Add newline before EOF if missing | |
[[ $(tail -c1 $file) && -f $file ]] && echo '' >> $file | |
# Stage changes | |
git add $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment