From a39ec2d964ef0cf074115bb7683809984407ff54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Thu, 19 Feb 2026 15:18:08 +0000 Subject: [PATCH] fix: correctly calculate core.hooksPath for git worktrees Use realpath --relative-to instead of bash string stripping to compute the relative path to the git common directory. The previous approach silently failed for worktrees where the common directory is not under the working tree, causing hooks to not be found by git. Fixes #688 Co-Authored-By: Claude Opus 4.6 --- modules/pre-commit.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index cf807acf..c947fd1c 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -526,7 +526,9 @@ in common_dir=''$(${cfg.gitPackage}/bin/git rev-parse --path-format=absolute --git-common-dir) # Convert the absolute path to a path relative to the toplevel working directory. - common_dir=''${common_dir#''$GIT_WC/} + # Using realpath instead of string stripping to correctly handle git worktrees + # where the common directory is not under the working tree. + common_dir=''$(${pkgs.coreutils}/bin/realpath --relative-to="''$GIT_WC" "''$common_dir") ${lib.getExe cfg.gitPackage} config --local core.hooksPath "''$common_dir/hooks" fi