Skip to content

fix(hooks): resolve worktree-local lefthook instead of path-baking shim - #127

Merged
StephenTangCook merged 1 commit into
mainfrom
claude/determined-curran-1fe0f4
Jun 30, 2026
Merged

fix(hooks): resolve worktree-local lefthook instead of path-baking shim#127
StephenTangCook merged 1 commit into
mainfrom
claude/determined-curran-1fe0f4

Conversation

@StephenTangCook

Copy link
Copy Markdown
Contributor

Summary

Replace prepare: lefthook install with a small script that installs git hooks resolving each worktree's own node_modules/.bin/lefthook, so a normal git commit in a fresh worktree neither errors nor silently reverts uncommitted edits.

Why

lefthook install regenerates the shared .git/hooks shim with an absolute path baked to whichever worktree last installed. In a fresh worktree (no node_modules) that path is stale, so the shim falls through its resolution chain to mint run csjones/lefthook-plugin. That branch assumes Swift Mint, but on this machine mint is Mintlify's CLI — a name collision. It errors mid-run, and lefthook's stage_fixed stash can leave the working tree in the reverted state, silently destroying uncommitted edits. The only workaround had been git commit --no-verify.

Confirmed live during this work: the worktree whose path was baked got cleaned up mid-session, which is exactly the trigger.

A fresh worktree has no node_modules, so it fundamentally cannot run biome — any attempt risks the stash/revert. The fix makes that case a clean skip while keeping full enforcement everywhere deps are installed.

How it works

  • New scripts/install-hooks.mjs writes pre-commit / pre-push into the shared common hooks dir (the one lever every worktree's core.hooksPath points at). Each hook resolves the worktree-local lefthook and execs it, or prints a one-line "run pnpm install" notice and exits 0 when deps are absent — never touching mint, never stashing.
  • lefthook.yml stays the single source of truth for what runs.

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test

Manually verified:

  • Fresh worktree (no node_modules), globbed .json with staged + unstaged edits → commit succeeds, exits 0, unstaged edit survives, no stash entry, no mint invocation.
  • Installed worktree → biome runs; an unfixable lint error blocks the commit (exit 1). Checks are not weakened.
  • prepare wiring end-to-end: a real pnpm install ran the script and installed both pre-commit and pre-push. (This PR's own commit ran through the new hook cleanly.)

Notes for reviewer

  • scripts/ is not in package.json files, so it isn't shipped; registry installs don't run a dependency's prepare, so consumers are unaffected — same exposure as the old lefthook install.
  • The lefthook devDependency is retained; the hooks invoke its bin directly rather than relying on its generated shim.

lefthook install bakes an absolute node_modules path into the shared
.git/hooks shim. In a fresh worktree that path is stale, so the shim
falls through to `mint run csjones/lefthook-plugin` — which collides
with Mintlify's `mint` CLI, errors mid-run, and lets lefthook's
stage_fixed stash silently revert uncommitted edits.

Replace `prepare: lefthook install` with a script that writes hooks
resolving each worktree's own node_modules/.bin/lefthook, skipping
cleanly (exit 0, no stash, no mint) when deps aren't installed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
block-kitchen d8bc585 Commit Preview URL

Branch Preview URL
Jun 30 2026, 06:06 AM

@StephenTangCook
StephenTangCook merged commit 9797918 into main Jun 30, 2026
13 checks passed
@StephenTangCook
StephenTangCook deleted the claude/determined-curran-1fe0f4 branch June 30, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant