Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError exception thrown during cz bump #1004

Closed
niall-byrne opened this issue Mar 6, 2024 · 3 comments
Closed

UnboundLocalError exception thrown during cz bump #1004

niall-byrne opened this issue Mar 6, 2024 · 3 comments

Comments

@niall-byrne
Copy link

niall-byrne commented Mar 6, 2024

Description

When I run cz bump without any existing tags, an error is thrown if I have a pre_bump script configured.

This started as of version 3.16.0, versions before that had no issue.

Steps to reproduce

  1. Repo with no tags.

  2. Configure a simple pre_bump script.

     #!/bin/bash
     # Standardize toml quotes
     set -eo pipefail
     main() {
        # sed compatible with Linux and BSD
        sed -i.bak "s,\"${CZ_PRE_NEW_VERSION}\",'${CZ_PRE_NEW_VERSION}',g" pyproject.toml
        rm pyproject.toml.bak
     }
    
     main
       [tool.commitizen]
       bump_message = 'bump(RELEASE): $current_version → $new_version'
       pre_bump_hooks = ['.cicd-tools/boxes/bootstrap/commitizen/pre_bump.sh']
  3. cz bump --increment MINOR --yes

Current behavior

poetry run cz bump --increment MINOR --yes
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    BRANCH_OR_TAG: master
    pythonLocation: /opt/hostedtoolcache/Python/[3](https://github.com/cicd-tools-org/cicd-tools/actions/runs/8175897168/job/22354095523#step:9:3).9.18/x6[4](https://github.com/cicd-tools-org/cicd-tools/actions/runs/8175897168/job/22354095523#step:9:4)
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.18/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.18/x64/lib
bump(RELEASE): 0.1.0 → 0.2.0
tag to create: 0.2.0
increment detected: MINOR

Traceback (most recent call last):
  File "/home/runner/.cache/pypoetry/virtualenvs/cicd-tools-3sbBasnr-py3.9/bin/cz", line 8, in <module>
    sys.exit(main())
  File "/home/runner/.cache/pypoetry/virtualenvs/cicd-tools-3sbBasnr-py3.9/lib/python3.9/site-packages/commitizen/cli.py", line [5](https://github.com/cicd-tools-org/cicd-tools/actions/runs/8175897168/job/22354095523#step:9:5)88, in main
    args.func(conf, arguments)()
  File "/home/runner/.cache/pypoetry/virtualenvs/cicd-tools-3sbBasnr-py3.9/lib/python3.9/site-packages/commitizen/commands/bump.py", line 34[6](https://github.com/cicd-tools-org/cicd-tools/actions/runs/8175897168/job/22354095523#step:9:6), in __call__
    is_initial=is_initial,
UnboundLocalError: local variable 'is_initial' referenced before assignment
Error: Process completed with exit code 1.

Desired behavior

The version to be bumped a minor increment, and the pre_bump script to finish as it did before.

Screenshots

No response

Environment

This is happening both in my Linux CI and on my local OSX machine.

@niall-byrne niall-byrne changed the title Exception thrown during cz bump UnboundLocalError exception thrown during cz bump Mar 6, 2024
@woile
Copy link
Member

woile commented Mar 6, 2024

@noirbizarre do you think it might be related to the new feature?

@noirbizarre
Copy link
Member

noirbizarre commented Mar 6, 2024

I'd say it has been introduced by c245b14, by the --exact feature.

I'll submit a fix in the evening, it seems easy to fix.
Maybe we are missing some tests for pre- and post-bump, I'll take a look at it too.

@noirbizarre
Copy link
Member

There it is, reproduced and fixed in #1007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants