Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How to make Husky run git hook?
How to make Husky run git hook? I have a working git hook, prepare-commit-message, but the moment Husky was installed, the hook stopped working.
Not finding much luck, I then tried to make it a "Husky git hook" and run it like that, so I installed it via npx husky add prepare-commit-message content
, but this did not help.
Summary of the situation:
- git hook on it's own - works
- two other husky git hooks - work on their own (pre-commit, pre-push)
-
git config -e
and hooksPath set as.husky
- my script as a husky hook, installed like above - makes commit-related two Husky hooks no longer work.
git commit
never happens, instead pre-commit hook fails with a message that
.husky/pre-commit: 2: .: cannot open .husky/husky.sh: No such file
or, if I move pre-commit
one out:
.husky/prepare-commit-msg: 8: .: cannot open .husky/_/husky.sh: No such file
However, interestingly, if I REMOVE the config bit about .husky
dir, git commit
opens normally, but without what I'd expect from prepare-commit-message
.
At this point I'm kind of stumped, so any help is welcome.
1 answer
Breakthrough, I found it, mere minutes after posting here. A workaround more than an answer, but it gets the script working.
- Reading up on
husky.sh
I decided that I don't have it and I don't want it (need to push the work forward). How did this work before though? Why could I push, commit, see Husky's messages? - So, I have a workaround! A) Comment out the line
. "$(dirname -- "$0")/_/husky.sh"
. B) Add the same script to.git/hooks
.
Made it run now with those two steps. And I'm now thinking that perhaps I botched Husky install somehow. Will probably reinstall and see then, but for now, have spent already hours on it, so need to do something. :-)
I'm still looking for better answers, or comments.
0 comment threads