husky icon indicating copy to clipboard operation
husky copied to clipboard

Husky not running when .git is in another directory

Open cmaciasjimenez opened this issue 1 year ago • 2 comments

Hi! I'm trying to use Husky v9 in a folder that has the .git folder in the parent folder. There is a specific section in the Husky website about this but I can't get it to work for some reason.

My folder structure is as follows

.
├── .git/
└── docs/ # package.json with husky

I've installed husky v9 in /docs and tried to run npx husky init which added the preparescript to the package.json but returned ".git can't be found". I went and did the changes specified in the website, but when I try to commit something to do the npm test, the commit goes through without husky running.

I don't know if maybe the guide isn't updated for v9 or am I installing it wrong or doing something in a different order as it should be.

Any help?

Thank you

cmaciasjimenez avatar May 08 '24 15:05 cmaciasjimenez

I have the same issue

PiotrPulsate avatar May 17 '24 14:05 PiotrPulsate

Same here it is nightmare to set it up. Managed to set it up like "prepare": "cd ../ && husky subproject/.husky" but it fails to run any hook as for example npm run lint from subproject/package.json

127 avatar May 23 '24 10:05 127

since the binary itself is located at docs/node_modules, I don't think that this is something that Husky can resolve. I'd say this is a limitation.

You can solve this if your git repo was supposed to be using Husky globally

micalevisk avatar Jul 03 '24 18:07 micalevisk

This should probably help https://typicode.github.io/husky/how-to.html#project-not-in-git-root-directory

typicode avatar Jul 12 '24 13:07 typicode