#!/bin/sh
# Enforce DCO sign-off on every local commit.
# Commit messages must carry a "Signed-off-by:" trailer. Add one with `git commit -s`.
#
# Enable this hook once per clone with: just install-hooks
# (sets core.hooksPath to this directory).

msg_file="$1"
subject=$(sed -n '1p' "$msg_file")

case "$subject" in
    fixup!\ *|squash!\ *|Merge\ *)
        exit 0
        ;;
esac

if ! grep -qE '^Signed-off-by: .+ <.+@.+>' "$msg_file"; then
    echo "commit-msg hook: missing DCO sign-off." >&2
    echo "  Re-run with 'git commit -s' to add a Signed-off-by trailer." >&2
    exit 1
fi
