Merge pull request #5581 from hashicorp/dev-make-boostrap-git-hooks

Dev make boostrap git hooks
This commit is contained in:
Lang Martin 2019-04-30 16:36:10 -04:00 committed by GitHub
commit 9cf1c5a74d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 11 deletions

View File

@ -133,7 +133,7 @@ endef
$(foreach t,$(ALL_TARGETS),$(eval $(call makePackageTarget,$(t))))
.PHONY: bootstrap
bootstrap: deps lint-deps # Install all dependencies
bootstrap: deps lint-deps git-hooks # Install all dependencies
.PHONY: deps
deps: ## Install build and development dependencies
@ -153,6 +153,13 @@ lint-deps: ## Install linter dependencies
go get -u github.com/alecthomas/gometalinter
gometalinter --install
.PHONY: git-hooks
git-dir = $(shell git rev-parse --git-dir)
git-hooks: $(git-dir)/hooks/pre-push
$(git-dir)/hooks/%: dev/hooks/%
cp $^ $@
chmod 755 $@
.PHONY: check
check: ## Lint the source code
@echo "==> Linting source code..."

View File

@ -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