Make pre-commit hook installation and execution work in git worktrees (#1643)

- Closes #1641.
- This PR replaces the existing hook pathname computation
  for `make pre-commit` with `git rev-parse --git-path hooks/...`,
  which resolves to the shared hooks directory in both the main
  checkout and any worktree.
This commit is contained in:
Harshit Singh Bhandari
2026-06-04 14:59:12 -07:00
committed by GitHub
parent 59e015acd1
commit 8bf87e8890
+7 -6
View File
@@ -319,12 +319,13 @@ check-licenses:
.PHONY: pre-commit
pre-commit:
cp scripts/pre-commit.fmt .git/hooks
touch .git/hooks/pre-commit
cat .git/hooks/pre-commit | grep -v 'hooks/pre-commit\.fmt' > /tmp/pre-commit.new || true
echo 'PRECOMMIT_NOFMT=$${PRECOMMIT_NOFMT} $$(git rev-parse --show-toplevel)/.git/hooks/pre-commit.fmt' >> /tmp/pre-commit.new
mv /tmp/pre-commit.new .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
$(eval HOOKS_DIR := $(shell git rev-parse --git-path hooks))
cp scripts/pre-commit.fmt $(HOOKS_DIR)/
touch $(HOOKS_DIR)/pre-commit
cat $(HOOKS_DIR)/pre-commit | grep -v 'hooks/pre-commit\.fmt' > /tmp/pre-commit.new || true
echo 'PRECOMMIT_NOFMT=$${PRECOMMIT_NOFMT} $$(git rev-parse --git-path hooks/pre-commit.fmt)' >> /tmp/pre-commit.new
mv /tmp/pre-commit.new $(HOOKS_DIR)/pre-commit
chmod +x $(HOOKS_DIR)/pre-commit
.PHONY: serve-docs
serve-docs: