Closed sdavids closed 7 months ago
I have been struggling with getting husky working with the git-tower application for so long. For some of the projects I work with it worked with above's example. But not for all. And indeed the issue is:
On macOS UI applications do not have the environment set in ~/.zshrc.
What I did was source the ~/.zshrc
. Adding this to the .huskyrc
file:
#!/usr/bin/env sh
source ~/.zshrc
#!/usr/bin/env sh source ~/.zshrc
I suggest you adjust it as follows:
#!/usr/bin/env sh
set -eu
[ -e /etc/zshenv ] && . /etc/zshenv
[ -e "${ZDOTDIR:=${HOME}}/.zshenv" ] && . "${ZDOTDIR:=${HOME}}/.zshenv"
[ -e /etc/zprofile ] && . /etc/zprofile
[ -e "${ZDOTDIR:=${HOME}}/.zprofile" ] && . "${ZDOTDIR:=${HOME}}/.zprofile"
[ -e /etc/zlogin ] && . /etc/zlogin
[ -e "${ZDOTDIR:=${HOME}}/.zlogin" ] && . "${ZDOTDIR:=${HOME}}/.zlogin"
git-hooks invoked by a graphical client are run in a non-interactive login shell.
I suggest you adjust it as follows: ...
AFAICT, nvm only adds its config lines to .zshrc; so @Klaasvaak solution worked for me. Thanks!!
Closing as there's a dedicated section: https://typicode.github.io/husky/how-to.html#node-version-managers-and-guis
There's only instructions for nvm because there are tens of version manager and it would be too complex to keep track how to load them.
Unless there's a check in .zshrc
to prevent loading in non-interactive mode, sourcing it manually should work (even in non-interactive mode).
That being said, you're right that different files are loaded by zsh based on the context :+1:
https://typicode.github.io/husky/troubleshooting.html#command-not-found
On macOS UI applications do not have the environment set in
~.zshrc
.Node version managers like nvm/fnm rely on setup in
~/.zsh
.Graphical git clients like Tower for example cannot use the git hooks created by husky because they will not find the husky npm installation.
Therefore on macOS you have to have a
.huskyrc
.Here are two examples:
nvm
fnm
Please mention the above under Troubleshooting, so other macOS users find it easier.