3

In a lerna/yarn monorepo, we use commitizen and cz-conventional-changelog to manage releases. We use husky to lint commit messages in the commit-msg hook and run the commitizen cli in the prepare-commit-msg hook:

  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
      "pre-commit": "lint-staged",
      "prepare-commit-msg": "exec < /dev/tty && yarn commit --hook || true"
    }
  },

This works fine as long as a rebase is not required, however, while our team are still learning the ropes, we often need to rebase feature branches in order to fix commit messages.

git rebase --interactive origin/master

While running the rebase, if I choose the reword command, I will be able to edit the commit message in my editor, but the commitizen cli will not run, in other words, there's nothing to prevent us from committing bad commit messages.

While we do lint commit messages in CI, I would much rather avoid this problem altogether by enforcing use of the commitizen CLI wizard at all stages.

Question:

Can I configure git to use the prepare-commit-msg hook during rebase reword operations?

phd
  • 82,685
  • 13
  • 120
  • 165
Benny Powers
  • 5,398
  • 4
  • 32
  • 55

1 Answers1

1

git rebase runs pre-rebase and post-rewrite hooks. I doubt it runs any other hooks.

I think you can use git rebase --exec to run a validation script after every rebased commit. Any error code pauses rebase process.

phd
  • 82,685
  • 13
  • 120
  • 165