30 lines
708 B
Bash
Executable File
30 lines
708 B
Bash
Executable File
#!/bin/sh -euC
|
|
#
|
|
# Reject commit messages that do not conform to Conventional Commits.
|
|
#
|
|
# Enforces Conventional Commits v1.0.0 at the syntactic level.
|
|
#
|
|
# Upstream: gitea.bp99.eu/bp99/git-hooks
|
|
|
|
subject="$(sed -n 1p "$1")"
|
|
second="$(sed -n 2p "$1")"
|
|
|
|
fail() {
|
|
>&2 cat <<EOF
|
|
commit-msg: $1
|
|
|
|
subject: $subject
|
|
format: <type>[(<scope>)][!]: <description>
|
|
|
|
Bypass with: git commit --no-verify
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
# type, optional (scope), optional !, terminal ': ', non-emtpy desc
|
|
printf '%s' "$subject" | grep -Eq '^[[:alpha:]]+(\([^()]+\))?!?: .+' \
|
|
|| fail 'subject does not conform to Conventional Commits'
|
|
|
|
# Body must begin one blank line after description
|
|
[ -z "$second" ] || fail 'Line 2 must be blank'
|