From 50cb734cf7e669e87216db9c15930fe57d5d120e Mon Sep 17 00:00:00 2001 From: Lang Martin Date: Wed, 17 Apr 2019 15:27:50 -0700 Subject: [PATCH] dev/hooks/pre-push refuses to push to master, still checks oss --- dev/hooks/pre-push | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/dev/hooks/pre-push b/dev/hooks/pre-push index ecc6108be..e1afca2e8 100755 --- a/dev/hooks/pre-push +++ b/dev/hooks/pre-push @@ -1,14 +1,27 @@ #!/bin/sh - -remote="$1" - -if [ "$remote" == "enterprise" ]; then - exit 0 -fi - -if [ -f version/version_ent.go ]; then - echo "Found enterprise version file while pushing to oss remote" +fail () { + echo "pre-push hook: $@" >&2 + echo " --no-verify to bypass this hook" >&2 exit 1 +} + +# only push to oss when the enterprise version is absent +# ==================== +oss="git@github.com:/hashicorp/nomad" +ent="git@github.com:/hashicorp/nomad-enterprise" +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 -exit 0 +# don't push to master, stable-* +# ==================== +while read local_ref local_sha remote_ref remote_sha +do + if [ "$remote_ref" = "refs/heads/master" ]; then + fail "refusing to push directly to master" + fi + + if echo "$remote_ref"|grep -q 'refs/heads/stable-.*'; then + fail "refusing to push directly to a branch prefixed \`stable-\`" + fi +done