forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-git-hooks.sh
More file actions
executable file
·38 lines (30 loc) · 944 Bytes
/
Copy pathinstall-git-hooks.sh
File metadata and controls
executable file
·38 lines (30 loc) · 944 Bytes
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
#!/usr/bin/env bash
# Install project Git hooks from .githooks/ into .git/hooks/.
#
# Usage:
# ./contrib/dev-tools/git/install-git-hooks.sh
#
# Run once after cloning the repository. Re-run to update hooks after
# they change.
set -euo pipefail
REPO_ROOT="$(git rev-parse --show-toplevel)"
HOOKS_SRC="${REPO_ROOT}/.githooks"
HOOKS_DST="$(git rev-parse --git-path hooks)"
mkdir -p "${HOOKS_DST}"
if [ ! -d "${HOOKS_SRC}" ]; then
echo "ERROR: .githooks/ directory not found at ${HOOKS_SRC}"
exit 1
fi
installed=0
for hook in "${HOOKS_SRC}"/*; do
hook_name="$(basename "${hook}")"
dest="${HOOKS_DST}/${hook_name}"
cp "${hook}" "${dest}"
chmod +x "${dest}"
echo "Installed: ${hook_name} → .git/hooks/${hook_name}"
installed=$((installed + 1))
done
echo ""
echo "=========================================="
echo "SUCCESS: ${installed} hook(s) installed."
echo "=========================================="