Repository navigation
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·59 lines (49 loc) · 1.64 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·59 lines (49 loc) · 1.64 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
52
53
54
55
56
57
58
59
#!/bin/bash
##
# Pre-commit Hook: Branch Name Validation
#
# Validates branch names before each commit to ensure they follow the LightSpeed
# branching strategy: {type}/{scope}-{short-title}
#
# This hook automatically skips validation for:
# - Protected branches (main, develop)
# - Bot/automation branches (dependabot/*, renovate/*)
# - Detached HEAD state (during rebase, merge, bisect operations)
#
# If validation fails, the commit is blocked with a helpful error message.
# To bypass the hook for development/testing, use: git commit --no-verify
#
# Installation: npm run setup:hooks
#
##
set -e
# Get the current branch name
BRANCH_NAME=$(git branch --show-current 2>/dev/null || true)
# Skip validation if in detached HEAD state (rebase, merge, bisect, etc.)
if [ -z "$BRANCH_NAME" ]; then
exit 0
fi
# Skip validation for protected and bot branches
if [ "$BRANCH_NAME" = "main" ] || [ "$BRANCH_NAME" = "develop" ] || \
[[ "$BRANCH_NAME" =~ ^(dependabot|renovate)/ ]]; then
exit 0
fi
# Get the repository root
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
# Path to validation script (from .git/hooks to repo root)
VALIDATION_SCRIPT="$REPO_ROOT/scripts/validation/validate-branch-name.cjs"
# Check if validation script exists
if [ ! -f "$VALIDATION_SCRIPT" ]; then
echo "⚠️ Branch validation script not found at $VALIDATION_SCRIPT"
echo " Skipping validation. Install the latest version to enable."
exit 0
fi
# Run validation
if ! node "$VALIDATION_SCRIPT" "$BRANCH_NAME"; then
echo ""
echo "💡 Tip: If you need to bypass this check for testing, use:"
echo " git commit --no-verify"
echo ""
exit 1
fi
exit 0