pre-push 919 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. # Pre-push: Don't allow commits without Signed-off-by. Skip with "git push --no-verify".
  3. set -euo pipefail
  4. z40=0000000000000000000000000000000000000000 # magic deleted ref
  5. while read local_ref local_sha remote_ref remote_sha; do
  6. if [ "$local_sha" != $z40 ]; then
  7. if [ "$remote_sha" = $z40 ]; then
  8. # New branch, examine all commits
  9. range="$(git merge-base master $local_sha)..$local_sha"
  10. else
  11. # Update to existing branch, examine new commits
  12. range="$remote_sha..$local_sha"
  13. fi
  14. # Check for commits without sign-off
  15. commit=$(git rev-list --no-merges --grep 'Signed-off-by' --invert-grep "$range")
  16. if [ -n "$commit" ]; then
  17. echo >&2 "Found commits without sign-off in $local_ref. Aborting push. Offending commits:"
  18. echo >&2 "$commit"
  19. exit 1
  20. fi
  21. fi
  22. done
  23. exit 0