| 1 | #!/bin/sh |
| 2 | |
| 3 | # This hook script prevents the user from pushing to the project's Git repo if |
| 4 | # any of the new commits' OpenPGP signatures cannot be verified, if a commit is |
| 5 | # signed with an unauthorized key, or if the channel news file is malformed |
| 6 | # (which would break the build). |
| 7 | |
| 8 | # Called by "git push" after it has checked the remote status, but before |
| 9 | # anything has been pushed. If this script exits with a non-zero status nothing |
| 10 | # will be pushed. |
| 11 | # |
| 12 | # This hook is called with the following parameters: |
| 13 | # |
| 14 | # $1 -- Name of the remote to which the push is being done |
| 15 | # $2 -- URL to which the push is being done |
| 16 | # |
| 17 | # If pushing without using a named remote those arguments will be equal. |
| 18 | # |
| 19 | # Information about the commits which are being pushed is supplied as lines to |
| 20 | # the standard input in the form: |
| 21 | # |
| 22 | # <local ref> <local sha1> <remote ref> <remote sha1> |
| 23 | |
| 24 | # This is the "empty hash" used by Git when pushing a branch deletion. |
| 25 | z40=0000000000000000000000000000000000000000 |
| 26 | |
| 27 | perform_checks() { |
| 28 | set -e |
| 29 | guix git authenticate |
| 30 | exec make check-channel-news |
| 31 | exit 127 |
| 32 | } |
| 33 | |
| 34 | main() { |
| 35 | while read local_ref local_hash remote_ref remote_hash |
| 36 | do |
| 37 | # When deleting a remote branch, no commits are pushed to the remote, |
| 38 | # and thus there are no signatures or news updates to be verified. |
| 39 | if [ "$local_hash" != $z40 ] |
| 40 | then |
| 41 | # Skip the hook when performing a pull-request... |
| 42 | case "$remote_ref" in |
| 43 | refs/for/*) |
| 44 | exit 0 |
| 45 | ;; |
| 46 | # ... or when pushing a new PGP key to the keyring branch, |
| 47 | # as this branch doesn't share ancestry with the master |
| 48 | # branch and fails the 'guix git authenticate' check. |
| 49 | refs/heads/keyring) |
| 50 | exit 0 |
| 51 | ;; |
| 52 | esac |
| 53 | |
| 54 | # Only perform checks when pushing to upstream. |
| 55 | case "$2" in |
| 56 | *savannah.gnu.org*) |
| 57 | printf "ERROR: The repositories on Savannah are read-only mirrors of our repos at <https://codeberg.org/guix>.\n" 1>&2 |
| 58 | exit 1 |
| 59 | ;; |
| 60 | *.gnu.org*) |
| 61 | perform_checks |
| 62 | ;; |
| 63 | # HTTPS Git remote. |
| 64 | *codeberg.org/guix/*) |
| 65 | perform_checks |
| 66 | ;; |
| 67 | # SSH Git remote. |
| 68 | *codeberg.org:guix/*) |
| 69 | perform_checks |
| 70 | ;; |
| 71 | *) |
| 72 | exit 0 |
| 73 | ;; |
| 74 | esac |
| 75 | fi |
| 76 | done |
| 77 | |
| 78 | exit 0 |
| 79 | } |
| 80 | |
| 81 | main "$@" |