Support v<semver> version

Allow protect tag (in gitlab, github) using "v*" regex.

Change-Id: I3e6eb1031ae92349c5a9531b143b6470482664e7
Signed-off-by: Gaetan Semet <gaetan@xeberon.net>
This commit is contained in:
Gaetan Semet 2018-01-05 14:31:03 +01:00 committed by Stephen Finucane
parent 4e859e76d3
commit 4c775e7890
4 changed files with 25 additions and 0 deletions

View File

@ -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

View File

@ -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(

View File

@ -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('.')

View File

@ -0,0 +1,5 @@
---
features:
- |
Support version parsing of git tag with the ``v<semver>`` pattern
(or ``V<semver>``), in addition to ``<semver>``.