Skip to content

A hook in a worktree writes lefthook's example config into cli/ #860

Description

@blafourcade

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

  1. In a linked worktree, git exports GIT_DIR into every hook. The main checkout gets only GIT_INDEX_FILE.
  2. 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".
  3. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions