Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/test_repo_utils: correctly parse system git version #1993

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions teuthology/test/test_repo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import os.path
from pytest import raises, mark
import re
import shutil
import subprocess
import tempfile
Expand All @@ -29,14 +30,21 @@ def setup_class(cls):
cls.repo_url = 'file://' + cls.src_path
cls.commit = None

cls.git_version = parse(
subprocess.check_output(('git', 'version')
).decode().strip().split(' ')[-1])
cls.git_version = parse(cls.get_system_git_version())

@classmethod
def teardown_class(cls):
shutil.rmtree(cls.temp_path)

@classmethod
def get_system_git_version(cls):
# parsing following patterns
# 1) git version 2.45.2
# 2) git version 2.39.3 (Apple Git-146)
git_version = subprocess.check_output(('git', 'version')).decode()
m = re.match(r"git version (?P<ver>\d+.\d+.\d+) ?", git_version)
return m['ver']

def setup_method(self, method):
# In git 2.28.0, the --initial-branch flag was added.
if self.git_version >= parse("2.28.0"):
Expand Down Expand Up @@ -239,4 +247,4 @@ def test_url_to_dirname(self, input_, expected):

def test_current_branch(self):
repo_utils.clone_repo(self.repo_url, self.dest_path, 'main', self.commit)
assert repo_utils.current_branch(self.dest_path) == "main"
assert repo_utils.current_branch(self.dest_path) == "main"