Skip to content

Commit

Permalink
[QT-669] Automatically synchronize git hooks on make invocation (#25197)
Browse files Browse the repository at this point in the history
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 <me@ryan.ec>
  • Loading branch information
ryancragun authored Feb 2, 2024
1 parent 8a81b7d commit e28da4c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -378,4 +385,4 @@ ci-copywriteheaders:

.PHONY: all-packages
all-packages:
@echo $(ALL_PACKAGES) | tr ' ' '\n'
@echo $(ALL_PACKAGES) | tr ' ' '\n'

0 comments on commit e28da4c

Please sign in to comment.