-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-git-hooks
executable file
·29 lines (25 loc) · 1.21 KB
/
create-git-hooks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# This script was taken from a StackOverflow answer that can be found at
# https://stackoverflow.com/a/3464399
#
# This is used under the CC BY-SA 4.0 license:
# https://creativecommons.org/licenses/by-sa/4.0/
#
# This file has been modified from its original form to include a BASE_DIR variable
# and to include creation of the Git hooks directory if it does not already exist
#!/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"
BASE_DIR=$(git rev-parse --show-toplevel)
HOOK_DIR=$BASE_DIR/.git/hooks
if [ ! -d $HOOK_DIR ]; then
mkdir $HOOK_DIR
fi
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 $BASE_DIR/scripts/hooks-wrapper $HOOK_DIR/$hook
done