typicode / husky

Git hooks made easy 🐶 woof!
https://typicode.github.io/husky
MIT License
31.68k stars 996 forks source link

Support for Projects with .git Directory in a Nested Parent Directory #1399

Open ShanteshSindgi opened 2 months ago

ShanteshSindgi commented 2 months ago

I have a project structure where the .git directory is located three levels up from the root directory where Husky is installed. The current setup requires manual navigation to the .git directory (cd ../../../) before running husky install to ensure Husky hooks are correctly set up. Additionally, for the hooks themselves (e.g., pre-commit), there is a need to navigate back to the nested project directory, complicating the script and making it error-prone.

Current Workaround: In the prepare script in package.json, I've included a command to navigate to the .git directory (cd ../../../) and then run husky install. Similarly, in the Husky hook scripts (e.g., .husky/pre-commit), I find myself needing to include commands to navigate back to the project directory where the actual code and scripts reside.

Desired Solution: I'm looking for a solution or configuration option in Husky that allows it to automatically detect the location of the .git directory without requiring manual directory navigation commands in the setup and hook scripts. This would streamline the process and reduce the potential for errors, especially in complex project structures.

Questions: Is there an existing configuration option in Husky to handle this scenario? If not, could a feature be considered for future releases to support automatic detection of .git directory locations, especially when they are not in the root directory of the project where Husky is installed? Are there recommended practices for handling such project structures with Husky that I might have overlooked? Thank you for considering this issue. Any guidance or suggestions on how to better handle this setup with Husky would be greatly appreciated.

pzrq commented 2 weeks ago

I'm still investigating my own issue with prettier precommit which may be different to the others who have upvoted this, though I found Husky does support "Project Not in Git Root Directory" which looks like this scenario, so may help others: https://typicode.github.io/husky/how-to.html#project-not-in-git-root-directory

EDIT: It's turned out that https://typicode.github.io/husky/how-to.html#project-not-in-git-root-directory was exactly my problem, so mine at least is resolved ❤️