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

Hook should fail if command is not found #715

Closed
seyfert opened this issue Apr 18, 2020 · 5 comments
Closed

Hook should fail if command is not found #715

seyfert opened this issue Apr 18, 2020 · 5 comments

Comments

@seyfert
Copy link

seyfert commented Apr 18, 2020

Husky should fail a hook if the package manager husky is configured to run cannot be found.

The reason this came up is that SourceTree has an issue with the PATH not including /usr/local/bin on MacOS by default. So if a developer doesn't have SourceTree setup correctly it will commit the change since the hook is skipped by Husky when the command is not found.

See this related SourceTree issue.
https://jira.atlassian.com/browse/SRCTREE-7184

Other related husky issues:
#390
#639

Shouldn't the hook error (exit 1) if the command is not found instead of skipping the hook?

husky/sh/husky.sh

Lines 25 to 28 in 85a4704

else
echo "Can't find $1 in PATH: $PATH"
echo "Skipping $hookName hook"
exit 0

In the example below I am trying to list my project using a yarn script as a pre-commit hook but I purposely removed yarn from my PATH.

~/test$ git --version
git version 2.20.1 (Apple Git-117)
~/test$ HUSKY_DEBUG=1 git commit -m "test commit"
husky:debug husky v4.2.3 - pre-commit
husky:debug Current working directory is /Users/.../test
Can't find yarn in PATH: /Library/Developer/CommandLineTools/usr/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
Skipping pre-commit hook
husky:debug husky v4.2.3 - prepare-commit-msg
husky:debug Current working directory is /Users/.../test
husky:debug prepare-commit-msg config not found, skipping hook
husky:debug husky v4.2.3 - commit-msg
husky:debug Current working directory is /Users/.../test
husky:debug commit-msg config not found, skipping hook
husky:debug husky v4.2.3 - post-commit
husky:debug Current working directory is /Users/.../test
Can't find yarn in PATH: /Library/Developer/CommandLineTools/usr/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
Skipping post-commit hook
[test-branch 06cb01a] test commit
 1 file changed, 1 insertion(+), 1 deletion(-)
@zuzusik
Copy link

zuzusik commented Apr 21, 2020

Very good suggestion. Due to Husky breaking changes (actually, I'd rather consider it a regression) after moving to husky 4 all the commit hooks just started to be skipped suddenly when doing commit through SourceTree. It took me quite a while to figure out what's going on.

@j3ko
Copy link

j3ko commented Aug 22, 2020

Some other related issues:

#666
#125

This seems like it should be the default behaviour. If the environment does not provide the necessary commands it shouldn't skip the hook. Uninitiated developers with improper environment setups should not be allowed to commit since many of the tools that are run by husky are purposed for this same group of people.

@drwaky
Copy link

drwaky commented Sep 24, 2020

Same here with husky 4, Sourcetree, and MacOs. I moved back to husky 3.1.0.

Any solution?

@qqilihq
Copy link

qqilihq commented Nov 20, 2020

Same here. Wondering why hooks did not run using Fork.app on Mac. Downgrading to 3.1.0 fixed this.

Feels like a regression to me.

@typicode
Copy link
Owner

typicode commented Jan 8, 2021

Behavior is changed in v5 and it will fail if a command is missing.
Thanks for the feedback 👍

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

6 participants