callowayproject / bump-my-version

A small command line tool to simplify releasing software by updating all version strings in your source code by the correct increment and optionally commit and tag the changes.
https://callowayproject.github.io/bump-my-version/
MIT License
349 stars 21 forks source link

Config file not updated when 'current_version' does not match template defined in 'serialize' #182

Closed reindlt closed 6 months ago

reindlt commented 6 months ago

This issue is related to #179.

Given the following config:

current_version = "1.0.0"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor:02d}.{patch}"]
search = "{current_version}"
replace = "{new_version}"

The config file's current version is not updated due to a regex pattern mismatch. Thus, committing also fails.

I wouldn't say that this is an error per se as one would assume that current_version should match the pattern specified in serialize but I saw that there are multiple entries for current_version in context when the regex pattern is determined and it is picking the zero-padded one instead of the one which is specified in the config.

If this could be solved without much effort I would be happy. Otherwise I'm also fine.

coordt commented 6 months ago

Could you paste in the output of what happens when you do a bump but add -vv into the command to turn on verbose output?

That would help me identify where the problem is.

reindlt commented 6 months ago
[tool.bumpversion]
current_version = "1.0.0"
serialize = ["{major}.{minor:02}.{patch}"]
tag = true
commit = true
allow_dirty = true
Starting BumpVersion 0.20.2
Reading configuration
  Reading config file: ***\.bumpversion.toml
  Parsing current version '1.0.0'
    Parsing version '1.0.0' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'
      Parsed the following values: major=1, minor=0, patch=0
  Attempting to increment part 'minor'
    Values are now: major=1, minor=1, patch=0
  Serializing version '<bumpversion.Version:major=1, minor=1, patch=0>'
    Using serialization format '{major}.{minor:02}.{patch}'
    Serialized to '1.01.0'
  New version will be '1.01.0'

Processing config file: ***\.bumpversion.toml
  Serializing version '<bumpversion.Version:major=1, minor=0, patch=0>'
    Using serialization format '{major}.{minor:02}.{patch}'
    Serialized to '1.00.0'
  Serializing version '<bumpversion.Version:major=1, minor=1, patch=0>'
    Using serialization format '{major}.{minor:02}.{patch}'
    Serialized to '1.01.0'
  Rendering search pattern with context
    No RegEx flag detected. Searching for the default pattern: '1\.00\.0'
  Not changing file ***\.bumpversion.toml:tool.bumpversion.current_version
Preparing Git commit
  Adding changes in file '***\.bumpversion.toml' to Git
  Committing to Git with message 'Bump version: 1.0.0 → 1.01.0'
  Failed to run ['git', 'commit', '-F', '***\\AppData\\Local\\Temp\\tmpaxtkaxbo']: return code 1, output:
b'On branch main\nYour branch is up to date with \'origin/main\'.\n\n...'
reindlt commented 6 months ago

@coordt any news on this one?

coordt commented 6 months ago

So here is the story: The logic for changing the config file intentionally does not change mismatching contents to avoid accidents.

I believe this mismatch should only be temporary or a true error. I'm willing to hear how this might be a long-term problem and what methods are available to prevent this behavior.

reindlt commented 6 months ago

Ok, thanks for clarification. For me the linked error is not raised as ignore_missing_version seems to be always set to true here.

But anyways, I am fine with it as it should only be relevant in case the versioning scheme changes.