Skip to content

Instantly share code, notes, and snippets.

@apexskier
Last active March 18, 2016 20:22
Show Gist options
  • Save apexskier/efb7c1aaa6e77e8127a8 to your computer and use it in GitHub Desktop.
Save apexskier/efb7c1aaa6e77e8127a8 to your computer and use it in GitHub Desktop.
Script to deploy git hooks from version control.
#!/bin/sh
# Deploy hooks stored in your git repo to everyone!
# https://gist.github.com/apexskier/efb7c1aaa6e77e8127a8
#
# I keep this in $ROOT/$HOOK_DIR/deploy
# From the top level of your git repo, run ./hook/deploy (or equivalent) after
# cloning or adding a new hook.
# No output is good output.
BASE=`git rev-parse --git-dir`
ROOT=`git rev-parse --show-toplevel`
HOOK_DIR=hooks # change to .githooks or whatever
HOOKS=$ROOT/$HOOK_DIR/*
if [ ! -d "$ROOT/$HOOK_DIR" ]
then
echo "Couldn't find hooks dir"
exit 1
fi
rm -f $BASE/hooks/*
for HOOK in $HOOKS
do
(cd $BASE/hooks ; ln -s $HOOK `basename $HOOK` || echo "Failed to link $HOOK to `basename $HOOK`")
done
SUBMODULES=`git submodule`
if [ -n "$SUBMODULES" ]
then
for SM in `grep path $BASE/../.gitmodules | sed 's/.*= //'`
do
SMHOOKS=$BASE/modules/$SM/hooks
rm -f $SMHOOKS/*
for HOOK in $HOOKS
do
(cd $SMHOOKS ; ln -s $HOOK `basename $HOOK` || echo "Failed to link $HOOK to `basename $HOOK`")
done
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment