repo: block pushing to release branches in git hook (#17377)

This commit is contained in:
Seth Hoenig
2023-06-01 09:36:20 -05:00
committed by GitHub
parent 20ee6e9a23
commit 1eeb3298b9

View File

@@ -1,4 +1,7 @@
#!/bin/sh
#!/usr/bin/env bash
set -euo pipefail
fail () {
echo "pre-push hook: $@" >&2
echo " --no-verify to bypass this hook" >&2
@@ -13,15 +16,19 @@ if [ "$2" != "$ent" -a -f version/version_ent.go ]; then
fail "found enterprise version file version/version_ent.go while pushing to oss remote"
fi
# don't push to main, stable-*
# do not push directly to main, stable-*, release/*
# ====================
while read local_ref local_sha remote_ref remote_sha
do
if [ "$remote_ref" = "refs/heads/main" ]; then
fail "refusing to push directly to main"
fail "refusing to push directly to main"
fi
if echo "$remote_ref"|grep -q 'refs/heads/stable-.*'; then
fail "refusing to push directly to a branch prefixed \`stable-\`"
fail "refusing to push directly to a branch prefixed \`stable-\`"
fi
if echo "$remote_ref"|grep -q 'refs/heads/release/.*'; then
fail "refusing to push directly to a branch prefixed \`release/\`"
fi
done