Commit 7c031666 by Joe Blaylock

Adding pre-commit and post-checkout hooks

* Pre-commit hook lints JSON
* Post-checkout hook causes hooks directory to update with current
  project hooks
* Readme updated so installation section reminds you to install hooks
parent eaa73521
......@@ -106,6 +106,7 @@ Example users are in the `vars/secure` directory:
```
mkvirtualenv ansible
pip install -r ansible-requirements.txt
util/sync_hooks.sh
```
### Launching example cloudformation stack - Working example
......
#!/bin/sh
echo -n Setting up hooks from git-hooks..
`pwd`/util/sync_hooks.sh >/dev/null
if [ $? -eq 0 ]; then
echo . done.
else
exit 1
fi
#!/bin/sh
echo -n Checking JSON parses..
`pwd`/util/json_lint.sh
if [ $? -eq 0 ]; then
echo . it does!
else
exit 1
fi
#!/bin/bash
# Do very basic syntax check of every json file to make sure it's valid format
for file in `find . -iname '*.json'`; do
cat $file | python -m json.tool 1>/dev/null 2>json_complaint.err;
retval=$?
if [ $retval != 0 ]; then
echo "JSON errors in $file"
cat json_complaint.err
rm -f json_complaint.err
exit $retval;
fi
done
# Everything went ok!
exit 0
#!/bin/bash
# Are we running from the git root?
GITHOOKSFOUND='false'
if [ -d git-hooks ]; then
GITHOOKSFOUND='true';
fi
DOTGITHOOKSFOUND='false'
if [ -d .git -a -d .git/hooks ]; then
DOTGITHOOKSFOUND='true';
fi
# Sync git-hooks directory entries into .git/hooks/
if [ 'true' = $GITHOOKSFOUND -a 'true' = $DOTGITHOOKSFOUND ]; then
for file in git-hooks/*; do
filepart=`echo $file | sed -e 's/git-hooks\/\(.*\)/\1/'`
if [ -e .git/hooks/$filepart -a ! -L .git/hooks/$filepart ]; then
echo ".git/hooks/$filepart not link-managed; bailing..."
echo "please examine your .git/hooks/ directory and repair inconsistencies manually"
exit 1
else
ln -v -s -b -f `pwd`/$file -t .git/hooks/
fi
done
else
echo "Not in git repository root, cannot continue."
exit 1
fi
# Ok, everything went well
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment