Skip to content

Instantly share code, notes, and snippets.

@groundwater
Last active December 29, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groundwater/7688111 to your computer and use it in GitHub Desktop.
Save groundwater/7688111 to your computer and use it in GitHub Desktop.
#!/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