Commitizen-branch with pre-commit prevents from push to origin with exit code 23
Description
Whenever I try to push a commit to the origin (git push -u origin main), an error is preventing me from pushing:
commitizen check branch..................................................Failed
- hook id: commitizen-branch
- exit code: 23
fatal: ambiguous argument 'origin/HEAD..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
error: failed to push some refs to 'https://github.com/<some repo>.git'
Steps to reproduce
- Run
cz init. - Run
pre-commit install --hook-type commit-msg --hook-type pre-push - Run
git init && git add . && git commit -m "feat: my new commit" - Run
git remote add origin https://github.com/<some repo>.git - Run
git push -u origin main
Current behavior
I should be able to push it correctly to origin.
Desired behavior
I want to push it to origin.
Screenshots
No response
Environment
Commitizen Version: 2.42.1
Python Version: 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110]
Operating System: Linux
I have exactly the same bug
If you are using dev containers, for me it worked by cleaning my local dev container and let it rebuild.
Any quick solution to this bug? (that is not --no-verify)
I'm still seeing this as well. I added cz to an existing repo, but in a new branch that did not exist on origin yet, if that helps.
For anyone still running into this, here's how you fix it:
git remote set-head origin --auto
For whatever reason, HEAD was not set in my repo.
Before:
$ git branch -a
* dev/initial_structure
main
remotes/origin/dev/initial_structure
remotes/origin/main
After:
$ git branch -a
* dev/initial_structure
main
remotes/origin/HEAD -> origin/main
remotes/origin/dev/initial_structure
remotes/origin/main