forked from ddddavidmartin/Pre-commit-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_hooks.sh
executable file
·74 lines (61 loc) · 2.1 KB
/
install_hooks.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
70
71
72
73
74
#!/bin/sh
# Install git pre-commit hooks.
# The root directory of the target local git repository is expected as a parameter.
# This file is part of a set of unofficial pre-commit hooks available
# at github.
# Link: https://github.com/githubbrowser/Pre-commit-hooks
# Contact: David Martin, [email protected]
###########################################################
# SETTINGS:
# select which pre-commit hooks are going to be installed
#HOOKS="pre-commit pre-commit-default pre-commit-compile pre-commit-uncrustify"
HOOKS="pre-commit pre-commit-uncrustify"
###########################################################
# There should be no need to change anything below this line.
source $(dirname "$0")/"canonicalize_filename.sh"
# exit on error
set -e
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT="$(canonicalize_filename "$0")"
# Absolute path this script is in, e.g. /home/user/bin/
SCRIPTPATH="$(dirname "$SCRIPT")"
# copy hooks to the directory specified as parameter
copy_hooks() {
# create hooks subfolder if it does not yet exist
mkdir -p "$1/hooks"
echo "Copying hooks to destination directory:"
for hook in $HOOKS
do
echo "Copying $hook to $1/hooks."
cp -i "$SCRIPTPATH/$hook" "$1/hooks"
done
echo ""
echo "Checking if hooks are executable:"
for hook in $HOOKS
do
if [ ! -x "$1/hooks/$hook" ] ; then
echo "$hook is not executable. Fix it by calling"
echo "sudo chmod +x $1/hooks/$hook"
else
echo "$hook OK."
fi
done
}
echo ""
echo "Git pre-commit hook installation."
echo ""
if [ $# = 1 ] ; then
if [ -d "$1/.git" ] ; then
echo "Copying prerequisites."
cp -i "$SCRIPTPATH/canonicalize_filename.sh" "$1/.git/hooks/"
echo ""
copy_hooks "$1/.git"
echo ""
echo "Finished installation."
else
echo "Error: $1/.git does not exist."
echo "Are you sure $1 is the root directory of your local git repository?"
fi
else
echo "Call this script with the destination git repository as parameter."
fi