Created
November 12, 2012 15:17
-
-
Save nicknisi/4059921 to your computer and use it in GitHub Desktop.
A git pre-commit to check js files up for commit against JSHint. If there are errors, the commit is cancelled.
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 | |
# JSHint Pre-Commit | |
# Place this in your .git/hooks/pre-commit directory and rename to `pre-commit` | |
# expects jshint to be installed in your projects node_modules directory | |
EXIT_CODE=0 | |
COLOR_RED="\x1B[31m" | |
COLOR_GREEN="\x1B[32m" | |
COLOR_NONE="\x1B[0m" | |
repo=$( git rev-parse --show-toplevel ) | |
jshint=${repo}/node_modules/jshint/bin/hint | |
for file in $( exec git diff-index --cached --name-only HEAD ); do | |
if [[ $file == *".js"* ]]; then | |
status=$( exec git status --porcelain $file ) | |
if [[ $status != D* ]]; then | |
# ${jshint} ${repo}/${file} >/dev/null 2>&1 | |
${jshint} ${repo}/${file} | |
EXIT_CODE=$((${EXIT_CODE} + $?)) | |
fi | |
fi | |
done | |
echo "" | |
if [[ ${EXIT_CODE} -ne 0 ]]; then | |
echo "${COLOR_RED}✘ JSHINT detected syntax problems.${COLOR_NONE}" | |
else | |
echo "${COLOR_GREEN}✔ JSHINT detected no errors.${COLOR_NONE}" | |
fi | |
exit $((${EXIT_CODE})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment