Husky is a tool which enables you to create git hooks easy.
With a hook you could for example make code linting and code formatting mandatory on the developers machine instead of doing that on the CI service.
I found that setting up husky following husky's documentation does not work out of the box for Git Graphical User Interfaces (GUI).
How to enable husky pre-commit hooks for Git GUI's
To enable this feature for a GUI such as Tower or sourcetree follow these steps:
Create a .huskyrc
file in your OSX home directory (~/
). Open your terminal and run the following commands:
$ cd ~/
$ touch .huskyrc
$ vi huskyrc
Press i
to enter vim's instert mode. Copy paste the following line:
PATH="/usr/local/bin:$PATH"
Press esc
. Then :
and wq
. Finally press enter
.
Now doing a commit in a GUI should show you the issues with the code when doing a commit:
Troubleshooting
How to solve dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib
Adding the path to the husky file enables husky, but initially it gave the following error on my machine:
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
Referenced from: /usr/local/bin/node
Reason: image not found
.git/hooks/husky.sh: line 15: 90006 Abort trap: 6 "$@" husky-run $hookName $gitParams
You can upgrade node to resolve this issue:
$ brew upgrade node
Bonus
When using a node version package manager make sure to also include the following lines to .huskyrc:
# this loads nvm.sh and sets the correct PATH before running hook
. ~/.nvm/nvm.sh
Top comments (4)
Thanks Remi, you made my day.
BTW: The first code snippet in the article is missing a dot. Line 3 should read
$ vi .huskyrc
, nothuskyrc
).Thanks for the tips.
I now have another error:
Here's my
~/.huskyrc
:Thanks! 🚀
I use this one-liner:
echo "\nPATH="/usr/local/bin:\$PATH"" >> ~/.huskyrc
Thanks! You saved my nerves 🙂