Do not mock git_helper.Git, suppress git describe error for ignore_no_tags

This commit is contained in:
Mikhail f. Shiryaev 2023-06-15 15:11:30 +02:00
parent 2ac95ccfce
commit eb2a5c31a3
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 6 additions and 10 deletions

View File

@ -10,9 +10,8 @@ from pr_info import PRInfo
from report import TestResult from report import TestResult
import docker_images_check as di import docker_images_check as di
with patch("git_helper.Git"): from version_helper import get_version_from_string
from version_helper import get_version_from_string import docker_server as ds
import docker_server as ds
# di.logging.basicConfig(level=di.logging.INFO) # di.logging.basicConfig(level=di.logging.INFO)
@ -312,7 +311,3 @@ class TestDockerServer(unittest.TestCase):
for case in cases_equal: for case in cases_equal:
release = ds.auto_release_type(case[0], "auto") release = ds.auto_release_type(case[0], "auto")
self.assertEqual(case[1], release) self.assertEqual(case[1], release)
if __name__ == "__main__":
unittest.main()

View File

@ -126,15 +126,16 @@ class Git:
# Format should match TAG_REGEXP # Format should match TAG_REGEXP
if self._ignore_no_tags and is_shallow(): if self._ignore_no_tags and is_shallow():
try: try:
self._update_tags() self._update_tags(True)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
pass pass
return return
self._update_tags() self._update_tags()
def _update_tags(self): def _update_tags(self, suppress_stderr: bool = False) -> None:
self.latest_tag = self.run("git describe --tags --abbrev=0") stderr = subprocess.DEVNULL if suppress_stderr else None
self.latest_tag = self.run("git describe --tags --abbrev=0", stderr=stderr)
# Format should be: {latest_tag}-{commits_since_tag}-g{sha_short} # Format should be: {latest_tag}-{commits_since_tag}-g{sha_short}
self.description = self.run("git describe --tags --long") self.description = self.run("git describe --tags --long")
self.commits_since_tag = int( self.commits_since_tag = int(