Implement the following plan: Husky v9 Hook Compatibility Context PR #355 fixed hook…
- User
Implement the following plan:
Husky v9 Hook Compatibility
Context
PR #355 fixed hook installation to use
git rev-parse --git-path hooks, which correctly resolvescore.hooksPath. When Husky is present, this resolves to.husky/_/. However, Husky regenerates.husky/_/on everynpm install(viaprepare: "husky"in package.json), wiping Entire's hooks.The fix: When Husky is detected, inject Entire's commands into the user-facing
.husky/<hookname>files instead of writing standalone hooks into.husky/_/. User-facing files are committed to the repo and survivenpm install.Closes #228.
How Husky v9 Works
code.husky/ ├── _/ ← generated wrappers (gitignored, regenerated on npm install) │ core.hooksPath points here ├── pre-commit ← user-editable, committed, survives npm install ├── prepare-commit-msg ← user-editable, committed, survives npm install └── ...Git calls
.husky/_/<hook>(wrapper) which delegates to.husky/<hook>(user script).Changes
Single file modified:
cmd/entire/cli/strategy/hooks.goSingle test file modified:cmd/entire/cli/strategy/hooks_test.go1. Husky Detection
Add helpers to detect if
core.hooksPathresolves to a Husky-managed directory:isHuskyHooksPath(hooksDir string) bool— checks if path ends in.husky/_getHuskyUserHooksDir(hooksDir string) string— returns.husky/parent dir (or empty)
Detection: path pattern match (
.husky/_) + verify.husky/directory exists on disk.2. Injection Content
Add
buildHuskyInjectionSpecs(cmdPrefix)returning hook commands wrapped in markers:sh# BEGIN entire # Entire CLI hooks entire hooks git prepare-commit-msg "$1" "$2" 2>/dev/null || true # END entire Assistant
Let me also check for the
fileExistshelper and see the existing test forTestInstallGitHook_CoreHooksPathRelativemore carefully since it already tests with.husky/_but without actual Husky detection.Assistant
Now let me create the task list and start implementing.
Assistant
Let me start implementing. First, I'll add all the Husky detection helpers, markers, and block manipulation functions to
hooks.go.Assistant
Now let me add the Husky detection helpers, block manipulation helpers, and the Husky injection specs. I'll add them after the
generateChainedContentfunction and beforeisLocalDev.Assistant
Now let me modify
InstallGitHook()to branch on Husky detection:Assistant
Now modify
isGitHookInstalledInHooksDirto check Husky user hooks when Husky is detected:Assistant
Now modify
RemoveGitHookto handle Husky:Assistant
Now let me verify the final state of hooks.go before writing tests:
Assistant
Good, the implementation looks clean. Now let me add the Husky-specific tests and update the existing tests. Let me first understand what needs to change in the existing tests:
TestInstallGitHook_CoreHooksPathRelativeand both set to , which will now trigger Husky detection. Since they don't create a directory on disk, will return empty (because check fails), so the fallback to standard install should happen. Wait, actually — the test creates via (which does). But checks if exists. Let me trace through:Assistant
Now I need a helper that sets up a Husky-style repo. Let me add it and the tests at the end of the file.
Assistant
Assistant
Now add the
hasHuskyInjectedHookshelper:Assistant
Similarly, I should apply the same logic to
isGitHookInstalledInHooksDir— if Husky is detected but no blocks are found in user hooks, we should check the standard location. Actually wait, the currentisGitHookInstalledInHooksDirlogic already returnsfalseif it doesn't find blocks in user hooks. The issue is it doesn't then fall through to check.husky/_/for standalone hooks. Let me fix that too:Assistant
Now the existing tests should work correctly. Let me verify the tests pass.
Assistant
Let me first run the hooks-specific tests to catch any issues quickly:
Assistant
All Husky-specific tests pass. Now let me run the existing hooks tests to make sure they still pass:
Assistant
All existing tests pass. Now let me run the full suite:
Assistant
There's a lint error — I have an unchecked error return. Let me fix it:
Assistant
Lint passes. Now run all tests:
Assistant
All tests pass including integration tests. Let me mark the task as complete.
Assistant
All done. Here's a summary of what was implemented:
Files modified:
cmd/entire/cli/strategy/hooks.go— Husky v9 compatibilitycmd/entire/cli/strategy/hooks_test.go— 11 new test cases
Key changes in
hooks.go:- Husky detection —
isHuskyHooksPath()detects.husky/_path pattern;getHuskyUserHooksDir()returns the.husky/parent if it exists on disk - Block injection —
buildHuskyInjectionSpecs()generates hook commands wrapped in# BEGIN entire/# END entiremarkers (no shebang needed for Husky user scripts) - Block manipulation helpers —
extractEntireBlock(),replaceEntireBlock(),buildEntireBlock(),injectHuskyHookContent(),removeEntireBlock() - — branches to when Husky detected, which injects blocks into and cleans up stale standalone hooks in
Assistant
That task failure is unrelated to our work — it was a stale background agent that errored out. The implementation is complete and all tests pass.
- User
commit and push this, and raise a draft PR