husky: Husky(v7) fails when .git/hooks directory is missing

Since v7 , I have an error on docker with node 14.17

yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@2.3.2: The platform "linux" is incompatible with this module.
info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
warning "@wdio/cucumber-framework > @cucumber/cucumber > @cucumber/html-formatter > @cucumber/react > react-markdown@5.0.3" has unmet peer dependency "@types/react@>=16".
[4/4] Building fresh packages...
$ husky install
husky - Git hooks failed to install
spawnSync git ENOENT
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error Command failed with exit code 1.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 19
  • Comments: 20 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve published v7.0.1. If git command is not found, husky should not fail anymore.

I’ve published v7.0.1. If git command is not found, husky should not fail anymore.

still getting the same issue with v7.0.1

I’m also seeing this in CI, but builds with Husky 6 seem to handle it gracefully? ↓

husky - not a Git repository, skipping hooks installation

Similar to others, but I’m seeing this error instead after upgrading to v7:

$ husky install
.git can't be found (see https://git.io/Jc3F9)

This is happening on our CI as well since not all our Docker images there have the .git directory. It would be great if husky’s installation steps could handle this gracefully and throw a warning instead instead of failing.

Hi team, this still fails for husky 7.0.4

For me the final solution was:

  • add .husky to .dockerignore
  • replace "prepare": "husky install" with "prepare": "[ -d '.husky' ] && (husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks) || true"
  • add to top of hook files
[ -n "$CI" ] && exit 0
. "$(dirname "$0")/_/husky.sh"