Last active
January 2, 2016 22:59
-
-
Save jasny/8373660 to your computer and use it in GitHub Desktop.
Define git hooks within your repository. Allows defining multiple scripts for one hook.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc" | |
HOOK_DIR=$(git rev-parse --show-toplevel)/.git/hooks | |
DIR=$(dirname "$0") | |
for hook in $HOOK_NAMES; do | |
# If the hook already exists, is executable, and is not a symlink | |
if [ ! -h "$HOOK_DIR/$hook" -a -x "$HOOK_DIR/$hook" ]; then | |
mv "$HOOK_DIR/$hook" "$HOOK_DIR/$hook.local" | |
fi | |
# create the symlink, overwriting the file if it exists | |
# probably the only way this would happen is if you're using an old version of git | |
# -- back when the sample hooks were not executable, instead of being named ____.sample | |
ln -s -f ../../bin/git-hooks/wrapper "$HOOK_DIR/$hook" | |
done | |
[ -f "$HOOK_DIR/env" ] || \ | |
echo "# Place environment variable here. These are only for your local system. | |
export APPLICATION_ENV=prod" > "$HOOK_DIR/env" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
. .git/hooks/env | |
if [ -x $0.local ]; then | |
$0.local "$@" | |
fi | |
if [ -d "bin/git-hooks/$(basename $0)" ]; then | |
for SCRIPT in bin/git-hooks/$(basename $0)/*; do | |
[ -x "$SCRIPT" ] || continue | |
"$SCRIPT" "$@" | |
done | |
fi |
Author
jasny
commented
Jan 11, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment