From 521cfe63f6498792426d82b09f83ee8168a8481a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Grimard?= Date: Mon, 5 Sep 2022 17:28:07 +0200 Subject: [PATCH] Fix tag comparison (numerical order) Tag comparison was done using alphabetical ordering instead of numerical ordering. This won't work for releases that uses numbers over 9. Casting each version component to an int will force numerical ordering. The bug can easily be reproduced by creating a dummy repository and adding tags "0.9.0" and "0.10.0". "0.9.0"will be seen as the latest by error. --- src/git_conventional_version/versioning/releases.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/git_conventional_version/versioning/releases.py b/src/git_conventional_version/versioning/releases.py index 0d7e690..4d9bf15 100644 --- a/src/git_conventional_version/versioning/releases.py +++ b/src/git_conventional_version/versioning/releases.py @@ -47,7 +47,7 @@ def _get_version_strings(self) -> List[str]: def _sort_version_strings(self, version_strings: List[str]) -> List[str]: return sorted( version_strings, - key=lambda x: tuple(re.findall(r'\d+', x)), + key=lambda x: tuple([int(i) for i in re.findall(r'\d+', x)]), reverse=True ) @@ -113,4 +113,4 @@ class AlphaRelease(PreRelease): class BetaRelease(PreRelease): """Handles beta versions specifically. """ - version_class = BetaVersion \ No newline at end of file + version_class = BetaVersion