Skip to content

prepare skips husky install in git worktrees, so every commit fails #150

Description

@tomcasaburi

Problem

The prepare script is test -d .git && husky install || true. In a linked git worktree, .git is a file rather than a directory, so husky install is skipped and .husky/_/husky.sh is never created. core.hooksPath=.husky lives in the shared repo config, so the hooks still run, and every commit then fails:

.husky/commit-msg: line 2: .husky/_/husky.sh: No such file or directory

Reproduction: git worktree add ../wt origin/master && cd ../wt && npm ci && git commit --allow-empty -m "test: x"

Plan

  1. Change the guard to test -e .git. husky 8 itself only checks that .git exists (fs.existsSync('.git')), so it supports worktrees once it is invoked.
  2. Add a test that runs the prepare script in a temporary linked worktree and in a normal checkout, and asserts that .husky/_/husky.sh exists in both.
  3. npm run build && npm run build:test, npm run test:cli
  4. Open a PR with Closes #N

Docker builds are unaffected: .git is in .dockerignore, and the Dockerfile installs with --ignore-scripts.

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions