Add git templates with preconfigured hooks

So far, add a single pre-commit hook which loops through the dotfiles
for *.pre-commit files and executes them
This commit is contained in:
Nick Nisi
2013-07-23 08:54:50 -05:00
parent 0f7a105e97
commit 4354fcc0e8
4 changed files with 82 additions and 0 deletions

32
git/hooks/jshint.pre-commit Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/sh
# JSHint Pre-Commit
# If a JavaScript file is trying to be committed and it fails linting
# then fail the commit
EXIT_CODE=0
COLOR_RED="\x1B[31m"
COLOR_GREEN="\x1B[32m"
COLOR_NONE="\x1B[0m"
repo=$( git rev-parse --show-toplevel )
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}))