Skip to content

Commit

Permalink
Merge pull request #294 from alaws-scottlogic/git-version-check
Browse files Browse the repository at this point in the history
Check for Git > 2.38
  • Loading branch information
ishepard authored Jul 20, 2024
2 parents 3d3d917 + 762f46c commit c9fbefc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pydriller/domain/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from pydriller.utils.check_git_version import CheckGitVersion


CheckGitVersion().check_git_version()
19 changes: 19 additions & 0 deletions pydriller/utils/check_git_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import subprocess
import re


class GitVersion(Exception):
def __init__(self, message):
super().__init__(message)


class CheckGitVersion:
def check_git_version(self):
git_version = (
subprocess.check_output(["git", "--version"]).decode("ascii").strip()
)
version_number = re.findall(r"[0-9]+\.[0-9]+", git_version)[0]
if float(version_number) < 2.38:
raise GitVersion(
f"Current git version is {version_number}. Minimum supported version is 2.38."
)
3 changes: 2 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mock
types-mock
pytest
psutil
psutil
pytest-mock
24 changes: 24 additions & 0 deletions tests/test_check_git_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from unittest.mock import patch
from pydriller.utils.check_git_version import CheckGitVersion, GitVersion
from contextlib import nullcontext as does_not_raise

import pytest


@pytest.mark.parametrize(
"version_number,expectation",
[
("3.2.0", does_not_raise()),
("2.38.1", does_not_raise()),
("2.0.0", pytest.raises(GitVersion)),
],
)
def test_extracts_correct_version(version_number, expectation):
with patch(
"pydriller.utils.check_git_version.subprocess.check_output"
) as mock_git_version:
mock_git_version().decode.return_value.strip.return_value = (
f"git version {version_number}"
)
with expectation:
CheckGitVersion().check_git_version()

0 comments on commit c9fbefc

Please sign in to comment.