Created
April 1, 2014 00:43
-
-
Save otanistudio/9905547 to your computer and use it in GitHub Desktop.
git pre-commit hook for checking tabs, but only in certain files. Just as an example, this one only looks for Obj-C, Obj-C++, C++, JSON and header files
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
if | |
git diff --cached --name-only | egrep '(\.(mm|m|h|cpp|json)$)' | xargs git diff --cached | egrep '^\+.*'$'\t' > /dev/null | |
then | |
echo "Tabs found in your commit. Please use (four) spaces and re-commit." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you noticed any issues with, e.g. Ubuntu 16.04 using this script?
What I've found is that, if the
git diff --cached --name-only | egrep '(\.(mm|m|h|cpp|json)$)'
bit returns no matches, the result of the rest of the line depends on all the files that have changed. So, let's say you have a load of .cpp files, and a .cproject file. If you've only changed the .cproject file and staged it, and it has tabs in it, it will be picked up in the xargs processing and your commit will be rejected.