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

Hooks not working #326

Closed
standayweb opened this issue Aug 14, 2018 · 41 comments

Comments

@standayweb
Copy link

@standayweb standayweb commented Aug 14, 2018

I have set up husky commit hooks to run on commit and push, it works for me and another dev, but for one dev the commit hooks do not get run. Not sure what the issue is here

@andrea11

This comment has been minimized.

Copy link

@andrea11 andrea11 commented Aug 14, 2018

I have the same issue... I don't know why but it seems that husky don't install correctly git hooks

@aguynamedben

This comment has been minimized.

Copy link

@aguynamedben aguynamedben commented Aug 14, 2018

Same here

@aguynamedben

This comment has been minimized.

Copy link

@aguynamedben aguynamedben commented Aug 14, 2018

I was experiencing this with a pre-push hook until I saw this other ticket in which somebody mentioned needing to use version 1.0.0-rc.13, then it worked.

@standayweb

This comment has been minimized.

Copy link
Author

@standayweb standayweb commented Aug 15, 2018

Unfortunately, we are already using 1.0.0-rc.13 but thanks for the suggestion

@ramakrishnasomepalli

This comment has been minimized.

Copy link

@ramakrishnasomepalli ramakrishnasomepalli commented Aug 22, 2018

I have the same issue i tried both the versions (1.0.0-rc.13 and the stable 0.14.3 ) but no hook (pre-commit,post-push ..etc) is triggering . I verified the hooks folder and all the respective scripts are available and husk is also installed as expected. I also verified the " npm config get ignore-scripts" and the flag is set to false.
Any suggestion how to make it work.

@nikolay-borzov

This comment has been minimized.

Copy link

@nikolay-borzov nikolay-borzov commented Aug 22, 2018

I know that hooks don't work on WebStorm IDE because of the way how WebStorm uses Git

@yiuyiu

This comment has been minimized.

Copy link

@yiuyiu yiuyiu commented Aug 30, 2018

@ramakrishnasomepalli
hello i met the same problem.And i find that the husky must install after git init . When installed it will show setting up git hooks ~

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Sep 10, 2018

Have you fixed your issue?
Are you getting any output from husky when running npm install husky@next -D or when commiting/pushing with Git? Also which Git client or IDE are you using?

@ramakrishnasomepalli you've checked the right things... maybe I would check the value of git config core.hooksPath

@ramakrishnasomepalli

This comment has been minimized.

Copy link

@ramakrishnasomepalli ramakrishnasomepalli commented Sep 10, 2018

I am still facing the error but the same configurations are working fine in another machine.

@ramakrishnasomepalli

This comment has been minimized.

Copy link

@ramakrishnasomepalli ramakrishnasomepalli commented Sep 10, 2018

@typicode When i am committing i am not getting any logs related to husk.

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Sep 11, 2018

@ramakrishnasomepalli when running git config core.hooksPath what do you get? When checking .git/hooks/pre-commit (or the failing hook) does it start with:

#!/bin/sh
# husky
# v1.0.0...
@Undistraction

This comment has been minimized.

Copy link

@Undistraction Undistraction commented Sep 11, 2018

I have the same problem. Hooks do not run. git config core.hooksPath returns nothing. I can't see anything in the docs. Does Husky expose a command to install the hooks if they fail on install?

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Sep 11, 2018

@Undistraction you can simply re-run npm install husky@next --save-dev

If it shows something different than the outpout below, could you copy/pate it here please?

husky > setting up git hooks
husky > done
@Undistraction

This comment has been minimized.

Copy link

@Undistraction Undistraction commented Sep 11, 2018

@typicode I found the problem. Husky is a dependency of another package. It seems that even though it is installed when I install that package, it doesn't set up the git hooks. This only happens when I install explicitly using npm i husky@next -D.

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Sep 11, 2018

@Undistraction thanks for the update, I was running out of ideas 😅

@ramakrishnasomepalli

This comment has been minimized.

Copy link

@ramakrishnasomepalli ramakrishnasomepalli commented Sep 11, 2018

@typicode Please find the below log.

$ npm i husky@next -D

> husky@1.0.0-rc.13 preuninstall D:\workspace\TW-Workspace\Q2A\svc-q2a-quote-pricecheck\node_modules\husky
> node husky uninstall

husky > uninstalling git hooks
husky > done

