Define components for GitVersion provenance
Adding binary provenance requires we track the commit. Typically this has been an optional form for the encompassing git ref. Moving towards always defining a commit means we need to have space to store a user requested ref that will then be paired with a commit sha.
This commit is contained in:
parent
bd41863797
commit
b56d7e028f
@ -810,6 +810,35 @@ def test_version_list_with_range_and_concrete_version_is_not_concrete():
|
||||
v = VersionList([Version("3.1"), VersionRange(Version("3.1.1"), Version("3.1.2"))])
|
||||
assert not v.concrete
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"pre_equal, post_equal", (
|
||||
("foo", "develop"),
|
||||
("a"*40, "develop"),
|
||||
("a"*40, None),
|
||||
("v1.2.0", "1.2.0")
|
||||
)
|
||||
)
|
||||
def test_git_versions_store_ref_requests(pre_equal, post_equal):
|
||||
"""
|
||||
User requested ref's should be known on creation
|
||||
Commit and standard version may not be known until concretization
|
||||
To be concrete a GitVersion must have a commit and standard version
|
||||
"""
|
||||
if post_equal:
|
||||
vstring = f"git.{pre_equal}={post_equal}"
|
||||
else:
|
||||
vstring = pre_equal
|
||||
|
||||
v = Version(vstring)
|
||||
|
||||
assert isinstance(v, GitVersion)
|
||||
assert v.requested_ref == pre_equal
|
||||
|
||||
if post_equal:
|
||||
assert v.std_version == Version(post_equal)
|
||||
|
||||
if v.is_commit:
|
||||
assert v.requested_ref == v.commit_sha
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"vstring, eq_vstring, is_commit",
|
||||
|
@ -551,6 +551,11 @@ class GitVersion(ConcreteVersion):
|
||||
__slots__ = ["ref", "has_git_prefix", "is_commit", "_ref_lookup", "_ref_version"]
|
||||
|
||||
def __init__(self, string: str):
|
||||
# WIP refactor
|
||||
self.requested_ref: Optional[String] = None
|
||||
self.commit_sha: Optional[String] = None
|
||||
self.std_version: Optional[StandardVersion] = None
|
||||
|
||||
# An object that can lookup git refs to compare them to versions
|
||||
self._ref_lookup: Optional[AbstractRefLookup] = None
|
||||
|
||||
@ -577,6 +582,11 @@ def __init__(self, string: str):
|
||||
# Used by fetcher
|
||||
self.is_commit: bool = len(self.ref) == 40 and bool(COMMIT_VERSION.match(self.ref))
|
||||
|
||||
self.requested_ref = self.ref
|
||||
self.std_version = self._ref_version
|
||||
if self.is_commit:
|
||||
self.commit_sha = self.ref
|
||||
|
||||
@property
|
||||
def ref_version(self) -> StandardVersion:
|
||||
# Return cached version if we have it
|
||||
|
Loading…
Reference in New Issue
Block a user