diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2019-03-06 19:45:58 +0200 |
---|---|---|
committer | rl1987 <rl1987@sdf.lonestar.org> | 2019-03-10 18:28:06 +0200 |
commit | 888bb9508b7a89550d3b2d33236073fc14868a98 (patch) | |
tree | 89fd2ac7e9133de9f74354d00c26d07790b25114 /scripts/git/pre-push.git-hook | |
parent | 7b5f31f2d6bea00d6e67d0f387dbc79398192c66 (diff) | |
download | tor-888bb9508b7a89550d3b2d33236073fc14868a98.tar.gz tor-888bb9508b7a89550d3b2d33236073fc14868a98.zip |
Move all git maintenance scripts to separate directory
Diffstat (limited to 'scripts/git/pre-push.git-hook')
-rwxr-xr-x | scripts/git/pre-push.git-hook | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/scripts/git/pre-push.git-hook b/scripts/git/pre-push.git-hook new file mode 100755 index 0000000000..e7a72efa08 --- /dev/null +++ b/scripts/git/pre-push.git-hook @@ -0,0 +1,82 @@ +#!/bin/bash + +# git pre-push hook script to: +# 1) prevent "fixup!" and "squash!" commit from ending up in master, release-* +# or maint-* +# 2) Disallow pushing branches other than master, release-* +# and maint-* to origin (e.g. gitweb.torproject.org). +# +# To install this script, copy it into .git/hooks/pre-push path in your +# local copy of git repository. Make sure it has permission to execute. +# +# The following sample script was used as starting point: +# https://github.com/git/git/blob/master/templates/hooks--pre-push.sample + +echo "Running pre-push hook" + +z40=0000000000000000000000000000000000000000 + +remote="$1" + +ref_is_upstream_branch() { + if [ "$1" == "refs/heads/master" ] || + [[ "$1" == refs/heads/release-* ]] || + [[ "$1" == refs/heads/maint-* ]] + then + return 1 + fi +} + +# shellcheck disable=SC2034 +while read -r local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + if (ref_is_upstream_branch "$local_ref" == 0 || + ref_is_upstream_branch "$remote_ref" == 0) && + [ "$local_ref" != "$remote_ref" ] + then + if [ "$remote" == "origin" ] + then + echo >&2 "Not pushing: $local_ref to $remote_ref" + echo >&2 "If you really want to push this, use --no-verify." + exit 1 + else + continue + fi + fi + + # Check for fixup! commit + commit=$(git rev-list -n 1 --grep '^fixup!' "$range") + if [ -n "$commit" ] + then + echo >&2 "Found fixup! commit in $local_ref, not pushing" + echo >&2 "If you really want to push this, use --no-verify." + exit 1 + fi + + # Check for squash! commit + commit=$(git rev-list -n 1 --grep '^squash!' "$range") + if [ -n "$commit" ] + then + echo >&2 "Found squash! commit in $local_ref, not pushing" + echo >&2 "If you really want to push this, use --no-verify." + exit 1 + fi + fi +done + +exit 0 + |