#!/bin/bash # # Usage: Copy this file to your repository's .git/hooks directory. Name it # "pre-push" and set the executable bit. # # This hook aborts git push when the log message of any commits to be pushed # starts with "WIP" (work in progress) or "stash", if the remote ref begins # with "refs/for/". This prevents incomplete/unwanted commits from being # pushed to Gerrit instances. # # When pushing to Gerrit, this hook also runs a Gradle build similar to # Gerrit's presubmit, to help catch errors locally and reduce churn on CLs. # # Remaining comments are copied from .git/hooks/pre-push.sample. # # An example hook script to verify what is about to be pushed. Called by "git # push" after it has checked the remote status, but before anything has been # pushed. If this script exits with a non-zero status nothing will be pushed. # # This hook is called with the following parameters: # # $1 -- Name of the remote to which the push is being done # $2 -- URL to which the push is being done # # If pushing without using a named remote those arguments will be equal. # # Information about the commits which are being pushed is supplied as lines to # the standard input in the form: # # remote="$1" url="$2" z40=0000000000000000000000000000000000000000 while read local_ref local_sha remote_ref remote_sha do # Handle delete if [[ "$local_sha" = "$z40" ]]; then echo "$local_ref, $remote_ref" : # Move along if we don't match refs/for/ elif [[ ! "$remote_ref" =~ ^refs/for/.+ ]]; then echo "$local_ref, $remote_ref" : else echo "$local_ref, $local_sha, $remote_ref, $remote_sha" if [[ "$remote_sha" = "$z40" ]]; then # New branch, examine all commits branchname="${remote_ref#refs/for/}" if [[ "$branchname" =~ % ]]; then # Gerrit allows various push-options by appending them to the remote # using "%