From 5b20171dbda0fb60916aec116b23cf4eaf97288f Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 23 Jul 2026 06:45:02 +0700 Subject: [PATCH] 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. --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 56963c4..b40b63a 100644 --- a/Makefile +++ b/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