Add version attribute restrictions for commit variant

This commit is contained in:
Philip Sakievich 2025-02-15 07:08:06 -07:00 committed by psakiev
parent 1199b1ef99
commit f070163a37
2 changed files with 12 additions and 5 deletions

View File

@ -4280,7 +4280,7 @@ def _specs_with_commits(spec):
# Specs with commit variants
# - variant value satsifies commit regex
# - paired to a GitVersion or can create GitVersion from version that was selected
# - paired to a GitVersion or version that is associated with a branch/tag
# - variant value should match GitVersion's commit value
if has_commit_var:
invalid_commit_msg = (
@ -4300,6 +4300,11 @@ def _specs_with_commits(spec):
return
spec.variants["commit"] = vt.SingleValuedVariant("commit", spec.version.commit_sha)
else:
# if we are not a GitVersion then only versions with a branch or tag should be
# allowed to have the commit variant
version_dict = spec.package_class.versions.get(spec.version, {})
assert version_dict.get("branch") or version_dict.get("tag")
def _develop_specs_from_env(spec, env):

View File

@ -3313,7 +3313,9 @@ def _ensure_cache_hits(self, problem: str):
[
(f"git-ref-package@main commit={'a' * 40}", True, None),
(f"git-ref-package@main commit={'a' * 39}", False, AssertionError),
# TODO only versions with git refs should allow the commit variant
(f"git-ref-package@2.1.6 commit={'a' * 40}", False, AssertionError),
(f"git-ref-package@git.2.1.6=2.1.6 commit={'a' * 40}", True, None),
(f"git-ref-package@2.1.6 commit={'a' * 40}", False, AssertionError),
],
)
def test_spec_containing_commit_variant(spec_str, should_pass, error_type):