1

I've recently started using commitizen in my day-to-day development, however I don't understand why I get the following error with the first commit to a new branch, ie:

...on current main branch...
git checkout -b fix/my-new-branch
...make some changes...
git commit -am "fix: did the thing"

commitizen check.........................................................Passed
commitizen check branch..................................................Failed
- hook id: commitizen-branch
- exit code: 3

No commit found with range: 'origin/HEAD..HEAD'

My pre-commit file looks like this:

---
repos:
  - repo: https://github.com/commitizen-tools/commitizen
    rev: v2.37.1
    hooks:
      - id: commitizen
      - id: commitizen-branch
        stages: [commit-msg]

Is there something I'm missing here?

  • My git remote is setup:
origin  git@github.com:myuser/my_repo.git (fetch)
origin  git@github.com:myuser/my_repo.git (push)
  • Git branch shows:
 fix/my-new-branch
 * main
torek
  • 448,244
  • 59
  • 642
  • 775
Chris
  • 2,739
  • 4
  • 29
  • 57
  • Run `git log --all --decorate --oneline --graph` (or see [Pretty Git branch graphs](https://stackoverflow.com/q/1057564/1256452) for various alternatives) and see whether there should be commits in the `origin/HEAD..HEAD` range. If not, that's the problem; if so, there's something wrong with your pre-commit hook. (Note that it's possible that the lack of commits between `origin/HEAD` and `HEAD` itself is fine, and the *expectation* that there be some such commits is the problem with the pre-commit hook.) In any case this isn't Git, it's some add-on. – torek Dec 02 '22 at 21:07

1 Answers1

0

the commitizen-branch hook is intended for after-the-fact usage and not during the commit-msg stage -- you probably don't need it / don't want it and can have it removed

notably, the stages: [commit-msg] is incorrect to set for that hook since it is not designed to run during commit-msg (where no commits exist between origin/HEAD and HEAD)

personally I'd probably set that ones as stages: [manual] such that it never automatically runs, but can be run on demand


disclaimer: I wrote pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207