#!/bin/sh
# Reject empty or wip/fixup commit messages on main.
msg_file="$1"
msg=$(head -1 "$msg_file")

if [ -z "$msg" ]; then
    echo "commit-msg: empty commit message"
    exit 1
fi

branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" = "main" ] && echo "$msg" | grep -qiE '^(wip|fixup!|squash!)'; then
    echo "commit-msg: refusing wip/fixup commit message on main"
    exit 1
fi

exit 0
