Repository navigation
fix(hooks): resolve the real hooks dir so worktree installs don't crash init - #1808
Conversation
…sh init In a git worktree, .git is a *file* (gitdir: <path>) pointing at the shared metadata dir, not a directory. The hook installer/status/uninstall built `root / ".git" / "hooks"` from _git_root's heuristic, so in a worktree `mkdir` raised NotADirectoryError and the crash propagated up to take down the whole `repowise init` (issue repowise-dev#1609). - Add _hooks_dir(repo_path): resolve via `git rev-parse --git-path hooks`, which returns the real (shared) hooks dir for both normal repos and worktrees, falling back to the .git/hooks heuristic when git is unavailable or not a repo. - install/status/uninstall now use _hooks_dir. Fixes repowise-dev#1609
|
📋 At a glance Files & modules (2)
✅ Health gate: passed 📌 Before you merge
🔎 More signals (2)🗺️ Change map flowchart LR
subgraph PR ["Changed in this PR (1 with dependents)"]
f_packages_cli_src_repowise_cli_hooks_py[".../cli/hooks.py 🔥"]:::changed
end
f_packages_cli_src_repowise_cli_commands_hook_cmd_py[".../commands/hook_cmd.py"]
f_packages_cli_src_repowise_cli_hooks_py --> f_packages_cli_src_repowise_cli_commands_hook_cmd_py
f_packages_cli_src_repowise_cli_commands_init_cmd__interactive_py[".../init_cmd/_interactive.py"]
f_packages_cli_src_repowise_cli_hooks_py --> f_packages_cli_src_repowise_cli_commands_init_cmd__interactive_py
f_packages_cli_src_repowise_cli_editor_setup_py[".../cli/editor_setup.py"]
f_packages_cli_src_repowise_cli_hooks_py --> f_packages_cli_src_repowise_cli_editor_setup_py
t_tests_unit_cli_test_editor_setup_py(["✅ .../cli/test_editor_setup.py"]):::guard
t_tests_unit_cli_test_editor_setup_py -.-> f_packages_cli_src_repowise_cli_hooks_py
classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Solid arrows: code that imports the changed files (3 direct dependents, from the last indexed snapshot). Dashed: history/tests. 🔥 Hotspots touched (2)
👀 Suggested reviewers @RaghavChamadiya 📊 See the full report for this PR |
RaghavChamadiya
left a comment
There was a problem hiding this comment.
Thanks @sloemo01. The diagnosis holds exactly as written: _git_root tests with .exists(), not .is_dir(), so in a worktree it happily returns the root and the failure lands one level down on mkdir, which is why a hook-install detail was able to take down the whole init.
Asking git for the path instead of rebuilding it is the right instinct, and it buys more than the worktree fix you claimed. git rev-parse --git-path hooks also honors core.hooksPath:
$ git rev-parse --git-path hooks
C:\Users\...\repowise\.git\hooks
$ git -c core.hooksPath=/tmp/myhooks rev-parse --git-path hooks
/tmp/myhooks
So this quietly fixes a second case nobody has filed: anyone using husky, lefthook or pre-commit has core.hooksPath pointed elsewhere, and the old code was writing a post-commit hook into a directory git had stopped reading. The hook installed, reported success, and never fired. Worth a line in the changelog beyond the worktree crash.
The absolute-or-relative handling on the rev-parse output is correct, and keeping the .git/hooks heuristic as a fallback means a machine without git on PATH degrades the way it used to instead of newly returning nothing.
|
Correction to my merge comment above. I said the |
What
Fixes #1609. In a git worktree,
.gitis a file (gitdir: <path>), not a directory. The hook installer builtroot / ".git" / "hooks"from_git_root's heuristic, so in a worktreemkdirraisedNotADirectoryErrorand the crash propagated up to take down the wholerepowise init.Root cause
_git_rootwalks up for any.gitentry — but in a worktree that entry is a file, not a directory.install()/status()/uninstall()then didroot / ".git" / "hooks", which fails on a worktree because.gitis not a directory.Fix
_hooks_dir(repo_path)— resolves the real hooks dir viagit rev-parse --git-path hooks, which returns the correct (shared) hooks dir for both normal repos and worktrees. Falls back to the.git/hooksheuristic when git is unavailable or not a repo.install,status, anduninstallnow use_hooks_dir.Tests
TestInstallInWorktreeintest_hooks_legacy_migration.py: creates a real worktree (where.gitis asserted to be a file), verifiesinstallno longer crashes andstatusreports correctly.