Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Husky(v7) fails when .git/hooks directory is missing #1003

Closed
lacell75 opened this issue Jul 2, 2021 · 20 comments
Closed

Husky(v7) fails when .git/hooks directory is missing #1003

lacell75 opened this issue Jul 2, 2021 · 20 comments
Labels

Comments

@lacell75
Copy link

lacell75 commented Jul 2, 2021

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.
@jrolfs
Copy link

jrolfs commented Jul 3, 2021

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

@EvHaus
Copy link

EvHaus commented Jul 5, 2021

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.

@Heatmanofurioso
Copy link

Heatmanofurioso commented Jul 5, 2021

Exactly the same thing as @EvHaus happening on our projects.
Both on React and Angular-based projects

@ranisalt
Copy link

ranisalt commented Jul 5, 2021

Alternatively, CI services set CI=true that can be checked to just skip installing the hooks in CI servers.

@andorfermichael
Copy link

andorfermichael commented Jul 6, 2021

This already happened for me in v6.

There is the section Disable Husky in CI/Docker. However, this didn't work because CI variable is not set when building in Docker for multi-stage.

The only thing that worked is the following solution #867 (comment) which implies moving the husky install from prepare to postinstall.

but it does not work for all cases only on master

@andorfermichael
Copy link

andorfermichael commented Jul 6, 2021

My pipeline fails because my hooks are running on CI although they should not. Even though I've added .husky to .dockerignore.

�[0KRunning with gitlab-runner 14.0.1 (c1edb478)
�[0;m�[0K  on app2 docker Hx9-RqLc
�[0;msection_start:1625563179:resolve_secrets
�[0K�[0K�[36;1mResolving secrets�[0;m
�[0;msection_end:1625563179:resolve_secrets
�[0Ksection_start:1625563179:prepare_executor
�[0K�[0K�[36;1mPreparing the "docker" executor�[0;m
�[0;m�[0KUsing Docker executor with image registry.company.com/company/gitlab-company-runner:latest ...
�[0;m�[0KAuthenticating with credentials from job payload (GitLab Registry)
�[0;m�[0KPulling docker image registry.company.com/company/gitlab-company-runner:latest ...
�[0;m�[0KUsing docker image sha256:1713559830d18d7626d9d982b302266f213d960dd3b6d77bc1bd0ff9deb3224b for registry.company.com/company/gitlab-company-runner:latest with digest registry.company.com/company/gitlab-company-runner@sha256:12605ee264a2ba161af76662e066076ea7f2782538ce3879de5624c195ebc0bf ...
�[0;msection_end:1625563181:prepare_executor
�[0Ksection_start:1625563181:prepare_script
�[0K�[0K�[36;1mPreparing environment�[0;m
�[0;mRunning on runner-hx9-rqlc-project-73-concurrent-0 via app2.company.com...
section_end:1625563182:prepare_script
�[0Ksection_start:1625563182:get_sources
�[0K�[0K�[36;1mGetting source from Git repository�[0;m
�[0;m�[32;1mFetching changes with git depth set to 50...�[0;m
Reinitialized existing Git repository in /builds/company/company-nuxt/.git/
�[32;1mChecking out 1bd1bd21 as refs/merge-requests/301/head...�[0;m
.husky/post-checkout: line 4: yarn: not found
husky - post-checkout hook exited with code 127 (error)
section_end:1625563184:get_sources
�[0Ksection_start:1625563184:cleanup_file_variables
�[0K�[0K�[36;1mCleaning up file based variables�[0;m
�[0;msection_end:1625563185:cleanup_file_variables
�[0K�[31;1mERROR: Job failed: exit code 1
�[0;m

@typicode
Copy link
Owner

typicode commented Jul 6, 2021

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

@typicode
Copy link
Owner

typicode commented Jul 6, 2021

I've also updated docs with more options for CI/Docker
https://typicode.github.io/husky/#/?id=disable-husky-in-cidocker

@typicode typicode closed this as completed Jul 6, 2021
@typicode typicode reopened this Jul 6, 2021
@lacell75
Copy link
Author

lacell75 commented Jul 6, 2021

Thanks that works now.

@lacell75
Copy link
Author

lacell75 commented Jul 6, 2021

I've also updated docs with more options for CI/Docker
https://typicode.github.io/husky/#/?id=disable-husky-in-cidocker

I used HUSKY: 0 in your CI config file in my CI gitlab config file but with v7.0.0 the husky install was enable .

@andorfermichael
Copy link

andorfermichael commented Jul 6, 2021

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"

@deepakthankachan
Copy link

deepakthankachan commented Jul 27, 2021

@typicode still getting the same issue with npm 7 (npm 6 is fine)

@Heatmanofurioso
Copy link

Heatmanofurioso commented Jul 28, 2021

Issue's been fixed for me. Using npm 7.20.1

aziiee pushed a commit to aziiee/ember-uikit that referenced this issue Jul 29, 2021
This fixes the following issue:
typicode/husky#1003
@prebra
Copy link

prebra commented Jul 30, 2021

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

aziiee added a commit to adfinis/ember-uikit that referenced this issue Aug 3, 2021
This fixes the following issue:
typicode/husky#1003

Co-authored-by: Akanksh Saxena <akanksh.saxena@adfinis.com>
nhall97 added a commit to nhall97/sfdx-monorepo-npm-workspace that referenced this issue Aug 3, 2021
@stale
Copy link

stale bot commented Sep 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 28, 2021
@stale stale bot closed this as completed Oct 5, 2021
@surfer19
Copy link

surfer19 commented Nov 11, 2021

Still same issue for "husky": "^7.0.2",

@sfc-gh-nlele
Copy link

sfc-gh-nlele commented Nov 30, 2021

Hi team, this still fails for husky 7.0.4

@simonmaass
Copy link

simonmaass commented Feb 16, 2022

i have the same issue in 7.0.4 - is there any update on how people have solved this?

@TimRudy
Copy link

TimRudy commented Apr 8, 2022

Same, with version 7.0.4 - fixed, but not fixed?
Using:
npm 6.14.11
node 14.15.5

@linong1526
Copy link

linong1526 commented Jul 21, 2022

It is really too bad.
Now ,2022/07/21,not fixed ???
Using:
nvm 1.1.9
Node v16.13.0
npm 8.1.0

> husky install
.git can't be found (see https://git.io/Jc3F9)
npm ERR! code 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests