From 702ec7835282e984ad98104781c461b2b696c459 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Fri, 28 Feb 2020 17:39:12 +0000 Subject: [PATCH 1/2] Sort by ref not date --- semver/get_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semver/get_version.py b/semver/get_version.py index 6714991..0535a67 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -23,7 +23,7 @@ def get_tag_version(): version = get_file_version(config) # If a version is found in tags, use that the lastest tagged version - tagged_versions = subprocess.Popen(['git','tag','--sort=taggerdate', '-l',tag_expression], + tagged_versions = subprocess.Popen(['git','tag','--sort=v:refname', '-l',tag_expression], stdout=subprocess.PIPE, stderr=DEVNULL, cwd=".").stdout.read().decode('utf-8').rstrip().split('\n') if len(tagged_versions) > 0 and tagged_versions[-1] != "": version = tagged_versions[-1] From 33d8615f16538d4e44cb7f385a8cbd67d883db11 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Fri, 28 Feb 2020 17:59:54 +0000 Subject: [PATCH 2/2] Added tests with mutiple tags & tags out of order --- semver/tests.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/semver/tests.py b/semver/tests.py index ac6555c..a391131 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -74,6 +74,35 @@ class TestGetTagVersion(unittest.TestCase): subprocess.call(['git', 'tag', '1.0.0']) tag = get_version.get_tag_version() self.assertEqual(tag, "1.0.0") + def test_get_version_multiple(self): + create_git_environment() + subprocess.call(['git', 'tag', '0.1.0']) + subprocess.call(['git', 'tag', '0.1.1']) + subprocess.call(['git', 'tag', '0.1.2']) + subprocess.call(['git', 'tag', '0.1.3']) + subprocess.call(['git', 'tag', '0.2.0']) + subprocess.call(['git', 'tag', '0.3.0']) + subprocess.call(['git', 'tag', '0.3.1']) + subprocess.call(['git', 'tag', '1.0.0']) + subprocess.call(['git', 'tag', '1.1.0']) + subprocess.call(['git', 'tag', '1.2.0']) + subprocess.call(['git', 'tag', '1.2.1']) + tag = get_version.get_tag_version() + self.assertEqual(tag, "1.2.1") + def test_get_version_out_of_order(self): + subprocess.call(['git', 'tag', '0.1.0']) + subprocess.call(['git', 'tag', '0.1.1']) + subprocess.call(['git', 'tag', '0.5.2']) + subprocess.call(['git', 'tag', '0.1.3']) + subprocess.call(['git', 'tag', '8.1.0']) + subprocess.call(['git', 'tag', '0.3.8']) + subprocess.call(['git', 'tag', '3.3.1']) + subprocess.call(['git', 'tag', '1.4.0']) + subprocess.call(['git', 'tag', '1.1.7']) + subprocess.call(['git', 'tag', '1.2.0']) + subprocess.call(['git', 'tag', '0.2.1']) + tag = get_version.get_tag_version() + self.assertEqual(tag, "8.1.0") def test_default_get_version_tag(self): create_git_environment() tag = get_version.get_tag_version()