forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-git-hooks.sh
More file actions
executable file
·50 lines (42 loc) · 1.32 KB
/
Copy pathcheck-git-hooks.sh
File metadata and controls
executable file
·50 lines (42 loc) · 1.32 KB
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
#!/usr/bin/env bash
# Check whether project Git hooks from .githooks/ are installed in .git/hooks/.
#
# Usage:
# ./contrib/dev-tools/git/check-git-hooks.sh
#
# Exits 0 if all hooks are installed and executable.
# Exits 1 if any hook is missing or not executable.
#
# Run after cloning or whenever you want to verify your hook installation.
set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel)"
HOOKS_SRC="${REPO_ROOT}/.githooks"
HOOKS_DST="$(git rev-parse --git-path hooks)"
if [ ! -d "${HOOKS_SRC}" ]; then
echo "ERROR: .githooks/ directory not found at ${HOOKS_SRC}"
exit 1
fi
all_installed=true
for hook in "${HOOKS_SRC}"/*; do
hook_name="$(basename "${hook}")"
dest="${HOOKS_DST}/${hook_name}"
if [[ -x "${dest}" ]]; then
echo "installed: ${hook_name}"
else
echo "NOT installed: ${hook_name}"
all_installed=false
fi
done
echo ""
if [[ "${all_installed}" == "true" ]]; then
echo "=========================================="
echo "SUCCESS: All hooks are installed."
echo "=========================================="
exit 0
else
echo "=========================================="
echo "FAILURE: Some hooks are missing."
echo "Run: ./contrib/dev-tools/git/install-git-hooks.sh"
echo "=========================================="
exit 1
fi