vitals/tools/check-dco.sh
Christian Sass aeb8065807 docs: contribution terms, and a check that enforces them
Vitals takes contributions under MIT, inbound equal to outbound, with a
Developer Certificate of Origin instead of a CLA. That is the same shape
Nextcloud uses on the project this tool was written to watch, so nobody
contributing here is being asked for paperwork they would not sign
upstream.

tools/check-dco.sh verifies both presence and identity of the sign-off,
and fails the pull request if either is wrong. Tested against three
cases: unsigned, correctly signed, and signed by someone other than the
author.

Signed-off-by: Christian Sass <csass@binaryranch.com>
2026-10-21 13:46:29 -05:00

31 lines
920 B
Bash
Executable file

#!/usr/bin/env bash
# DCO check: every commit in the range must carry a Signed-off-by trailer that
# matches the commit author. Run locally as: ./tools/check-dco.sh origin/main..HEAD
set -euo pipefail
range="${1:-origin/main..HEAD}"
fail=0
while IFS= read -r sha; do
[ -z "$sha" ] && continue
author_email="$(git log -1 --format='%ae' "$sha")"
body="$(git log -1 --format='%B' "$sha")"
if ! printf '%s' "$body" | grep -qiE '^Signed-off-by: .+ <.+@.+>'; then
echo "MISSING sign-off: $sha $(git log -1 --format='%s' "$sha")"
fail=1
continue
fi
if ! printf '%s' "$body" | grep -qiE "^Signed-off-by: .+ <${author_email}>"; then
echo "MISMATCHED sign-off: $sha expected <$author_email>"
fail=1
fi
done < <(git rev-list "$range")
if [ "$fail" -ne 0 ]; then
echo
echo "Fix with: git commit -s --amend (or git rebase --signoff $range)"
exit 1
fi
echo "DCO: all commits signed off"