Skip to content

'husky install' fails if '.git' directory does not exists #1084

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

Closed
BricePissard opened this issue Dec 16, 2021 · 6 comments
Closed

'husky install' fails if '.git' directory does not exists #1084

BricePissard opened this issue Dec 16, 2021 · 6 comments
Labels

Comments

@BricePissard
Copy link

If you have a large project, we can't install Husky anymore. Only small projects can install it now...

in a repo:

  • myRepo/.git
    -- ./myRepo/back/package.json
    -- ./myRepo/front/package.json
cd ./myRepo/back
yarn add husky -D
npx husky install

throw new Error(".git can't be found");

The bug still exists in 7.0.4, (#851) could you please place a recursive test to check if the .git folder exists in the parent, then parent's parent, then parent's parent's parent... folder.

In the real world, it happens that the GIT is a mono-repo that contains differents folders with different projects with a package.json in each.

@mateuszklinowski
Copy link

mateuszklinowski commented Dec 17, 2021

Hello!

Does the custom directory section of documentation match your problem?
https://typicode.github.io/husky/#/?id=custom-directory

@thany
Copy link

thany commented Jan 4, 2022

I ran into this as well, and I was baffled to why this requires a custom directory config. This my case, and in BricePissard's case, the .git directory is not in a custom location, but rather in a perfectly reasonable and default location. It's completely normal for the .git directory to be one or more levels up.

Looking for it should be (and can be!) fully automated. In the same way that any git * command works anywhere in the dorectory structure, as long as somehwere in a parent or ancestor folder the .git directory can be found, indicating the presence of a git project.

@typicode
Copy link
Owner

It's on purpose because of two issues that happened:

  1. Imagine you have a Python project and download a JS Open Source project as zip or tar. You proceed to run npm install, if husky recursively checks for .git then it can create issues with existing git hooks.
  2. Some users also go to node_modules/some_project and run npm install inside them to quickly try things.

Also some users believe that package.json dependencies should not go below package.json root directory.

I understand it can be annoying and there's no universal solution. However the choice was made with husky 7 to lean on the side of safety and being more explicit where hooks should be installed by not allowing .. in the install path.

That said as @mateuszklinowski mentioned, you can cd .. && husky project/.husky. There's also a section for monorepos.

Hope it helps and clarifies the reasoning behind it :)

@stale
Copy link

stale bot commented Apr 19, 2022

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 Apr 19, 2022
@stale stale bot closed this as completed Apr 27, 2022
@mario-d-s
Copy link

@typicode wouldn't it be more convenient to have a flag for husky install that explicitly allows it to search for the .git directory upwards recursively? This would already be much more convenient than having to cd ../../.. to the correct level.

In my case it's even harder cause I'm integrating Husky as part of a project template, where the template cannot know where the .git directory will eventually be - it's supposed to be some levels up, but how many levels is not known beforehand.

@David245M
Copy link

David245M commented May 29, 2023

@mateuszklinowski The link is not leading anywhere, could you update it? I believe this is the right one https://typicode.github.io/husky/guide.html#custom-directory

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

6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy