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 #!/bin/sh
dir=`git rev-parse --show-toplevel`
if [ -z $dir ]; then
exit 1
fi
echo -n Setting up hooks from git-hooks.. 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 if [ $? -eq 0 ]; then
echo . done. echo . done.
else else
......
#!/bin/sh #!/bin/sh
dir=`git rev-parse --show-toplevel`
if [ -z $dir ]; then
exit 1
fi
echo -n Checking JSON parses.. echo -n Checking JSON parses..
`pwd`/util/json_lint.sh $dir/util/json_lint.sh
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo . it does! echo . it does!
else else
......
#!/bin/bash #!/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 # Do very basic syntax check of every json file to make sure it's valid format
for file in `find . -iname '*.json'`; do for file in `find . -iname '*.json'`; do
...@@ -8,9 +15,12 @@ for file in `find . -iname '*.json'`; do ...@@ -8,9 +15,12 @@ for file in `find . -iname '*.json'`; do
echo "JSON errors in $file" echo "JSON errors in $file"
cat json_complaint.err cat json_complaint.err
rm -f json_complaint.err rm -f json_complaint.err
cd $STARTED_FROM
exit $retval; exit $retval;
fi fi
done done
# Everything went ok! # Everything went ok!
rm -f json_complaint.err
cd $STARTED_FROM
exit 0 exit 0
#!/bin/bash #!/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' # Save current directory so we can come back; change to repo root
if [ -d git-hooks ]; then STARTED_FROM=`pwd`
GITHOOKSFOUND='true'; cd $(git rev-parse --show-toplevel)
fi
DOTGITHOOKSFOUND='false'
if [ -d .git -a -d .git/hooks ]; then
DOTGITHOOKSFOUND='true';
fi
# Sync git-hooks directory entries into .git/hooks/ # Sync git-hooks directory entries into .git/hooks/
if [ 'true' = $GITHOOKSFOUND -a 'true' = $DOTGITHOOKSFOUND ]; then for file in git-hooks/*.in; do
for file in git-hooks/*; do filepart=`basename $file .in`
filepart=`echo $file | sed -e 's/git-hooks\/\(.*\)/\1/'`
if [ -e .git/hooks/$filepart -a ! -L .git/hooks/$filepart ]; then if [ -e .git/hooks/$filepart -a ! -L .git/hooks/$filepart ]; then
echo ".git/hooks/$filepart not link-managed; bailing..." echo ".git/hooks/$filepart not link-managed; bailing..."
echo "please examine your .git/hooks/ directory and repair inconsistencies manually" echo "please examine your .git/hooks/ directory and repair inconsistencies manually"
cd $STARTED_FROM
exit 1 exit 1
else else
ln -v -s -b -f `pwd`/$file -t .git/hooks/ ln -v -s -b -f `pwd`/$file .git/hooks/$filepart
fi fi
done done
else
echo "Not in git repository root, cannot continue."
exit 1
fi
# Ok, everything went well # Ok, everything went well; restore previous context
cd $STARTED_FROM
exit 0 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