1

I am using husky and commitLint to check the commit messages in one of the repo's I work.

package.json

"husky": {
  "hooks": {
    "pre-commit": "lint-staged",
    "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
  }
}

pretty straightforward. However, as I don't wanna create a barrier for the less experienced developers of my team I wanna run a CLI to help them format their commit message IF the hook "commit-msg" fails because of bad formatting.

So, I tried the following "commit-msg": "commitlint -E HUSKY_GIT_PARAMS &> /dev/null || npx git-cz" and it executes the second command, but it also closes the cli right after running it.

So, any idea how to implement such thing ?

RobC
  • 22,977
  • 20
  • 73
  • 80
vbotio
  • 1,566
  • 3
  • 26
  • 53

1 Answers1

0

Have you tried with this:

"husky": {
  "hooks": {
    "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true"
  }
}

source

  • doesnt really work as it runs the CLI regardless the commit message is good or not. – vbotio Aug 25 '20 at 06:19
  • you could validate the commit message directly with commitlint. Check if this is useful for you [commitlint-usage](https://github.com/mpielvitori/commitlint-usage) – Martin Pielvitori Aug 26 '20 at 21:56