diff --git a/module_build_service/scm.py b/module_build_service/scm.py index a241c95d..8444d25f 100644 --- a/module_build_service/scm.py +++ b/module_build_service/scm.py @@ -98,8 +98,6 @@ class SCM(object): self.name = self.name[:-4] self.commit = match.group("commit") self.branch = branch if branch else "master" - if not self.commit: - self.commit = self.get_latest(self.branch) self.version = None else: raise ValidationError("Unhandled SCM scheme: %s" % self.scheme) @@ -351,6 +349,9 @@ class SCM(object): @property def commit(self): """The commit ID, for example the git hash, or None.""" + if not self._commit: + self._commit = self.get_latest(self.branch) + return self._commit @commit.setter diff --git a/tests/test_scm.py b/tests/test_scm.py index a3f1bd80..38678a26 100644 --- a/tests/test_scm.py +++ b/tests/test_scm.py @@ -93,7 +93,10 @@ class TestSCMModule: def test_verify_unknown_branch(self): with pytest.raises(UnprocessableEntity): - module_build_service.scm.SCM(repo_url, "unknown") + scm = module_build_service.scm.SCM(repo_url, "unknown") + # Accessing the commit property will cause the commit to be resolved, causing an + # exception + scm.commit def test_verify_commit_in_branch(self): target = "7035bd33614972ac66559ac1fdd019ff6027ad21"