Install pre-commit hook via make hooks; resolve shared hooks dir
The hooks target uses git rev-parse --git-common-dir so it works from both the main checkout and linked worktrees.
This commit is contained in:
14
Makefile
14
Makefile
@@ -33,12 +33,16 @@ check: test lint fmt-check
|
||||
docker:
|
||||
docker build -t $(BINARY) .
|
||||
|
||||
# Hooks are shared between the main checkout and all worktrees, so
|
||||
# resolve the common git dir instead of assuming .git is a directory.
|
||||
HOOKS_DIR := $(shell git rev-parse --git-common-dir)/hooks
|
||||
|
||||
hooks:
|
||||
@printf '#!/bin/sh\nset -e\n' > .git/hooks/pre-commit
|
||||
@printf 'go mod tidy\ngo fmt ./...\n' >> .git/hooks/pre-commit
|
||||
@printf 'git diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> .git/hooks/pre-commit
|
||||
@printf 'make check\n' >> .git/hooks/pre-commit
|
||||
@chmod +x .git/hooks/pre-commit
|
||||
@printf '#!/bin/sh\nset -e\n' > $(HOOKS_DIR)/pre-commit
|
||||
@printf 'go mod tidy\ngo fmt ./...\n' >> $(HOOKS_DIR)/pre-commit
|
||||
@printf 'git diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> $(HOOKS_DIR)/pre-commit
|
||||
@printf 'make check\n' >> $(HOOKS_DIR)/pre-commit
|
||||
@chmod +x $(HOOKS_DIR)/pre-commit
|
||||
|
||||
clean:
|
||||
rm -f $(BINARY) files.dat
|
||||
|
||||
Reference in New Issue
Block a user