pre-push 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. # Pre-push: Don't allow commits without Signed-off-by. Skip with "git push --no-verify".
  3. # SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
  4. # SPDX-FileCopyrightText: 2021 Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
  5. # SPDX-License-Identifier: GPL-3.0-or-later
  6. set -euo pipefail
  7. z40=0000000000000000000000000000000000000000 # magic deleted ref
  8. while read local_ref local_sha remote_ref remote_sha; do
  9. if [ "$local_sha" != $z40 ]; then
  10. if [ "$remote_sha" = $z40 ]; 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 commits without sign-off
  18. commit=$(git rev-list --no-merges --grep 'Signed-off-by' --invert-grep "$range")
  19. if [ -n "$commit" ]; then
  20. echo >&2 "Found commits without sign-off in $local_ref. Aborting push. Offending commits:"
  21. echo >&2 "$commit"
  22. exit 1
  23. fi
  24. fi
  25. done
  26. exit 0