From 4c775e7890e90fc2ea77c66020659e52d6a61414 Mon Sep 17 00:00:00 2001 From: Gaetan Semet Date: Fri, 5 Jan 2018 14:31:03 +0100 Subject: Support v version Allow protect tag (in gitlab, github) using "v*" regex. Change-Id: I3e6eb1031ae92349c5a9531b143b6470482664e7 Signed-off-by: Gaetan Semet --- doc/source/user/features.rst | 6 ++++++ pbr/tests/test_version.py | 13 +++++++++++++ pbr/version.py | 1 + releasenotes/notes/v_version-457b38c8679c5868.yaml | 5 +++++ 4 files changed, 25 insertions(+) create mode 100644 releasenotes/notes/v_version-457b38c8679c5868.yaml diff --git a/doc/source/user/features.rst b/doc/source/user/features.rst index 2a4c25c..fb82255 100644 --- a/doc/source/user/features.rst +++ b/doc/source/user/features.rst @@ -17,6 +17,12 @@ If the currently checked out revision is not tagged, then we take the last tagged version number and increment it to get a minimum target version. +.. note:: + + ``pbr`` support bare version tag (ex: ``0.1.0``) and version prefixed with + ``v`` or ``V`` (ex: ``v0.1.0``) + + We then walk git history back to the last release. Within each commit we look for a Sem-Ver: pseudo header, and if found parse it looking for keywords. Unknown symbols are not an error (so that folk can't wedge pbr or break their diff --git a/pbr/tests/test_version.py b/pbr/tests/test_version.py index 14c8d17..d861d57 100644 --- a/pbr/tests/test_version.py +++ b/pbr/tests/test_version.py @@ -84,6 +84,19 @@ class TestSemanticVersion(base.BaseTestCase): lambda: from_pip_string('1.2.3.post5.dev6'), matchers.raises(ValueError)) + def test_from_pip_string_v_version(self): + parsed = from_pip_string('v1.2.3') + expected = version.SemanticVersion(1, 2, 3) + self.expectThat(expected, matchers.Equals(parsed)) + + expected = version.SemanticVersion(1, 2, 3, 'a', 5, dev_count=6) + parsed = from_pip_string('V1.2.3.0a4.post6') + self.expectThat(expected, matchers.Equals(parsed)) + + self.expectThat( + lambda: from_pip_string('x1.2.3'), + matchers.raises(ValueError)) + def test_from_pip_string_legacy_nonzero_lead_in(self): # reported in bug 1361251 expected = version.SemanticVersion( diff --git a/pbr/version.py b/pbr/version.py index 474faf1..5eb217a 100644 --- a/pbr/version.py +++ b/pbr/version.py @@ -149,6 +149,7 @@ class SemanticVersion(object): @classmethod def _from_pip_string_unsafe(klass, version_string): # Versions need to start numerically, ignore if not + version_string = version_string.lstrip('vV') if not version_string[:1].isdigit(): raise ValueError("Invalid version %r" % version_string) input_components = version_string.split('.') diff --git a/releasenotes/notes/v_version-457b38c8679c5868.yaml b/releasenotes/notes/v_version-457b38c8679c5868.yaml new file mode 100644 index 0000000..696ba41 --- /dev/null +++ b/releasenotes/notes/v_version-457b38c8679c5868.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Support version parsing of git tag with the ``v`` pattern + (or ``V``), in addition to ````. -- cgit v1.2.1