From e28da4ce5d0a0795c6c4f8465d9bc218165a0493 Mon Sep 17 00:00:00 2001 From: Ryan Cragun Date: Fri, 2 Feb 2024 11:38:01 -0700 Subject: [PATCH] [QT-669] Automatically synchronize git hooks on make invocation (#25197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git doesn’t allow hooks to be in-repo which prevents branch specific hooks. To get around this we’ve historically copied our hooks from .hooks into .git/hooks when running make prep in vault and vault-enterprise. That sort of works but has the following issues: * If you hooks call into files in-repo and they are modified between branches you have to re-sync to resolve it * Remembering to sync the hooks is cumbersome We can’t exactly get around the first issue. It’s always possible that if you change branches and don’t update your hooks you could run into this problem if you try to commit without updating them. But we can make it less likely to fail by: * Always syncing the hooks whenever make is called * Updating the files in the hooks on all maintained branches to be consistent Signed-off-by: Ryan Cragun --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c345c5fed0..27be0f94b6 100644 --- a/Makefile +++ b/Makefile @@ -163,8 +163,15 @@ prep: check-go-version @GOARCH= GOOS= $(GO_CMD) generate $(MAIN_PACKAGES) @GOARCH= GOOS= cd api && $(GO_CMD) generate $(API_PACKAGES) @GOARCH= GOOS= cd sdk && $(GO_CMD) generate $(SDK_PACKAGES) + +# Git doesn't allow us to store shared hooks in .git. Instead, we make sure they're up-to-date +# whenever a make target is invoked. +.PHONY: hooks +hooks: @if [ -d .git/hooks ]; then cp .hooks/* .git/hooks/; fi +-include hooks # Make sure they're always up-to-date + # bootstrap the build by generating any necessary code and downloading additional tools that may # be used by devs. bootstrap: prep tools @@ -378,4 +385,4 @@ ci-copywriteheaders: .PHONY: all-packages all-packages: - @echo $(ALL_PACKAGES) | tr ' ' '\n' + @echo $(ALL_PACKAGES) | tr ' ' '\n'