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

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

Open
ShanteshSindgi opened this issue Mar 3, 2024 · 1 comment

Comments

@ShanteshSindgi
Copy link

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
Copy link

pzrq commented May 2, 2024

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 ❤️

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

No branches or pull requests

2 participants