-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.sh
More file actions
38 lines (32 loc) · 1.08 KB
/
Copy pathhooks.sh
File metadata and controls
38 lines (32 loc) · 1.08 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
#!/bin/zsh
# =============================================================================
# hooks.sh — Git hooks installer
# =============================================================================
#
# Symlinks all hooks from .githooks/ into .git/hooks/ and makes them
# executable. Run this once after cloning the repository.
#
# Available hooks:
# - commit-msg : Enforces the Conventional Commit specification
# - pre-commit : Regenerates Brewfile when brew.sh is staged for commit
#
# Usage:
# zsh hooks.sh
# =============================================================================
CURRENT_DIR="$PWD"
HOOKS_DIR=".githooks"
TARGET_HOOKS_DIR=".git/hooks"
# Ensure hooks directory exists
mkdir -p "$HOOKS_DIR"
# Link all custom hooks to the Git hooks directory
for hook in "$HOOKS_DIR"/*; do
hook_name=$(basename "$hook")
LINK=$TARGET_HOOKS_DIR/$hook_name
if [ ! -e "$LINK" ]; then
ln -s "$CURRENT_DIR/$hook" "$LINK"
echo "-----> Symlinking $LINK in Git hooks"
fi
# Make the symlinked hook file executable
chmod +x "$LINK"
echo "-----> Made $LINK executable"
done