What happens
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.
What happens
A stray
cli/lefthook.ymlholding lefthook's commented example config (# EXAMPLE USAGE: ...) appears untracked in linked worktrees of this repository, and in the checkout a session works from.Why
GIT_DIRinto every hook. The main checkout gets onlyGIT_INDEX_FILE.cli/:cd cli && pnpm lint,pnpm test:arch,pnpm typecheck,pnpm --dir cli knip,pnpm --dir cli test. Whencli/node_modulesis missing or stale, pnpm 12 installs first, which runscli/package.json's"prepare": "lefthook install".GIT_DIRset and noGIT_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 installgivesAdded config: .../cli/lefthook.yml;GIT_DIR, no file;cd cli && pnpm lintin a linked worktree creates it.|| truedoes not prevent it, and a.gitignoreentry 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 theclipackage calls lefthook.