You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A hook in a worktree writes lefthook's example config into cli/ #860
A stray cli/lefthook.yml holding lefthook's commented example config (# EXAMPLE USAGE: ...) appears untracked in linked worktrees of this repository, and in the checkout a session works from.
Why
In a linked worktree, git exports GIT_DIR into every hook. The main checkout gets only GIT_INDEX_FILE.
A pre-commit or pre-push job runs pnpm inside cli/: cd cli && pnpm lint, pnpm test:arch, pnpm typecheck, pnpm --dir cli knip, pnpm --dir cli test. When cli/node_modules is missing or stale, pnpm 12 installs first, which runs cli/package.json's "prepare": "lefthook install".
With GIT_DIR set and no GIT_WORK_TREE, git takes the current directory, cli/, as the work tree root. lefthook finds no config there, writes its example, and installs hooks into the hooks directory every worktree shares.
Reproduced in throwaway repos with lefthook 2.1.12 and pnpm 12.3.4:
cd cli && GIT_DIR=<root>/.git lefthook install gives Added config: .../cli/lefthook.yml;
without GIT_DIR, no file;
a pre-commit job cd cli && pnpm lint in a linked worktree creates it.
|| true does not prevent it, and a .gitignore entry would only hide the file while the shared hooks keep being reinstalled.
Expected
Hooks are installed from the repository root only, by the root prepare. No script of the cli package calls lefthook.
Activity
fix(cli): install git hooks from the repository root only (#861)