typicode / husky

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

Inquiry about Husky's Choice of Git Hook Configuration Method #1410

Closed yufeikang closed 1 month ago

yufeikang commented 1 month ago

Troubleshoot

Context I'm reaching out to inquire about the current design choice in Husky where it configures the core.hooksPath to point to a project-specific directory (e.g., .husky) for Git hooks, rather than directly placing hook files into the project's .git/hooks directory. This approach seems to override the ability for global hooks set through a user's global core.hooksPath configuration to be executed.

In my workflow, I have global hooks that I use across multiple projects for personal utilities and checks. However, I noticed that when a project utilizes Husky, my global hooks no longer execute due to Husky's redirection of the core.hooksPath.

Questions and Concerns:

  1. Design Rationale: Could you please elaborate on the reasoning behind choosing to modify the core.hooksPath over directly writing to the project's .git/hooks directory? I'm interested in understanding the benefits or constraints that led to this decision.

  2. Global Hooks Compatibility: Is there a recommended approach or best practice for maintaining the functionality of global Git hooks alongside Husky-managed project hooks? Any advice on how to configure my environment to allow both project-specific hooks managed by Husky and my global hooks to coexist and work properly would be greatly appreciated.

  3. Possible Enhancements: Are there plans to address this compatibility issue in future releases, or could there be potential features added to Husky that would allow better interoperability with global Git hooks?

Technical Details:

Thank you for your time and assistance. Husky has been a valuable tool for automating and enforcing project-specific hooks, and I'm looking forward to finding a solution that accommodates both project and global hook needs.

typicode commented 1 month ago

Sorry, I may not have time to go into 1 except that to me, it's the modern approach to sharing hooks and simpler.

As for 2, you can disable husky installation by setting HUSKY=0 which would prevent core.hooksPath to be changed. Another approach is to have global code run in ~/.config/husky/init.sh. This way, you can have global then local code run.