Skip to content

Conversation

@bearomorphism
Copy link
Collaborator

@bearomorphism bearomorphism commented Dec 12, 2025

Closes #1679

Manually tested and added test cases, the result LGTM.

@bearomorphism
Copy link
Collaborator Author

@Lee-W I already ran pytest tests/commands/test_version_command.py -n auto --regen-all to regenerate the test files, but the pipeline still fails. (The tests passed on my machine)

Do you have any ideas why this happen

version = f"{version_scheme.minor}"
out.write(version.major)
return
if self.arguments.get("minor"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize now that this creates problems with the (not)monotonic kind of versions (and possible non-semver). I'm not sure what to do about it.

I think for now it's fine that if you diverge too much from semver in your custom version scheme, then you won't get the full range of features.

@woile
Copy link
Member

woile commented Dec 12, 2025

There was a way to run all the pre-commits, but I don't remember how it works 😅



@pytest.mark.parametrize(
"next_version, current_version, expected_version",
Copy link
Member

@woile woile Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename next_version to next_increment?
In the user facing cli, it makes sense semantically: --next=MAJOR (give me the next major).

assert expected_version in captured.out


def test_next_version_invalid_version(config, capsys):
Copy link
Member

@woile woile Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about having a parametrize of the combinations that should fail:

@pytest.mark.parametrize(
    "args",
    [
        # incomplete list:
        {"next"},
        # ...
        {"--verbose", "next"}
    ]
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

out.error("Invalid version.")
return

if next_str := self.arguments.get("next"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would happen here if I run cz version --project --next? I would expect that to work

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior is the same as cz version --next=*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what would be the output?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I misunderstood your question. The output should depend on the commit history, right?
I forgot to implement that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do #1678 in another PR since it's a bit complicated (we need to consider major_version_zero, bump_map, etc. for this feature and I prefer not to just copy & paste code, need some refactoring)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that logic should be core and it should be possible to re-use it across commands.

@woile
Copy link
Member

woile commented Dec 12, 2025

Nice to see this going forward 🎉

@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

❌ Patch coverage is 97.10145% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.81%. Comparing base (1d89195) to head (c3d27c9).

Files with missing lines Patch % Lines
commitizen/commands/version.py 94.73% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1724      +/-   ##
==========================================
- Coverage   97.88%   97.81%   -0.08%     
==========================================
  Files          60       61       +1     
  Lines        2606     2649      +43     
==========================================
+ Hits         2551     2591      +40     
- Misses         55       58       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bearomorphism
Copy link
Collaborator Author

@Lee-W I already ran pytest tests/commands/test_version_command.py -n auto --regen-all to regenerate the test files, but the pipeline still fails. (The tests passed on my machine)

Do you have any ideas why this happen

I see why the test failure happens. Please see my other PR #1726 .

@bearomorphism
Copy link
Collaborator Author

I will rebase this branch after #1726 is merged. The test failure should be resolved then.

@bearomorphism bearomorphism force-pushed the feat-next-version branch 3 times, most recently from 8d938d2 to f9afbd4 Compare December 14, 2025 14:08
@bearomorphism bearomorphism changed the base branch from v4-11-0 to master December 29, 2025 11:11
@bearomorphism bearomorphism force-pushed the feat-next-version branch 3 times, most recently from 3b48a33 to b07121e Compare January 3, 2026 17:24
Copy link
Member

@noirbizarre noirbizarre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting feature, one that I would totally use!

Also, I never realized that the version command was doing totally different things depending on the flags 😅
So maybe it's the occasion to have a dedicated --version flag and have the version command focusing on the the project versioning and not the Commitizen version. It would be cleaner, easier to understand and more standard. WDYT ?

Note

I would not remove the Type aliases as it makes the PR bigger than it should and it introduce a breaking change (and reading the PR and issues, we know that it has been used by some users for some custom version schemes).

return self.name

@classmethod
def safe_cast(cls, value: object) -> "VersionIncrement":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add from __future__ import annotations and remove the quotes to stay consistent with the existing code base.

Also it's not a cast but an instantiation, so maybe rename this in from_value()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc there is a ruff rule for this. will check later when I have a moment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noirbizarre
Copy link
Member

Also, the enumn part seems to overlap with #1518, so maybe #1518 should go first so this PR can reuse the Increment enum

@bearomorphism
Copy link
Collaborator Author

Also, the enumn part seems to overlap with #1518, so maybe #1518 should go first so this PR can reuse the Increment enum

I would prefer to merge this before #1518 because it is a bit larger than this PR.

So maybe it's the occasion to have a dedicated --version flag and have the version command focusing on the the project versioning and not the Commitizen version. It would be cleaner, easier to understand and more standard. WDYT ?

+1. As a user, I often run cz --version and end up seeing an error. We can create another work item about adding the dedicated flag and then deprecate cz version --commitizen and other removable flags in the next major version.

@woile
Copy link
Member

woile commented Jan 5, 2026

We had a --version in the past, but it was replaced by version, do you remember why @Lee-W ?
It would be a breaking change if we go that route. If agreed, I can add it as a different task on the parent issue tracking this work #1677

@bearomorphism bearomorphism force-pushed the feat-next-version branch 4 times, most recently from 575468d to 3af1a57 Compare January 6, 2026 13:24
@bearomorphism bearomorphism marked this pull request as ready for review January 6, 2026 13:26
@bearomorphism bearomorphism changed the title feat(version): add MANUAL_VERSION, --next and --patch to version comm… feat(version): add MANUAL_VERSION, --next and --patch to version command Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for cz version <version_arg>

3 participants