> husky@1.0.0-rc.14 install D:\workspace\TW-Workspace\Q2A\svc-q2a-quote-pricecheck\node_modules\husky
> node husky install

husky > setting up git hooks
husky > done
npm WARN svc-q2a-quote-pricecheck@1.0.9 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ husky@1.0.0-rc.14
added 2 packages and updated 1 package in 203.131s.

And it is still not working also as suggested by @Undistraction I have noticed the below packages are missing from being installed under nodule modules of husky but the same are available under my project node modules.
"cosmiconfig": "^5.0.6","get-stdin": "^6.0.0","please-upgrade-node": "^3.1.1","run-node": "^1.0.0",

@Undistraction

This comment has been minimized.

Copy link

@Undistraction Undistraction commented Sep 12, 2018

@typicode Thanks for all your help. Can you confirm that husky should install hooks if installed via the dependency of another package?

For example if my project installed a package called 'alpha' and that package has a dependency on 'husky', should husky install the githooks for my project? Or will this only happen if husky is installed directly in the project?

@standayweb

This comment has been minimized.

Copy link
Author

@standayweb standayweb commented Sep 13, 2018

The developer who was having this issue is no longer at the company and has reset his laptop, I'll leave this open though as other people seem to be having the issue.

@MincheolC

This comment has been minimized.

Copy link

@MincheolC MincheolC commented Sep 20, 2018

Hi, I encounter with similar issue. I'm using husky v1.0.0-rc.14 and package.json as follow.

"husky": {
    "hooks": {
      "pre-push": "npm test"
    }
  }

pre-push hook doesn't not working, but pre-commit work fine as follow

"husky": {
    "hooks": {
      "pre-commit": "npm test"
    }
  }

Is there anyone here who can help me with this problem?? Thanks

p.s I want to use pre-push for unit test and pre-commit for lint.

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Sep 23, 2018

Hi @MincheolC, can you check that .git/hooks/pre-commit and .git/hooks/pre-push have the same content?

@jakewies

This comment has been minimized.

Copy link

@jakewies jakewies commented Oct 1, 2018

I seem to be having the same issue when upgrading from 0.14 to 1.0.1. I am using husky in conjunction with lint-staged:

// package.json

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/**/*.{js,jsx,json,css}": [
      ...
    ]
  }

I noticed that I am no longer getting any husky related output when committing.

My /.git/hooks/pre-commit contents begin with:

// .git/hooks/pre-commit

#!/bin/sh
# husky
# v1.0.1 darwin

...

Not sure what's going on, but I hope this info helps narrow the issue a bit. 😄

EDIT:

I also attempted to re-install husky via yarn add husky (installs v1.0.1) but never received any output regarding hooks being installed 🤷‍♂️

@MincheolC

This comment has been minimized.

Copy link

@MincheolC MincheolC commented Oct 2, 2018

Hi, @typicode I just have pre-commit.sample and pre-push.sample in .git/hooks.
Do I need pre-commit and pre-push files?
If they're needed, then could you give me the content of them?

thanks~

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Oct 4, 2018

Hi @MincheolC,

Yes, they're needed. They should be created automatically for you when you run npm install husky --save-dev, or just with npm install if husky is already defined in package.json.

I'd suggest running npm install husky --save-dev and checking .git/hooks content again. Let me know if it creates them.

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Oct 4, 2018

Hi @jakewies,

To confirm that pre-commit is running, I'd try to edit .git/hooks/pre-commit and add something like:

#!/bin/sh
# husky
# v1.0.1 darwin
echo "pre-commit" # should be visible in the console when doing a git commit

...
@MincheolC

This comment has been minimized.

Copy link

@MincheolC MincheolC commented Oct 8, 2018

@typicode thanks it works well. now~

@jakewies

This comment has been minimized.

Copy link

@jakewies jakewies commented Oct 8, 2018

@typicode I'll update that file and see what happens 👍

@jakewies

This comment has been minimized.

Copy link

@jakewies jakewies commented Oct 8, 2018

@typicode I updated .git/hooks/pre-commit with the line below:

 #!/bin/sh
 # husky
 # v1.0.1 darwin

echo "pre-commit"

...

I added a test file and committed to source. Unfortunately "pre-commit" was not logged to the console when running git commit. 😞

@typicode

This comment has been minimized.

Copy link
Owner

@typicode typicode commented Oct 8, 2018

@standayweb AFAICT it doesn't seem to be related to husky. Do you have a GIT_DIR env variable set?

