-
Notifications
You must be signed in to change notification settings - Fork 2
/
setupgithooks
executable file
·62 lines (56 loc) · 1.6 KB
/
setupgithooks
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
#!/bin/bash
githooksdir="githooks"
dest=".git/hooks"
if ! type realpath >/dev/null; then
echo "required program not found 'realpath'"
exit 10
fi
echo "Run this only once after git clone, it will symlink all hooks from '$githooksdir' dir into '$dest' dir, unless they already exist."
echo "You can run this again in the future to check for symlinks consistency"
if test ! -d "$dest" ; then
echo "'$dest' folder not detected!"
exit 2
fi
for fd in "${githooksdir}"/*; do
f=${fd##*/}
ffull="`realpath -- "$fd"`"
d="${dest}/$f"
destfull="`realpath -- "$d"`"
echo "processing: '$f'"
echo " from '$ffull'"
echo " to '$d'"
if test -z "$f" -o -z "$ffull" -o -z "$d" -o -z "$destfull"; then
echo "one of the following is empty: '$f' or '$ffull' or '$d' or '$destfull'"
exit 81
fi
if test -h "$d" ; then
echo " existing symlink"
if test "$ffull" != "$destfull"; then
echo " symlink doesn't point to '$ffull' but rather to '$destfull'"
echo " you may want to manually check that folder for possibly broken links"
echo " aborting"
exit 6
else
echo " points to same thing as expected"
fi
echo " skipped"
continue
elif test -e "$f" ; then
echo " '$f' exists as something that's not a symlink"
echo " bailing out!"
exit 3
else
echo " symlinking(relative)"
ln --relative --symbolic --target-directory="${dest}" -- "$ffull"
ec=$?
if test "$ec" -ne 0; then
echo " failed, ln exitcode=$ec bailing out"
exit 5
fi
echo " done $?"
continue
fi
echo "unreached"
exit 80
done
echo "Everything OK!"