-
Notifications
You must be signed in to change notification settings - Fork 3
/
hooker.sh
executable file
·69 lines (59 loc) · 1.4 KB
/
hooker.sh
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
this=$dir/`basename "${BASH_SOURCE[0]}"`
# http://git-scm.com/docs/githooks
hook_names="
applypatch-msg \
commit-msg \
post-update \
pre-applypatch \
pre-commit \
pre-push \
pre-rebase \
prepare-commit-msg \
update \
"
export _HOOKER_LOG_RED='\033[0;31m'
export _HOOKER_LOG_YELLOW='\033[0;33m'
export _HOOKER_LOG_WHITE='\033[0;37m'
export _HOOKER_LOG_BOLD='\033[0;1m'
export _HOOKER_LOG_UNDERLINE='\033[0;4m'
export _HOOKER_LOG_BLINK='\033[0;5m'
export _HOOKER_LOG_NC='\033[0m' # No Color
# Logging helpers
_log_message() {
text=$1
color=$2
shift
if [ -z "$TERM" ]; then
printf "$text\n"
else
printf "$color$text${_HOOKER_LOG_NC}\n"
fi
}
export -f _log_message
log_info() {
_log_message "$1" ${_HOOKER_LOG_WHITE}
}
export -f log_info
log_warn() {
_log_message "$1" ${_HOOKER_LOG_YELLOW}
}
export -f log_warn
log_error() {
_log_message "$1" ${_HOOKER_LOG_RED}
}
export -f log_error
if [ "$1" = "--install" ]; then
echo "Hooking you up..."
for hook in $hook_names; do
ln -sf $this .git/hooks/$hook
done
else
hook_name=$(basename "$this")
hook_dir="$dir/../../.githooks/$hook_name"
hook_files=$(find $hook_dir -perm +111 -type f 2> /dev/null)
for hook in $hook_files; do
$hook $* || exit $?
done
fi