@standayweb

This comment has been minimized.

Copy link
Author

@standayweb standayweb commented Oct 16, 2018

@typicode The developer who was having this issue is no longer at the company and has reset his laptop

@typicode typicode closed this Dec 7, 2018
@HeyParkerJ

This comment has been minimized.

Copy link

@HeyParkerJ HeyParkerJ commented Jan 8, 2019

For those who come after me - I was having this issue because my global git config hooksPath was set to a different directory.

@jorgemasta

This comment has been minimized.

Copy link

@jorgemasta jorgemasta commented Feb 5, 2019

As @HardcoreParkore says, checks you git config, in your folder project: cat .git/config

You must remove hooksPath, husky will handle this for you.

@zlydenko

This comment has been minimized.

Copy link

@zlydenko zlydenko commented Feb 20, 2019

As @HardcoreParkore says, checks you git config, in your folder project: cat .git/config

You must remove hooksPath, husky will handle this for you.

what if you dont have config file?

@codelegant

This comment has been minimized.

Copy link

@codelegant codelegant commented Apr 9, 2019

I meet this issue, the reason is I install husky before I init git。

@HeyParkerJ

This comment has been minimized.

Copy link

@HeyParkerJ HeyParkerJ commented Apr 9, 2019

As @HardcoreParkore says, checks you git config, in your folder project: cat .git/config
You must remove hooksPath, husky will handle this for you.

what if you dont have config file?

In order, do the following

  • Run git config --list and ensure there is no 'hooksPath'
  • If there was a hooksPath, remove/comment it
  • Delete the hooks in .git/hooks^1
  • npm install
  • You can check that this worked by reading the hook and ensuring that there's a comment from Husky inside it

^1: This is required because husky takes over the hooks in .git/hooks at installation time and won't override a pre-existing hook.

@JuanmaMenendez

This comment has been minimized.

Copy link

@JuanmaMenendez JuanmaMenendez commented May 20, 2019

Guys my problem is that committing with WebStorm Dialog fails and show me this error: "cannot spawn .git/hooks/pre-commit: No such file or directory"

However, when I commit manually in the console, everything works as expected (pre-commit hook is called, the lints executed and the files committed)

I am using Windows and lint-staged.

I tried without hooksPath and setting hooksPath = .git/hooks but the same results it works in the console but not in WebStorm Dialog.

Any ideas?

@HeyParkerJ

This comment has been minimized.

Copy link

@HeyParkerJ HeyParkerJ commented May 20, 2019

@JuanmaMenendez I've seen some people say that adding a shebang to the beginning of the file helps

conventional-changelog/standard-version#254

@JuanmaMenendez

This comment has been minimized.

Copy link

@JuanmaMenendez JuanmaMenendez commented May 21, 2019

@JuanmaMenendez I've seen some people say that adding a shebang to the beginning of the file helps

@HardcoreParkore I had the shebang to the beginning :(

@JuanmaMenendez

This comment has been minimized.

Copy link

@JuanmaMenendez JuanmaMenendez commented May 24, 2019

I solved the problem, just in case somebody in the future need it the solution was:

In "Webstorm Settings > Version Control > Git > Path to Git executable" to change “C:\Program Files\Git\mingw64\bin\git.exe” by “C:\Program Files\Git\cmd\git.exe”

@eiji03aero

This comment has been minimized.

Copy link

@eiji03aero eiji03aero commented Aug 2, 2019

i kind of had similar case, and found out it was git version.
as part of installation code says, husky requiried git to be some version. maybe this thing should be put on README.md as well?
Husky requires Git >= 2.13.2

somehow, when i ran yarn add -D husky in my docker container, the log did not show the error supposedly thrown from src/installer/gitRebParse.ts

@hansiemithun

This comment has been minimized.

Copy link

@hansiemithun hansiemithun commented Aug 2, 2019

I am sorry to be late here, i am facing similar challenges. Can someone please answer this for me: https://stackoverflow.com/questions/57314400/precommit-hook-not-triggering-even-after-failures. I don't want to install lot more libraries and keep it simple in advance is my request.

@N0xFF

This comment has been minimized.

Copy link

@N0xFF N0xFF commented Aug 8, 2019

maybe this thing should be put on README.md as well?
Husky requires Git >= 2.13.2

It should be at the top of README https://github.com/typicode/husky/blob/master/CHANGELOG.md#300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.