Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Don't you have problems of twice precommit with husky? #267

Closed
9andresc opened this issue Apr 23, 2017 · 4 comments
Closed

Don't you have problems of twice precommit with husky? #267

9andresc opened this issue Apr 23, 2017 · 4 comments

Comments

@9andresc
Copy link

Hello @kentcdodds, hope you are well.

I wanted to ask if you don't have this kind of problem. See, when I execute yarn commit the precommit is executed before and after starting the lint and test process (twice). It's a weird behavior. Here's a portion of my package.json in case you can help me with this.

...
"scripts": {
  "commit": "git-cz",
  "lint": "standard --verbose | snazzy",
  "lint:fix": "standard --fix",
  "precommit": "yarn test",
  "semantic-release": "semantic-release pre && npm publish && semantic-release post",
  "test": "yarn lint && jest --coverage",
  "test:watch": "jest --watch"
},
...
"config": {
  "commitizen": {
    "path": "node_modules/cz-conventional-changelog"
  }
},
...

Thank you.

@kentcdodds
Copy link
Owner

Hi @gustavoandrescabral!

So the problem is that npm scripts have this feature which allows you to prefix script names with pre or post and those things will run before or after the script name. So you have both a commit and a precommit. What this means is that precommit will be run before commit is run. Then husky will run your precommit script as that's the name of a commit hook.

So you can do one of a few things to solve/workaround this:

  1. Contribute back to husky to solve these problems
  2. Use something other than husky. There are a bunch of projects like this.
  3. Don't use commitizen (honestly, I pretty much never use it, even though it's setup in all of my projects...
  4. Change your commit script name to something else.
  5. Use nps and have commitizen as your commit script in package-scripts.js. This is what I do.

I hope that's helpful! Good luck!

@9andresc
Copy link
Author

9andresc commented May 6, 2017

Thank you @kentcdodds! I tried the fourth option and worked nicely 😌. About the third option, if you don't use commitizen, what solution do you recommend? I'm excited to know ✨

@kentcdodds
Copy link
Owner

I just author my message by hand 😀

@9andresc
Copy link
Author

9andresc commented May 6, 2017

I'll continue to use commitizen until I do it on my own, time will do its work. Again, thank you very much!

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

No branches or pull requests

2 participants