#!/usr/bin/env bash
# Reject a push if any outgoing commit carries an unauthorized identity.
set -uo pipefail
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
ZERO=0000000000000000000000000000000000000000
rc=0
while read -r _lref lsha _rref rsha; do
  [ "$lsha" = "$ZERO" ] && continue
  if [ "$rsha" = "$ZERO" ]; then
    base=$(git rev-list --max-parents=0 "$lsha" | tail -1)
  else
    base="$rsha"
  fi
  "$HERE/authorship-check.sh" "$base" "$lsha" || rc=1
done
exit "$rc"
