-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-install-hooks.sh
49 lines (41 loc) · 1.55 KB
/
git-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
#!/usr/bin/env bash
PROJECT_BASE_DIR=${1}
PRE_COMMIT_FILE="${PROJECT_BASE_DIR}/.git/hooks/pre-commit"
PRE_COMMIT_HOOK_SCRIPT="${PROJECT_BASE_DIR}/project-resources/git/hooks/pre-commit.sh"
function print {
echo "**** ${1}"
}
function printBannerLine {
echo "***************************************************************"
}
# Note that this is a minimal example, and I am not suggesting that this
# is how you should install the script. Consider running some checks to
# determine if the user's development environment is correctly set up,
# and consider providing some feedback about any misconfiguration or other
# incompatibility that is found.
printBannerLine
print 'Installing git hooks...'
# Ensure that the project-resources git pre-commit hook script is executable
if [ ! -x "${PRE_COMMIT_HOOK_SCRIPT}" ] ; then
print 'Making pre-commit hook script executable.'
chmod +x "${PRE_COMMIT_HOOK_SCRIPT}"
if [ ! -x "${PRE_COMMIT_HOOK_SCRIPT}" ] ; then
print 'Pre-commit hook script is not executable. Exiting.'
printBannerLine
exit 1
fi
fi
print 'Pre-commit hook script is executable. Attempting to link.'
# Install the project-resources git pre-commit hook as a symlink in the git hooks directory
if [ ! -L "${PRE_COMMIT_FILE}" ] ; then
print 'Creating pre-commit link.'
ln -sfn "${PRE_COMMIT_HOOK_SCRIPT}" "${PRE_COMMIT_FILE}"
if [ ! -L "${PRE_COMMIT_FILE}" ] ; then
print 'Could not create pre-commit link. Exiting.'
printBannerLine
exit 2
fi
fi
print 'Pre-commit link exists.'
print 'Finished installing git hooks.'
printBannerLine