Commit 52fb2492 by Joe Blaylock

Improved directory management in git hooks

* Make git hooks always execute utilities relative to git repository root
* And make them fail if called from outside the git repository
* Make utilities save current directory and return after doing their
  things
parent 7c031666
#!/bin/sh
dir=`git rev-parse --show-toplevel`
if [ -z $dir ]; then
exit 1
fi
echo -n Setting up hooks from git-hooks..
`pwd`/util/sync_hooks.sh >/dev/null
$dir/util/sync_hooks.sh >/dev/null
if [ $? -eq 0 ]; then
echo . done.
else
......
#!/bin/sh
dir=`git rev-parse --show-toplevel`
if [ -z $dir ]; then
exit 1
fi
echo -n Checking JSON parses..
`pwd`/util/json_lint.sh
$dir/util/json_lint.sh
if [ $? -eq 0 ]; then
echo . it does!
else
......
#!/bin/bash
# A very simple check to see if the json files in the project at least compile.
# If they do not, a cryptic message that might be helpful is produced.
# Save current directory so we can come back; change to repo root
STARTED_FROM=`pwd`
cd $(git rev-parse --show-toplevel)
# Do very basic syntax check of every json file to make sure it's valid format
for file in `find . -iname '*.json'`; do
......@@ -8,9 +15,12 @@ for file in `find . -iname '*.json'`; do
echo "JSON errors in $file"
cat json_complaint.err
rm -f json_complaint.err
cd $STARTED_FROM
exit $retval;
fi
done
# Everything went ok!
rm -f json_complaint.err
cd $STARTED_FROM
exit 0
#!/bin/bash
# A small utility to symlink the files from git-hooks/ with filenames ending
# like .in into the directory .git/hooks/
#
# It's intended this be run once near the start of a project by hand, and then
# subsequently a hook that it installs keeps it running at project checkouts.
# 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
# Save current directory so we can come back; change to repo root
STARTED_FROM=`pwd`
cd $(git rev-parse --show-toplevel)
# 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
for file in git-hooks/*.in; do
filepart=`basename $file .in`
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"
cd $STARTED_FROM
exit 1
else
ln -v -s -b -f `pwd`/$file .git/hooks/$filepart
fi
done
# Ok, everything went well
# Ok, everything went well; restore previous context
cd $STARTED_FROM
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