Skip to content

cz bump could not find the latest version tag to do incremental changelog when there is custom tag_format #561

Description

@ssiuhk

Description

cz bump could not find the latest version tag to do incremental changelog when there is custom tag_format in git tags for versions

Steps to reproduce

  1. Create a release 1.0.0
  2. Create a custom git tag SOME_TAG_PREFIX_1.0.0
  3. Add a new feature commit
  4. Run cz bump to try to determine new version

Current behavior

cz bump cannot find tag to do an incremental changelog

$ cat .cz.toml | grep tag_format
tag_format = "SOME_TAG_PREFIX_$version"
$ git tag
SOME_TAG_PREFIX_1.0.0

$ git log
commit 11ba99fd2907be046e814662e3057c4bdd9f3db0 (HEAD -> master)
Author: Sam SIU <23556929+ssiuhk@users.noreply.github.com>
Date:   Fri Aug 19 19:35:08 2022 +0000

    feat(Testing): Testing something

commit db20a16f6ed45ef1470b131f65c9006b094c4a58 (tag: SOME_TAG_PREFIX_1.0.0)
Author: Sam SIU <23556929+ssiuhk@users.noreply.github.com>
Date:   Fri Aug 19 18:54:18 2022 +0000

    First release
$ cz bump --dry-run --changelog
bump: version 1.0.0 → 1.1.0
tag to create: SOME_TAG_PREFIX_1.1.0
increment detected: MINOR

No tag found to do an incremental changelog

Desired behavior

cz bump should identify the custom git tag and create an incremental changelog

$ cz bump --dry-run --changelog
bump: version 1.0.0 → 1.1.0
tag to create: SOME_TAG_PREFIX_1.1.0
increment detected: MINOR

## SOME_TAG_PREFIX_1.1.0 (2022-08-19)

### Feat

- **Testing**: Testing something

Screenshots

No response

Environment

commitizen/commands/changelog.py
_find_incremental_rev()

$ cz bump --dry-run --changelog
bump: version 1.0.0 → 1.1.0
tag to create: SOME_TAG_PREFIX_1.1.0
increment detected: MINOR

> commitizen/commands/changelog.py(71)_find_incremental_rev()
-> tag_ratio = map(
(Pdb) n
> commitizen/commands/changelog.py(72)_find_incremental_rev()
-> lambda tag: (SequenceMatcher(None, latest_version, tag.name).ratio(), tag),
(Pdb) n
> commitizen/commands/changelog.py(73)_find_incremental_rev()
-> tags,
(Pdb) latest_version
'1.0.0'
(Pdb) tags
[GitTag('SOME_TAG_PREFIX_1.0.0', 'db20a16f6ed45ef1470b131f65c9006b094c4a58', '2022-08-19')]
(Pdb) n
> commitizen/commands/changelog.py(75)_find_incremental_rev()
-> try:
(Pdb) n
> commitizen/commands/changelog.py(76)_find_incremental_rev()
-> score, tag = max(tag_ratio, key=itemgetter(0))
(Pdb) n
> commitizen/commands/changelog.py(79)_find_incremental_rev()
-> if score < SIMILARITY_THRESHOLD:
(Pdb) score
0.38461538461538464

Activity

  1. Lee-W commented on Aug 21, 2022

    @Lee-W
    Member

    Hi @ssiuhk, I'm afraid I can not reproduce your error. But we do notice we might encounter such issue and have discussion on #463 (comment).

  2. Lee-W commented on Aug 21, 2022

    @Lee-W
    Member

    As these seems to be duplicate issues. I'll close this one for now and let's discuss on that one 👍

  3. added a commit that references this issue on Aug 21, 2022
  4. ssiuhk commented on Aug 22, 2022

    @ssiuhk
    ContributorAuthor

    @Lee-W Not entirely sure it's the same issue with #463, as per latest comment even without git tag it failed in #463.
    For my case it's simple, as illustrated in above report, when the git tag prefix is long, like "SOME_TAG_PREFIX_", the similarity reported will be extremely low "0.38461538461538464" (for "SOME_TAG_PREFIX_1.0.0" vs "1.0.0" in comparison). The fix is simple, just add tag_format in version when calling _find_incremental_rev in command/changelog.py per my PR #566. This will fix the issue of discreprency between looking-up version in custom formatted git taged versions.
    Please review.

    Thanks!

  5. added a commit that references this issue on Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions