From 4e7648b4e2221ae213d9e342beb24dec10a82908 Mon Sep 17 00:00:00 2001 From: Safi Date: Thu, 14 May 2026 23:37:05 +0100 Subject: [PATCH] fix #865: use git rev-parse --git-path hooks so hook install works in linked worktrees In a linked worktree .git is a file not a directory, so root/.git/hooks fails with NotADirectoryError. Fall back to git rev-parse --path-format=absolute --git-path hooks which resolves the correct hooks dir from any worktree. Co-Authored-By: Claude Sonnet 4.6 --- graphify/hooks.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/graphify/hooks.py b/graphify/hooks.py index 0b1c1e58..2723110e 100644 --- a/graphify/hooks.py +++ b/graphify/hooks.py @@ -197,8 +197,22 @@ def _hooks_dir(root: Path) -> Path: f"{root / '.git' / 'config'}: {exc}", file=sys.stderr, ) + # In a linked worktree .git is a file not a directory, so constructing + # root/.git/hooks directly fails. Ask git for the real hooks path instead. + import subprocess as _sp + try: + res = _sp.run( + ["git", "-C", str(root), "rev-parse", "--path-format=absolute", "--git-path", "hooks"], + capture_output=True, text=True, + ) + if res.returncode == 0: + d = Path(res.stdout.strip()) + d.mkdir(parents=True, exist_ok=True) + return d + except (OSError, FileNotFoundError): + pass d = root / ".git" / "hooks" - d.mkdir(exist_ok=True) + d.mkdir(parents=True, exist_ok=True) return d