-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgit-hooks
executable file
·58 lines (50 loc) · 962 Bytes
/
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
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
#!/bin/bash
usage() {
echo "`basename $0` enable|disable <hook>"
}
if [[ $# < 1 ]]; then
usage
exit 1
fi
cmd=$1
hook=$2
hook_disabled=$hook.disabled
case $cmd in
enable)
;;
disable)
;;
*)
usage
exit 1
;;
esac
git rev-list HEAD~..HEAD > /dev/null
if [ $? -ne 0 ]; then
exit 1
fi
# git rev-list will take care of searching for the git-repo
# so if we get here, we know we're inside a git repo.
while ! [ -e ".git" ]; do
cd ..
done
pushd .git/hooks > /dev/null || exit 1
case $cmd in
enable)
if ! [[ -e "$hook_disabled" ]]; then
echo "Hook $hook_disabled does not exist"
exit 1
fi
mv $hook_disabled $hook
;;
disable)
if ! [[ -e "$hook" ]]; then
echo "Hook $hook does not exist"
exit 1
fi
mv $hook $hook_disabled
;;
*)
;;
esac
popd > /dev/null || exit 1