pre-push 782 B

12345678910111213141516171819202122232425262728293031
  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
  6. do
  7. if [ "$local_sha" != $z40 ]
  8. then
  9. if [ "$remote_sha" = $z40 ]
  10. then
  11. # New branch, examine all commits
  12. range="$(git merge-base master $local_sha)..$local_sha"
  13. else
  14. # Update to existing branch, examine new commits
  15. range="$remote_sha..$local_sha"
  16. fi
  17. # Check for WIP commit
  18. commit=$(git rev-list --grep 'Signed-off-by' --invert-grep "$range")
  19. if [ -n "$commit" ]
  20. then
  21. echo >&2 "Found commits without signoff in $local_ref. Aborting push. Offending commits:"
  22. echo >&2 "$commit"
  23. exit 1
  24. fi
  25. fi
  26. done
  27. exit 0