2023-06-01 14:36:20 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2019-04-17 22:27:50 +00:00
|
|
|
fail () {
|
|
|
|
echo "pre-push hook: $@" >&2
|
|
|
|
echo " --no-verify to bypass this hook" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2017-08-17 17:55:53 +00:00
|
|
|
|
2019-04-17 22:27:50 +00:00
|
|
|
# only push to oss when the enterprise version is absent
|
|
|
|
# ====================
|
2020-02-03 16:29:05 +00:00
|
|
|
oss="git@github.com:hashicorp/nomad.git"
|
|
|
|
ent="git@github.com:hashicorp/nomad-enterprise.git"
|
2019-04-17 22:27:50 +00:00
|
|
|
if [ "$2" != "$ent" -a -f version/version_ent.go ]; then
|
|
|
|
fail "found enterprise version file version/version_ent.go while pushing to oss remote"
|
2017-08-17 17:55:53 +00:00
|
|
|
fi
|
|
|
|
|
2023-06-01 14:36:20 +00:00
|
|
|
# do not push directly to main, stable-*, release/*
|
2019-04-17 22:27:50 +00:00
|
|
|
# ====================
|
|
|
|
while read local_ref local_sha remote_ref remote_sha
|
|
|
|
do
|
2021-03-08 13:50:13 +00:00
|
|
|
if [ "$remote_ref" = "refs/heads/main" ]; then
|
2023-06-01 14:36:20 +00:00
|
|
|
fail "refusing to push directly to main"
|
2019-04-17 22:27:50 +00:00
|
|
|
fi
|
2017-08-17 17:55:53 +00:00
|
|
|
|
2019-04-17 22:27:50 +00:00
|
|
|
if echo "$remote_ref"|grep -q 'refs/heads/stable-.*'; then
|
2023-06-01 14:36:20 +00:00
|
|
|
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/\`"
|
2019-04-17 22:27:50 +00:00
|
|
|
fi
|
|
|
|
done
|