|
| 1 | +#!/bin/bash |
| 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 oid> <remote ref> <remote oid> |
| 18 | + |
| 19 | +BAD_WORDS=("NvidiaProprietary" "Nvidia Proprietary" "NV_PRIVATE") |
| 20 | + |
| 21 | +remote="$1" |
| 22 | +url="$2" |
| 23 | + |
| 24 | +zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0') |
| 25 | + |
| 26 | +while read local_ref local_oid remote_ref remote_oid |
| 27 | +do |
| 28 | + if test "$local_oid" = "$zero" |
| 29 | + then |
| 30 | + # Handle delete |
| 31 | + : |
| 32 | + else |
| 33 | + if test "$remote_oid" = "$zero" |
| 34 | + then |
| 35 | + # New branch, examine all commits |
| 36 | + range="$local_oid" |
| 37 | + else |
| 38 | + # Update to existing branch, examine new commits |
| 39 | + range="$remote_oid..$local_oid" |
| 40 | + fi |
| 41 | + |
| 42 | + # If pushing to a public GitHub repo (i.e. any GitHub repo that is not |
| 43 | + # private), do validation checks. |
| 44 | + if [[ $url =~ "github.com" && ! $url =~ "private" ]]; then |
| 45 | + commits=$(git rev-list $range) |
| 46 | + for commit in $commits; do |
| 47 | + for word in "${BAD_WORDS[@]}"; do |
| 48 | + if git show $commit | grep -q "$word"; then |
| 49 | + echo >&2 "Error: Commit '$commit' contains the forbidden word '$word'. Not pushing!" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + done |
| 53 | + done |
| 54 | + fi |
| 55 | + fi |
| 56 | +done |
| 57 | + |
| 58 | +exit 0 |
0 commit comments