#!/usr/bin/env bash # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. # # SPDX-License-Identifier: MPL-2.0 # Copyright (c) 2026 Jairus Tanaka set -euo pipefail msg_file="${1:-}" if [ -z "$msg_file" ] || [ ! -f "$msg_file" ]; then echo "commit-msg hook requires the commit message file path." exit 1 fi msg="$(head -n 1 "$msg_file" | tr -d '\r')" pattern='^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([[:alnum:]_.\/-]+\))?(!)?: .+' if ! printf '%s\n' "$msg" | grep -Eq "$pattern"; then cat <<'EOF' Commit message must follow Conventional Commits: (optional-scope): description Examples: feat: add fast path for string deserialization fix(json-value): retain managed refs across GC chore!: drop deprecated cache experiment EOF exit 1 fi