mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
46 lines
1.3 KiB
Bash
Executable File
46 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
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.git"
|
|
ent="hashicorp/nomad-enterprise"
|
|
|
|
# isEnterprise exits with a 0 when the first parameter matches the
|
|
# nomad-enterprise repo, regardless of additional optional and variable
|
|
# components of the remote URL, like the terminal ".git" extension
|
|
isEnterprise () {
|
|
local arg="${1}"
|
|
return (echo "${arg}" | grep -q -E "^(https://github.com/|git@github.com:)?${ent}(.git)?$")
|
|
}
|
|
|
|
isEnterprise "${2}"
|
|
|
|
if [ $? -ne 0 -a -f version/version_ent.go ]; then
|
|
fail "found enterprise version file version/version_ent.go pushing to non-enterprise remote \"${2}\""
|
|
fi
|
|
|
|
# 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"
|
|
fi
|
|
|
|
if echo "$remote_ref"|grep -q 'refs/heads/stable-.*'; then
|
|
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
|