#!/bin/bash
set -e -o pipefail

# Don't use CI_PROJECT_URL, because that might refer to a user's fork,
# which might not have all the branches we care about.

repo_url=$(sed -n 's/^Vcs-Git:  *//p' debian/control)

git remote rm repo 2>/dev/null ||:
git remote add repo "${repo_url}"
git fetch --unshallow -p repo || echo 'OK, maybe it was not shallow'
git fetch -p repo

git log --pretty=oneline --invert-grep -i --grep '^signed-off-by'	\
    ^repo/{trixie,main}						\
    HEAD								\
    >../missing-sob

if cmp -s ../missing-sob /dev/null; then
    echo 'All commits signed off, OK.'
    exit 0
fi

echo '===== commit(s) missing Signed-Off-by ====='
cat ../missing-sob
echo '===== ^ some commit(s) missing Signed-Off-by ====='
exit 8
