Last active
December 29, 2015 14:59
-
-
Save groundwater/7688111 to your computer and use it in GitHub Desktop.
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/bash | |
# COLORS!!!! | |
RED=$(tput setaf 1) | |
CLR=$(tput sgr0) | |
# 1. grab pending chagnes | |
# 2. remove ?? files that aren't part of the commit | |
# 3. only grab things in the index | |
git status --porcelain |\ | |
grep -v '^??' |\ | |
grep '^[MA]' |\ | |
while read line; do | |
# the file path | |
file=$(echo "$line" | sed 's/...//') | |
# fail if a file has unstaged modifications | |
# a file is staged if it's got M/A in the first column | |
# a file has unstanged changes if it's got M in the second column | |
# e.g. | |
# | |
# M file-unstange with modifications | |
# M modified file-staged | |
# MM file with staged *and* unstanged modifications | |
# | |
if [[ "$line" =~ ^.[MA].* ]]; then | |
echo "${RED}Cannot JSHint on Dirty File $file${CLR}" | |
exit -2 | |
fi | |
# we should only JSHint staged files | |
echo "Testing JSHINT: $file" | |
jshint $file || exit -1 | |
done | |
# bail if shit goes south | |
if [[ $? -ne 0 ]]; then | |
echo -e "${RED}Commit Failed JSHint${CLR}" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment