Stefan Tauner | 7634708 | 2016-11-27 17:45:49 +0100 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | # A hook script to verify what is about to be pushed. Called by "git |
| 4 | # push" after it has checked the remote status, but before anything has been |
| 5 | # pushed. If this script exits with a non-zero status nothing will be pushed. |
| 6 | # |
| 7 | # This hook is called with the following parameters: |
| 8 | # |
| 9 | # $1 -- Name of the remote to which the push is being done |
| 10 | # $2 -- URL to which the push is being done |
| 11 | # |
| 12 | # If pushing without using a named remote those arguments will be equal. |
| 13 | # |
| 14 | # Information about the commits which are being pushed is supplied as lines to |
| 15 | # the standard input in the form: |
| 16 | # |
| 17 | # <local ref> <local sha1> <remote ref> <remote sha1> |
| 18 | |
| 19 | remote="$1" |
| 20 | url="$2" |
| 21 | |
| 22 | zero=0000000000000000000000000000000000000000 |
| 23 | |
| 24 | upstream_pattern="github\.com.flashrom/flashrom(\.git)?|flashrom\.org.git/flashrom(\.git)?" |
| 25 | precious_branches="stable staging" |
| 26 | |
| 27 | # Only care about the upstream repository |
| 28 | if echo "$url" | grep -q -v -E "$upstream_pattern" ; then |
| 29 | exit 0 |
| 30 | fi |
| 31 | |
| 32 | while read local_ref local_sha remote_ref remote_sha ; do |
| 33 | if [ "$remote_ref" != "refs/heads/staging" -a "$remote_ref" != "refs/heads/stable" ]; then |
| 34 | echo "Feature branches not allowed ($remote_ref)." >&2 |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | if [ "$local_sha" = $zero ]; then |
| 39 | echo "Deletion of branches is prohibited." >&2 |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | if [ "$remote_sha" = "$zero" ]; then |
| 44 | echo "No new branches allowed." >&2 |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | # Check for Signed-off-by and Acked-by |
| 49 | commit=$(git rev-list -n 1 --all-match --invert-grep -E \ |
| 50 | --grep '^Signed-off-by: .+ <.+@.+\..+>$' --grep '^Acked-by: .+ <.+@.+\..+>$' \ |
| 51 | "$remote_sha..$local_sha") |
| 52 | if [ -n "$commit" ]; then |
| 53 | echo "Commit $local_sha in $local_ref is missing either \"Signed-off-by\"" \ |
| 54 | " or \"Acked-by\" lines, not pushing." >&2 |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
| 58 | # Make _really_ sure we do not rewrite precious history |
| 59 | for lbranch in $precious_branches ; do |
| 60 | if [ "$remote_ref" = "refs/heads/$lbranch" ]; then |
| 61 | nonreachable=$(git rev-list $remote_sha ^$local_sha | head -1) |
| 62 | if [ -n "$nonreachable" ]; then |
| 63 | echo "Only fast-forward pushes are allowed on $lbranch." >&2 |
| 64 | echo "$nonreachable is not included in $remote_sha while pushing to $remote_ref" >&2 |
| 65 | exit 1 |
| 66 | fi |
| 67 | fi |
| 68 | done |
| 69 | |
| 70 | # FIXME: check commit log format (subject without full stop at the end etc). |
| 71 | # FIXME: do buildbot checks if authorized? |
| 72 | done |
| 73 | |
| 74 | exit 0 |