forked from AD7six/git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
installGitHooks
executable file
·46 lines (40 loc) · 1008 Bytes
/
installGitHooks
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
#!/bin/bash
src=`dirname $(readlink $0)`
dryrun=
ignore='(^\.|^config.*php$|^install|~$)'
if [ ! -d .git/hooks ]; then
echo "This script needs to be run whilst in the root of your git project"
exit 1
fi
i=0
commands=()
for f in $(ls -A $src 2>/dev/null); do
if [[ $f =~ $ignore ]]; then
continue
fi
if [[ $f = "config.php" ]]; then
commands[$i]="cp $src/$f .git/hooks/"
else
commands[$i]="ln -sf $src/$f .git/hooks/"
fi
let i++
done
commands[$i]="cp $src/config.sample.php .git/hooks/config.php"
let i++
for f in applypatch-msg commit-msg post-commit post-receive post-update pre-applypatch pre-commit prepare-commit-msg pre-rebase update; do
commands[$i]="ln -sf $src/one-hook .git/hooks/$f"
let i++
done
echo "Installing files:"
echo ""
for ((j=0;j<$i;j++)) do
if [ -z $dryrun ]; then
echo " ${commands[$j]}"
else
echo " ${commands[$j]} [dryrun]"
continue
fi
${commands[$j]}
done
echo ""
echo "Completed, edit .git/hooks/config.php to modify this repositories hooks"