forked from dimagi/commcare-hq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·64 lines (54 loc) · 1.07 KB
/
install.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
#!/bin/bash
function usage()
{
cat << EOF
usage: $0 options
This script installs CommCare HQ's default git hooks on all submodules
OPTIONS:
-h Show this message
-f don't ask before overwriting your current git hooks
-r remove existing hooks but do not add the new ones
EOF
}
OPT='-i'
FUNC='copy_hooks'
while getopts "hfr" OPTION
do
case $OPTION in
h)
usage
exit
;;
f)
OPT='-f'
;;
r)
FUNC='remove_hooks'
;;
?)
usage
exit 1
;;
esac
done
function copy_hooks() {
hook=$1
base_path=$2
cp $OPT git-hooks/$hook.sh $base_path/hooks/$hook
}
function remove_hooks() {
hook=$1
base_path=$2
rm $OPT $base_path/hooks/$hook
}
function git-submodule-list() {
git submodule | sed 's/^+/ /' | cut -f3 -d' '
}
for hook in 'pre-commit' 'post-checkout'
do
${FUNC} $hook '.git'
for submodule in $(git-submodule-list)
do
${FUNC} $hook ".git/modules/$submodule"
done
done