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

precommit runs twice when using commitizen #152

Closed
faceyspacey opened this issue Apr 27, 2017 · 10 comments
Closed

precommit runs twice when using commitizen #152

faceyspacey opened this issue Apr 27, 2017 · 10 comments

Comments

@faceyspacey
Copy link

I'm using Husky. I have:

"scripts": {
   "precommit": "lint-staged --verbose",
   "commit": "git-cz",
},
"lint-staged": {
    "*.js": [
      "prettier --single-quote --semi=false --write",
      "eslint --fix",
      "git add"
    ]
},
"config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
},

At first I thought perhaps the precommit script isn't needed anymore, so I remove the it and lint-staged doesn't run at all. Then I decided to commit without commitizen and realized that's where the problem is. lint-staged is called once before the commitizen command line form appears, and again after you submit it. Is that the expected behavior? What can be done about it?

@okonet
Copy link
Collaborator

okonet commented Apr 28, 2017

If you always commit using npm run commit you could add lint-staged before calling git-cz and remove the precommit hook. I would not advise doing this, though.

Regarding running twice: it should not. Looking at your config I can't see the reason for that. So you should investigate and create a reproducible example on GitHub if the problem is with this package.

@Hotell
Copy link
Contributor

Hotell commented Jun 4, 2017

I have same issue here
https://github.com/Hotell/typescript-lib-starter

image

@Hotell
Copy link
Contributor

Hotell commented Jun 4, 2017

ha! so this isn't definitely issue with this library, rather than husky is the culprit here. I guess you can close this @okonet

typicode/husky#110

Maybe it should be stated in your docs? If you're ok with that I'll submit PR

thanks!

Hotell added a commit to Hotell/typescript-lib-starter that referenced this issue Jun 4, 2017
Hotell added a commit to Hotell/typescript-lib-starter that referenced this issue Jun 4, 2017
@okonet
Copy link
Collaborator

okonet commented Jun 5, 2017

PR would be awesome! Thanks for investigating.

@okonet okonet closed this as completed Jun 5, 2017
@Hotell
Copy link
Contributor

Hotell commented Jun 5, 2017

cheers ! #182

@codepunkt
Copy link

Is there an issue in the husky repository to fix this?

@Hotell
Copy link
Contributor

Hotell commented Jun 13, 2018

this is fixed with latest husky ✌️

yarn add husky@next
"scripts": {
-"cz": "git-cz",
+"commit": "git-cz",
-"precommit": "lint-staged"
},
+"husky": {
+   "hooks": {
+      "pre-commit": "lint-staged"
+   }
+ }

@wearefridayhutber
Copy link

wearefridayhutber commented Sep 12, 2018

humm so @Hotell juts to confirm steps to get this working:

"devDependencies": {
   "cz-conventional-changelog": "^2.1.0",
   "husky": "^0.14.3",
},
"commit": "git-cz",
 "husky": {
   "hooks": {
     "pre-commit": "lint-staged"
   }
},

is all you need?

Because when I run git cz with the above config, it goes straight to commitizen and does not run any test.

@jcarroll2007
Copy link

jcarroll2007 commented Oct 31, 2018

@wearefridayhutber I get the same. My approach has been to simply run a specific script before husky.

"devDependencies": {
   "cz-conventional-changelog": "^2.1.0",
   "husky": "^0.14.3",
},
"scripts": {
  "commit": "lint-staged && git-cz --no-verify",
},
"husky": {
   "hooks": {
     "pre-commit": "lint-staged"
   }
},

The --no-verify flag prevents husky from being run after commitizen.

Or


"devDependencies": {
   "cz-conventional-changelog": "^2.1.0",
   "husky": "^0.14.3",
},
"scripts": {
  "pre-commit": "lint staged",
  "commit": "yarn run pre-commit && git-cz --no-verify",
},
"husky": {
   "hooks": {
     "pre-commit": "yarn pre-commit"
   }
},

This approach ensures that husky is run before commitizen (but not after) and before a vanilla git commit

@hassankhan
Copy link

This seems to be happening again with husky@4.2.3. @jcarroll2007's fix from the above comment seems to do the trick, though.

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

No branches or pull requests

7 participants