Skip to content

Instantly share code, notes, and snippets.

@pid
Created July 15, 2013 01:56
Show Gist options
  • Select an option

  • Save pid/5997010 to your computer and use it in GitHub Desktop.

Select an option

Save pid/5997010 to your computer and use it in GitHub Desktop.
Automatically JSHint files before Git commit (git hook)
#!/bin/bash
# Pre-commit Git hook to run JSHint on JavaScript files.
#
# If you absolutely must commit without testing,
# use: git commit --no-verify
filenames=($(git diff --cached --name-only HEAD))
which jshint &> /dev/null
if [ $? -ne 0 ];
then
echo "error: jshint not found"
echo "install with: sudo npm install -g jshint"
exit 1
fi
for i in "${filenames[@]}"
do
if [[ $i =~ \.js$ ]];
then
echo jshint $i
jshint $i
if [ $? -ne 0 ];
then
exit 1
fi
fi
done
@pid
Copy link
Author

pid commented Aug 1, 2013

.git/hooks/pre-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment