I want to add pre-commit hook for jshint in svn. As I new to svn therefore, I need some help. I already did some work which is following. Below is my local repo folder structure
svn-repo
branches
hooks
pre-commit.sh
tags
trunk
scripts
script.js
index.html
.jshintrc
Here is my pre-commit hook code
ROOT_DIR=$(git rev-parse --show-toplevel) # gets the path of this repo
CONF="--config=${ROOT_DIR}/build/config/jshint.json" # path of your jshint config
JSHINT=$(which jshint) # jshint path
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
for file in $(git diff-index --name-only ${against} -- | egrep \.js); do
if $JSHINT $file ${CONF} 2>&1 | grep 'No errors found' ; then
echo "jslint passed ${file}"
exit 0
else
$JSHINT $file
exit 1
fi
done
I installed jshint globally and is located on below location
/usr/local/bin/jshint
Now when I commit with incorrect javascript then it still gets committed and does not throw any errors even though js contains errors according to .jshintrc.
How can I make this pre-commit work?