-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-hooks.sh
More file actions
executable file
·51 lines (44 loc) · 1.6 KB
/
install-hooks.sh
File metadata and controls
executable file
·51 lines (44 loc) · 1.6 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
51
#!/bin/bash
# ─────────────────────────────────────────────────────────
# install-hooks.sh — Symlink git hooks into .git/hooks/
# Called by: make configure-hooks (preferred) or manually
# ─────────────────────────────────────────────────────────
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
HOOKS_SRC="$REPO_ROOT/vendor/scripts/hooks"
HOOKS_DST="$REPO_ROOT/.git/hooks"
declare -A HOOK_MAP=(
["pre-commit"]="pre-commit"
["commit-msg"]="commit-msg"
["pre-push"]="pre-push"
["post-checkout"]="post-checkout"
["pre-merge-commit"]="pre-merge-commit"
)
echo "Resetting hooks in $HOOKS_DST ..."
for hook in "${!HOOK_MAP[@]}"; do
dst="$HOOKS_DST/$hook"
# Remove any existing file or symlink
if [ -e "$dst" ] || [ -L "$dst" ]; then
rm -f "$dst"
echo "Removed old hook: $dst"
fi
done
for hook in "${!HOOK_MAP[@]}"; do
src="$HOOKS_SRC/${HOOK_MAP[$hook]}"
dst="$HOOKS_DST/$hook"
if [ -f "$src" ]; then
ln -sf "$src" "$dst"
chmod +x "$src"
echo "Symlinked $dst -> $src"
else
echo "Source hook not found: $src"
fi
done
# Symlink log_hook.sh for sourcing in hooks
if [ -f "$HOOKS_SRC/log_hook.sh" ]; then
ln -sf "$HOOKS_SRC/log_hook.sh" "$HOOKS_DST/log_hook.sh"
echo "Symlinked $HOOKS_DST/log_hook.sh -> $HOOKS_SRC/log_hook.sh"
else
echo "Source log_hook.sh not found: $HOOKS_SRC/log_hook.sh"
fi
echo "All hooks and log_hook.sh reset and symlinked to .git/hooks/."