Skip to content

fix(hooks): install Entire into husky user hooks#1778

Open
suhaanthayyil wants to merge 1 commit into
mainfrom
fix/784-husky-mid-turn-trailer
Open

fix(hooks): install Entire into husky user hooks#1778
suhaanthayyil wants to merge 1 commit into
mainfrom
fix/784-husky-mid-turn-trailer

Conversation

@suhaanthayyil

@suhaanthayyil suhaanthayyil commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Trail: https://entire.io/gh/entireio/cli/trails/876

https://entire.io/gh/entireio/cli/trails/876

What: Install Entire git hooks into husky's user-hook directory (parent of core.hooksPath=.husky/_) instead of into regenerable .husky/_.

Why / how it helps: npm install / husky prepare rewrites .husky/_ mid-turn and previously removed Entire's wrappers, so later commits in the same turn silently lost Entire-Checkpoint trailers (Fixes #784). User hooks under .husky/ survive prepare, so mid-turn commits keep trailers without per-tool-hook recovery.

How:

  • When core.hooksPath is a husky _ dir with the h dispatcher, write managed hooks to the parent user-hook dir and leave _ stubs alone
  • Migrate legacy Entire wrappers out of _ (restore .pre-entire or write forwarding stubs)
  • IsGitHookInstalled requires forwarding stubs so EnsureSetup can heal a broken husky layout
  • Advisory Note when husky-safe path is active; Warning otherwise

Testing / verification:

  • Live repro on macOS: commit1 trailer → npx husky → commit2 trailer (same turn)
  • Mutation: disabling hookInstallDir husky redirect fails unit + integration tests
  • go test ./cmd/entire/cli/strategy/ green (806)
  • go test -tags=integration ./cmd/entire/cli/integration_test/ -run TestHusky_MidTurnPrepare|TestHookOverwrite_MidTurn green
  • mise run fmt + mise run lint 0 issues on committed tree
  • Audit: two consecutive clean passes after fixes

Made with Cursor

Husky regenerates .husky/_ on npm prepare, which previously clobbered
Entire's wrappers mid-turn so later commits lost Entire-Checkpoint
trailers. Install into the parent .husky/ user-hook directory that
husky's stubs invoke, so mid-turn commits keep trailers after prepare.

Fixes #784
Copilot AI review requested due to automatic review settings July 16, 2026 15:17
@suhaanthayyil
suhaanthayyil requested a review from a team as a code owner July 16, 2026 15:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Entire’s git-hook installation logic to be Husky v9–safe by installing managed hooks into Husky’s user hook directory (the parent of core.hooksPath=.husky/_) so Husky/npm prepare regenerations of .husky/_ don’t clobber Entire’s wrappers mid-session (fixing the multi-commit trailer loss described in #784).

Changes:

  • Detect Husky v9’s core.hooksPath shape (.../_ with dispatcher _/h) and install Entire-managed hooks into the parent user-hook directory.
  • Migrate legacy Entire wrappers out of the regenerable Husky-owned _ directory, restoring backups or writing Husky forwarding stubs as needed.
  • Update hook-manager warnings to emit a Husky-specific advisory note when the Husky-safe install path is active, and add unit + integration coverage for the mid-turn “husky prepare” scenario.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/entire/cli/strategy/hooks.go Adds Husky-safe install directory selection, legacy migration/cleanup, and updated installation/removal detection logic.
cmd/entire/cli/strategy/hooks_test.go Updates/extends unit tests for Husky install behavior, migration, and stubs surviving simulated prepare.
cmd/entire/cli/strategy/hook_managers.go Adjusts Husky warning output to a Note when hooks are installed in the Husky-safe user-hook dir.
cmd/entire/cli/strategy/hook_managers_test.go Updates tests for the new Husky-safe Note vs Warning behavior and hooksPath detection.
cmd/entire/cli/integration_test/hook_overwrite_husky_test.go Adds an integration test reproducing the mid-turn Husky regenerate case and asserting trailers persist across commits.

Comment on lines +212 to 225
// huskyForwardingStubsPresent reports whether each managed hook has a
// non-Entire stub in the husky-owned hooks directory (so git → `_` → parent).
func huskyForwardingStubsPresent(hooksDir string) bool {
for _, hook := range gitHookNames {
data, err := os.ReadFile(filepath.Join(hooksDir, hook)) //nolint:gosec // path from constants
if err != nil {
return false
}
if strings.Contains(string(data), entireHookMarker) {
return false
}
}
return true
}
Comment on lines +426 to +428
if installDir != hooksDir {
fmt.Println(" Installed into .husky/ (survives husky/npm prepare)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Only first commit per session gets Entire-Checkpoint trailer; subsequent commits silently skipped

2 participants