PR #355 fixed hook installation to use git rev-parse --git-path hooks, which correctly resolves core.hooksPath (e.g., Husky's .husky/_/). However, Husky regenerates .husky/_/ on every npm install (via the prepare script), so Entire's hooks get overwritten.
Goal: Detect when an external hook manager is in use, warn the user during entire enable, and provide copy-paste instructions for a durable integration.
New Files
cmd/entire/cli/strategy/hook_managers.go
Data model:
go
type HookManager struct {
Name string // "Husky", "Lefthook", "pre-commit", "Overcommit"
ConfigPath string // relative path that triggered detection (e.g., ".husky/")
OverwritesHooks bool // true if tool will overwrite Entire's hooks on reinstall
}
Builds warning text from buildHookSpecs(cmdPrefix) via an extractCommandLine() helper — this keeps the copy-paste instructions always in sync with actual hook content.
TestHookManagerWarning_Husky — verifies Husky warning includes all 4 hook commands
TestHookManagerWarning_GitHooksManager — verifies Category B message
TestExtractCommandLine — unit test for the helper
All tests use t.Parallel() + t.TempDir().
Modified Files
cmd/entire/cli/setup.go — 4 call sites
Add strategy.CheckAndWarnHookManagers(w) after each InstallGitHook() call:
Line 306 — runEnableWithStrategy()
Line 404 — runEnableInteractive()
Line 614 — setupAgentHooksNonInteractive()
Line 715 — setupGitHook() (uses os.Stderr since this function has no w param)
Pattern:
go
if _, err := strategy.InstallGitHook(true); err != nil {
return fmt.Errorf("failed to install git hooks: %w", err)
}
strategy.CheckAndWarnHookManagers(w) // NEW
The warning only prints during entire enable, never during EnsureSetup self-healing (which calls InstallGitHook(true) directly without CheckAndWarnHookManagers).
Warning Messages
Husky (overwrites hooks):
code
Warning: Husky detected (.husky/)
Husky may overwrite hooks installed by Entire on npm install.
To make Entire hooks permanent, add these lines to your Husky hook files:
.husky/prepare-commit-msg:
entire hooks git prepare-commit-msg "$1" "$2" 2>/dev/null || true
.husky/commit-msg:
entire hooks git commit-msg "$1" || exit 1
.husky/post-commit:
entire hooks git post-commit 2>/dev/null || true
.husky/pre-push:
entire hooks git pre-push "$1" || true
Category B tools (backup/chain works, but may need re-enable):
code
Note: Lefthook detected (lefthook.yml)
If Lefthook reinstalls hooks, run 'entire enable' to restore Entire's hooks.
Verification
mise run fmt && mise run lint && mise run test:ci
Manual test: create a temp repo with .husky/_/ dir, run entire enable, verify warning appears
Manual test: create a temp repo with lefthook.yml, verify note appears
Manual test: clean repo without hook managers, verify no warning
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /Users/robin/.REDACTED.jsonl
Assistant
I'll start by reading the key files I need to understand and modify.
Assistant
Now let me read the paths package to understand RepoRoot() and also look at the hooks test file for test patterns.
Assistant
Let me check the fileExists helper and the common.go file.
Assistant
Now I have everything I need. Let me implement the solution.
Assistant
Now create the test file.
Assistant
Now let me check how gitCommand is used in the test files (it's referenced in strategy tests).
Assistant
No gitCommand helper exists — the tests use exec.CommandContext directly. Let me fix my test file.
Assistant
I need to fix initGitRepo to use exec.CommandContext instead of gitCommand.
Assistant
Now remove the duplicate paths import since it's already imported at the top (but was also imported via the old initGitRepo that referenced it). Wait, let me check — the test file already imports paths via the new import block. But the TestCheckAndWarnHookManagers_* tests call CheckAndWarnHookManagers which internally uses paths.RepoRoot(). The initGitRepo helper also calls paths.ClearRepoRootCache(). So the import is correct.
Now let me modify setup.go to add the CheckAndWarnHookManagers calls at the 4 locations.
Assistant
Those are pre-existing diagnostics. Now let me update the second call site in runEnableInteractive.
Assistant
Now let me update the third call site in setupAgentHooksNonInteractive.
Assistant
Now the fourth call site in setupGitHook(). This function doesn't have a writer param, so I'll use os.Stderr.
Assistant
Now let me run the tests and linter to verify everything compiles and passes.
Assistant
Build succeeded. Now let me run the new tests.
Assistant
All 15 tests pass. Now let me run format, lint, and the full test suite.
Assistant
I need to fix the goconst lint issue. Let me extract "Lefthook" as a constant in the test file (or just use a variable).
Assistant
The simplest fix: use //nolint:goconst on the first occurrence, or better, just inline constants. Actually, the lint-clean approach is to add a nolint comment since these are test assertions with different contexts. But let me just add a simple nolint. Actually, looking at the pattern in the codebase, the cleanest fix is to just suppress it in the test.
Assistant
Lint passes. Now run the full test suite.
Assistant
All tests pass, including the new ones. Let me do a quick summary of the changes.
Summary
Created 2 new files and modified 1 existing file:
New: cmd/entire/cli/strategy/hook_managers.go
HookManager struct — holds name, config path, and whether the tool overwrites hooks
DetectHookManagers(repoRoot) — filesystem-only detection (os.Stat) for Husky v9+, Lefthook, pre-commit, and Overcommit. Deduplicates managers (e.g., lefthook.yml + .lefthook.yml).
HookManagerWarning(managers, cmdPrefix) — generates warning text. For tools that overwrite hooks (Husky), shows copy-paste instructions extracted from buildHookSpecs() via extractCommandLine() to stay in sync with actual hook content. For other tools, shows a simpler "re-run entire enable" note.
extractCommandLine(hookContent) — returns the first non-shebang, non-comment line from a hook script
CheckAndWarnHookManagers(w) — public entry point called from setup.go; resolves repo root, detects managers, and writes warning
I'll update the detection to cover all Lefthook config patterns.
Assistant
Now update the tests — update the TestDetectHookManagers_LefthookDotPrefix to also test a yaml variant, and add a test for a -local variant.
Assistant
Lint passes (the nolint comments were removed by the linter since goconst didn't trigger — that's fine). Now run tests.
Assistant
All 31 tests pass (including all 15 Lefthook variant subtests). Let me amend the commit.
Assistant
All passing. Now amend the commit.
Assistant
Done. Commit amended on feat/detect-hook-managers with all 16 Lefthook config patterns listed explicitly.
User
why is HookManager and DetectHookManagers exported (capitalized)?
Assistant
Good catch — nothing outside the strategy package calls them. CheckAndWarnHookManagers is the only public entry point (called from setup.go in the cli package). The struct and detection function can be unexported.
Assistant
Only used within the strategy package (and its tests) plus setup.go which only calls CheckAndWarnHookManagers. Let me also check if HookManagerWarning is used outside.
Assistant
HookManagerWarning is also only used within the package. I'll unexport all three — HookManager, DetectHookManagers, and HookManagerWarning.
Assistant
Now update all references throughout the file.
Assistant
Now update the struct literal field names in the hookManager{} construction.
Assistant
Now rename the exported functions to unexported.
Assistant
Now update the test file references.
Assistant
Now bulk-update the test file — replace exported names with unexported ones.
Assistant
Now update the field access patterns in test assertions.
Assistant
Now verify it all compiles and passes.
Assistant
Two issues: test function names can't start with Testd or Testh (lowercase after Test), and CheckAndWarnHookManagers can't return an unexported type. The return value isn't used by callers anyway — let me just drop it.
Assistant
Now fix the return type of CheckAndWarnHookManagers — callers don't use the return value.
Assistant
The tests do use the return value. I'll drop the return type from the exported function and adjust the tests to call detectHookManagers directly for assertions.
Assistant
Now update the two tests that used the return value.
Assistant
All passing. Let me amend the commit.
Assistant
Done. hookManager, detectHookManagers, and hookManagerWarning are now unexported. Only CheckAndWarnHookManagers remains exported (needed by the cli package in setup.go), and its return type is now void.
User
efthook is the most flexible in terms of config file naming. During installation, Lefthook looks for a configuration file using the pattern {.,}lefthook.{yml,yaml,json,toml} DeepWiki. So all valid main config files are:
There's a typo on line 34 — .pre-commit-config.yam/l instead of .pre-commit-config.yaml. Let me fix that along with the Lefthook expansion.
Assistant
Now update the test for the .lefthook.yml dot-prefix case — it should still work since that filename is still generated. Let me also add a test for a .toml variant to cover the new extensions.
Assistant
The existing tests still cover the right cases. Let me add a test for a .toml variant to verify the new extensions work.
Assistant
All green. Let me amend the commit with these changes.
Assistant
Done. Expanded Lefthook detection to cover all 16 valid config filenames ({.,}lefthook{,-local}.{yml,yaml,json,toml}), fixed a typo in the pre-commit path, and added tests for .toml and -local variants. All tests and lint pass.
User
let make HookManager and DetectHookManagers local (not captialised)
Assistant
These are all within the strategy package (same package), so making them unexported is safe. Let me do the renames.
Assistant
The hookManager rename already caught HookManagerWarning → hookManagerWarning. Let me check what's left.
Assistant
The replace_all on HookManager also caught DetectHookManagers → DetecthookManagers. That's wrong — it should be detectHookManagers. Let me fix that.
Assistant
Also fix the warning function name — it became hookManagerWarning which is correct. And CheckAndWarnhookManagers needs fixing too.
Assistant
Good — CheckAndWarnHookManagers stays exported since it's called from setup.go. Now update the test file.
Assistant
Now fix HookManagerWarning → check what happened in tests.
Assistant
The test function names like TesthookManagerWarning_Husky are invalid — Go test functions must start with Test followed by an uppercase letter. Let me fix these.
Assistant
Same issue with TestDetect — check for those.
Assistant
Need to fix all the mangled test names.
Assistant
Now verify everything looks right and builds.
Assistant
The function calls in the test file still have detecthookManagers (lowercase h in hook) instead of detectHookManagers. The DetectHookManagers → detectHookManagers rename in the test only fixed the test function names, not the actual function calls because those went through the HookManager → hookManager replace first.
Assistant
Exported function returning unexported type. Since the return value isn't used by setup.go, I'll change it to not return anything.
Assistant
Now update the test to not capture the return value.
Assistant
All green — lint clean, all tests pass. Let me amend the commit.
Assistant
Done. hookManager and detectHookManagers are now unexported. CheckAndWarnHookManagers stays exported (called from setup.go) and no longer returns a value to avoid the unexported-return lint error.
User
/reviewer
Assistant
Review Summary
APPROVE with one important finding and a few minor suggestions:
Important: Husky v9 detection
The detection checks for .husky/_/ which is Husky v5-v8. Husky v9+ places hooks directly in .husky/ without the _ subdirectory. Should we update to detect .husky/ instead?
Minor suggestions
Move buildHookSpecs call inside the OverwritesHooks branch (avoids allocation when not needed)
Consider reusing existing initTestRepo helper instead of the new initGitRepo
Want me to apply the Husky v9 fix and the minor suggestions?
User
create a PR
Assistant
Branch is already pushed and up to date. Let me check for a PR template.
initGitRepo duplicates the existing initHooksTestRepo helper in hooks_test.go (both run git init, t.Chdir, and clear the RepoRoot cache). Reusing the shared helper would reduce duplication and keep repo setup logic consistent across tests.
Assistant
initHooksTestRepo already does t.TempDir(), t.Chdir(), git init, and ClearRepoRootCache() — and returns tmpDir. I can replace the custom initGitRepo calls with it and drop the helper entirely.
Assistant
Now remove the unused imports (context, exec, paths).
Assistant
All green. Let me amend and push.
User
[Request interrupted by user for tool use]
User
should the tests in cmd/entire/cli/strategy/hook_managers_test.go use t.Parallel()?
Assistant
The pure unit tests (TestDetectHookManagers_*, TestHookManagerWarning_*, TestExtractCommandLine) already do — that's correct.
The two TestCheckAndWarnHookManagers_* tests correctly don't — they call initHooksTestRepo which uses t.Chdir(), and per CLAUDE.md Go will panic if t.Chdir() is used after t.Parallel(). The comments already explain this.
So the current state is correct as-is.
User
push it
Assistant
Stale tracking info. Let me fetch first and retry.
User
[Request interrupted by user for tool use]
User
pull and merge the changes from the remote
Assistant
Remote has a merge commit bringing in main. Let me rebase our local amended commit on top.
Assistant
Our local version (after =======) is the correct one in all cases — it removes initGitRepo and uses initHooksTestRepo instead, with fewer imports. Let me resolve all conflicts with our version.
User
[Request interrupted by user for tool use]
User
git push
Assistant
Pushed successfully.
User
cmdPrefix selection logic is duplicated here and in hooks.go (both branch on isLocalDev() to pick either entire or go run ...). Consider extracting a small helper (e.g. hookCmdPrefix() / commandPrefix()) to avoid future drift where hook contents and warning instructions could disagree.
Assistant
Good catch. Let me find the duplication in hooks.go and extract a shared helper.
Assistant
I'll add a hookCmdPrefix() helper next to isLocalDev() in hooks.go and use it in both places.