-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-msg.sh
More file actions
executable file
·28 lines (21 loc) · 860 Bytes
/
commit-msg.sh
File metadata and controls
executable file
·28 lines (21 loc) · 860 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
#!/usr/bin/env bash
# Validate commit messages follow conventional commit format.
set -euo pipefail
SUBJECT=$(grep -v '^#' "$1" | sed '/^$/d' | head -n1)
# Skip merge commits, reverts, and empty messages
[[ "$SUBJECT" =~ ^Merge[[:space:]] ]] && exit 0
[[ "$SUBJECT" =~ ^Revert[[:space:]]\" ]] && exit 0
[[ -z "$SUBJECT" ]] && exit 0
TYPES="feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert"
[[ "$SUBJECT" =~ ^($TYPES)(\(.+\))?!?:[[:space:]].+ ]] && exit 0
cat >&2 <<'MSG'
ERROR: commit message must follow conventional commit format.
<type>[optional scope][!]: <description>
Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
Examples:
feat: add semantic release workflow
fix(pty): handle zombie processes on macOS
refactor!: drop deprecated --legacy flag
chore(deps): bump tokio to 1.42
MSG
exit 1