Last active
August 29, 2015 14:14
-
-
Save maephisto/e53e3ae7b3caad3a96fc to your computer and use it in GitHub Desktop.
Pre-commit hook doing a jshint and less before comitting.
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 | |
echo "\nLet me check if you can commit!" | |
jsFiles=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$") | |
lessFiles=$(git diff --cached --name-only --diff-filter=ACM | grep ".less$") | |
if [ "$jsFiles" = "" ]; then | |
echo "\033[32mNo JavaScript files were modified.\033[0m" | |
if [ "$lessFiles" = "" ]; then | |
echo "\033[32mNo CSS files were modified. All good, committing...\033[$ | |
exit 0 | |
fi | |
fi | |
jsValidationResult=$(grunt jshint | grep "Done, without errors") | |
lessValidationResult=$(grunt less | grep "Done, without errors") | |
if [ "$jsValidationResult" != "" ]; then | |
echo "\033[32mJSHint Passed. Awesome!\033[0m" | |
else | |
echo "\033[31mJHLint Failed :( Commit stopped. \033[0m" | |
exit 1 | |
fi | |
if [ "$lessValidationResult" != "" ]; then | |
echo "\033[32mLESS Passed\033[0m" | |
else | |
echo "\033[31mLESS Failed :( Commit stopped. \033[0m" | |
exit 1 | |
fi | |
echo "\033[32mLet's roll! Commiting...\033[0m" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment