Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I understand this works with GUI's but what about Github's Desktop Client? #49

Closed
lasergoat opened this issue May 25, 2016 · 19 comments
Closed

Comments

@lasergoat
Copy link

I have installed node with the standard installer.

I have husky working in the CLI but Github Desktop Client acts like there are no scripts to run.

@iamstarkov
Copy link

maybe it is the problem with github desktop?

@typicode
Copy link
Owner

Hi,

What's the output of which node? You're on OS X?

@lasergoat
Copy link
Author

lasergoat commented May 26, 2016

OSX EL Capitan, 10.11.5

which node = /usr/local/bin/node

The weird part is that before I found husky, I had tried using ghooks. Ghooks worked in the CLI but the Desktop Client broke with the no env node error so I know that the desktop client does try to run git hooks properly. I believe that something within the husky generated script skips the entire hook if node isn't found.

@typicode
Copy link
Owner

I believe that something within the husky generated script skips the entire hook if node isn't found.

It checks if npm is available in $PATH and fails otherwise. I suspect that $PATH may not be the same when the git hook script is run from GitHub Desktop.

If you want verify it, you can run:

my-project$ echo $PATH

# echo $PATH in some file when pre-commit is called
my-project$ mv .git/hooks/pre-commit .git/hooks/pre-commit.bak
my-project$ echo 'echo $PATH > ../../precommit-path' > .git/hooks/pre-commit

# try to make a commit from GitHub Desktop and check the output
my-project$ cat precommit-path

Sorry I'm on Linux right now, so I can't test it.
There may be a setting in GitHub Desktop to edit PATH.

@typicode
Copy link
Owner

Quick update, works with nvm + GitHub Desktop.
Need to test with Node installed differently.

@skhilko
Copy link

skhilko commented Aug 28, 2016

I confirm, husky hooks don't work for GUI clients with Node installed without use of nvm. When I use SourceTree to commit something, I see the following error:
husky - can't find npm in PATH. Skipping precommit script in package.json
I'm pretty sure it fails the same in GitHub Desktop.

@typicode, you're exactly right:

I suspect that $PATH may not be the same when the git hook script is run from GitHub Desktop.

After some research I found that GUI apps on mac didn't respect $PATH value set for terminal environment.

I've installed node via homebrew. Both node and npm are installed under /usr/local/bin. (as you'd installed them with a standard installer)

/usr/bin:/bin:/usr/sbin:/sbin is the $PATH value when committing from SourceTree.

I know that this is not really a husky issue, that is simply how mac GUI apps work. However, if we could include /usr/local/bin when husky generates the hooks, that would've resolved the issue for many people without the need of finding the unreliable solution and tinkering with the system.

@typicode
Copy link
Owner

typicode commented Sep 1, 2016

I know that this is not really a husky issue, that is simply how mac GUI apps work. However, if we could include /usr/local/bin when husky generates the hooks

I agree :), do you want to make a PR?

@typicode
Copy link
Owner

Should be good with v0.11.8.
Thank you @skhilko

@cecilia-sanare
Copy link
Contributor

cecilia-sanare commented Oct 5, 2016

Still seeing the original issue of the pre-commit hook running from the CLI, but getting skipped in GUIs.

I checked the $PATH variable from both the GUI and CLI as mentioned above, and it looks like its the same exact issue.

OS: Windows 7
GUI: GitHub Desktop

@iamstarkov
Copy link

@nick-woodward is it with latest husky?

@cecilia-sanare
Copy link
Contributor

@iamstarkov Sorry forgot to mention that. Yes I'm using 0.11.8.

@damusnet
Copy link

damusnet commented May 5, 2017

Hi, somehow I still have that exact same issue as well:

OS: macOS Sierra 10.12.4
GUI: GitHub Desktop
which node = /usr/local/bin/node
node --version = v7.9.0 installed with Homebrew
"husky": "^0.13.3" with yarn add husky --dev --force

Am I missing something? Thanks in advance!

@damusnet
Copy link

damusnet commented May 5, 2017

Nevermind! I just had removed another precommit lib (precommit-hook) and had to remove all hooks rm -f .git/hooks/* and run yarn add husky --dev --force again. Now all works fine!

@jbcpollak
Copy link

I'm having this problem with nodenv installed, since /usr/local/bin/nvm doesn't exist. I don't have a solution yet.

@lasergoat
Copy link
Author

@jbcpollak did you figure it out?

@jantimon
Copy link

jantimon commented Sep 11, 2017

@jbcpollak @lasergoat my work a round for nodenv is the following:
Create a new file: ~/.nvm/nvm.sh with the following content:

#!/bin/bash
eval "$(nodenv init -)"

As husky executes the nvm.sh it will also initialize nodenv.

However it would be nice if husky could detect nodenv and call that command directly

@jbcpollak
Copy link

@jantimon that's a great idea - I'll try it. I had been installing a copy of node directly through homebrew, but I'll try this solution instead.

@jonasdev
Copy link

jonasdev commented Jan 8, 2020

How did you solve this issue? I'm now getting the error Commit failed - exit code 1 received, with output: 'Husky requires Node 8.6.0, can't run Git hook.' - guess its the same issue? Using github desktop 2.2.4

@lasergoat
Copy link
Author

lasergoat commented Jan 9, 2020

@jonaskkristensen I never did solve this, it just started working after their PR and me switching to the newer github client when it came out. What node version are you?

node -v

or if using nvm, do nvm list and see which is your default version.

Make sure it's higher than 8.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants