fix(indexer): resolve git hooks dir via git, not hardcoded .git/hooks#53
Open
fazleelahhee wants to merge 2 commits intomainfrom
Open
fix(indexer): resolve git hooks dir via git, not hardcoded .git/hooks#53fazleelahhee wants to merge 2 commits intomainfrom
fazleelahhee wants to merge 2 commits intomainfrom
Conversation
`install_hooks` and the inline uninstall logic in `cce uninstall` both assumed `<project>/.git/hooks/` is always a real directory. In a git worktree, `<project>/.git` is a *file* (gitfile pointer) and the actual hooks live in the shared main-repo `.git/hooks/`. The old path check silently no-op'd, so installing or uninstalling from inside a worktree did nothing — no auto-reindex hook fired on commit, and uninstall appeared successful while leaving hooks in place. Use `git rev-parse --git-path hooks` to resolve the real directory. That returns the relative `.git/hooks` for regular checkouts, the absolute path to the shared main-repo hooks dir for worktrees, and respects `core.hooksPath` if a project has overridden it. Same code path for both install and uninstall. Refactor: extract a new `uninstall_hooks(project_dir)` in `indexer/git_hooks.py` so the cli.py uninstall command shares the worktree-aware resolver. cli.py is now three lines instead of a hand-rolled directory walk. Tests: - Convert the existing fake-`.git/hooks/` fixture to a real `git init` repo so the resolver is exercised end-to-end (the previous fixture silently masked the production path). - New worktree fixture (`git worktree add`) pins both the install and uninstall behavior: from a worktree, both must operate on the shared main-repo hooks dir. - Skip the file when git binary is unavailable (matches `_resolve_hooks_dir` graceful return-None contract). Partially addresses #48 — the storage-key collision item from that issue is left for a follow-up since it touches 30+ call sites and needs a one-time migration.
This was referenced May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Partially addresses #48.
install_hooksandcce uninstallboth assumed<project>/.git/hooks/is always a directory. In a git worktree,<project>/.gitis a file (gitfile pointer) and the hooks live in the shared main-repo.git/hooks/. The old path check silently no-op'd, so installing or uninstalling from inside a worktree did nothing.Use
git rev-parse --git-path hooksto resolve the right directory in both regular checkouts and worktrees, and to honorcore.hooksPathif set. Refactor: extractuninstall_hooks(project_dir)so cli.py shares the same resolver.The storage-key collision item from #48 is split into a follow-up issue (#52) since it touches 30+ call sites and needs a one-time migration.
Test plan
.git/hooks/fixture replaced with a realgit initrepo (the previous fixture silently masked the production path).git worktree add) pins both install and uninstall behavior from inside a worktree.gitbinary is unavailable.ruff check).Files
src/context_engine/indexer/git_hooks.py— new_resolve_hooks_dir()helper usinggit rev-parse --git-path hooks;install_hooksand newuninstall_hooksboth go through it.src/context_engine/cli.py—cce uninstallnow callsuninstall_hooksinstead of walking.git/hooks/inline.tests/indexer/test_git_hooks.py— real git-repo fixture, new worktree fixture, 5 new test cases covering worktree install/uninstall and content-based hook detection.