Open jclaveau opened 3 months ago
I am using version v9, how do I write the./.husky/link-submodules-hooks.sh file
Just create it and copy the following content as written above
#!/bin/bash # Create the symlinks .git/modules/<submodule_path>/hooks to .husky/<submodule_paths> git submodule foreach --quiet '\ cd $(git rev-parse --git-path hooks)/.. ;\ mv hooks hooks.bak || true ;\ mkdir -p ../../../../.husky/$path ;\ ln -s ../../../../.husky/$path hooks ;\ ' || true # No blocking if the .git folder is missing (like during deploy)
NB: Windows doesn't support symlinks for what I know, I personnaly use Linux
Then add the prepare line to your package Then run npm / yarn or pnpm install
Summary I see two use cases for submodules with Husky
Here I focus only on the first case
Context
Steps
hooksPath
of the root repo so Husky can't handle submodules hooks.As a workaround I created the script
.husky/link-submodules-hooks.sh
And run it from my
package.json
:Glad to it, I have folders in my
.husky
directory where i can store my hooks likeThis feature should belong, IMHO, to Husky. Meanwhile, this script may help other Husky users to achieve it!
This use case also answers your message, here https://github.com/typicode/husky/issues/1308#issuecomment-1762381639
Thanks a lot for sharing your work!