commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

Commitizen-branch with pre-commit prevents from push to origin with exit code 23

Open vabatta opened this issue 2 years ago • 5 comments

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

  1. Run cz init.
  2. Run pre-commit install --hook-type commit-msg --hook-type pre-push
  3. Run git init && git add . && git commit -m "feat: my new commit"
  4. Run git remote add origin https://github.com/<some repo>.git
  5. 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

vabatta avatar Apr 13 '23 08:04 vabatta

I have exactly the same bug

image

Corfucinas avatar Jun 19 '23 09:06 Corfucinas

If you are using dev containers, for me it worked by cleaning my local dev container and let it rebuild.

vabatta avatar Jun 19 '23 13:06 vabatta

Any quick solution to this bug? (that is not --no-verify)

Corfucinas avatar Jun 23 '23 22:06 Corfucinas

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.

eadgbear avatar Aug 15 '23 00:08 eadgbear

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

eadgbear avatar Aug 17 '23 15:08 eadgbear