husky icon indicating copy to clipboard operation
husky copied to clipboard

Hooks not working

Open standayweb opened this issue 8 years ago • 91 comments

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

standayweb avatar Aug 14 '18 11:08 standayweb

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

hackardoX avatar Aug 14 '18 13:08 hackardoX

Same here

aguynamedben avatar Aug 14 '18 21:08 aguynamedben

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.

aguynamedben avatar Aug 14 '18 21:08 aguynamedben

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

standayweb avatar Aug 15 '18 09:08 standayweb

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.

ramakrishnasomepalli avatar Aug 22 '18 04:08 ramakrishnasomepalli

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

nikolay-borzov avatar Aug 22 '18 12:08 nikolay-borzov

@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 ~

yiuyiu avatar Aug 30 '18 10:08 yiuyiu

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

typicode avatar Sep 10 '18 15:09 typicode

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

ramakrishnasomepalli avatar Sep 10 '18 23:09 ramakrishnasomepalli

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

ramakrishnasomepalli avatar Sep 10 '18 23:09 ramakrishnasomepalli

@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...

typicode avatar Sep 11 '18 12:09 typicode

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?

Undistraction avatar Sep 11 '18 16:09 Undistraction

@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

typicode avatar Sep 11 '18 16:09 typicode

@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.

Undistraction avatar Sep 11 '18 17:09 Undistraction

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

typicode avatar Sep 11 '18 19:09 typicode

@typicode Please find the below log.

$ npm i husky@next -D

> [email protected] preuninstall D:\workspace\TW-Workspace\Q2A\svc-q2a-quote-pricecheck\node_modules\husky
> node husky uninstall

husky > uninstalling git hooks
husky > done

> [email protected] 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 [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ [email protected]
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",

ramakrishnasomepalli avatar Sep 11 '18 23:09 ramakrishnasomepalli

@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?

Undistraction avatar Sep 12 '18 08:09 Undistraction

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.

standayweb avatar Sep 13 '18 12:09 standayweb

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.

MincheolC avatar Sep 20 '18 01:09 MincheolC

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

typicode avatar Sep 23 '18 04:09 typicode