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

Check for Git > 2.38 #294

Merged
merged 6 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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()
20 changes: 20 additions & 0 deletions pydriller/utils/check_git_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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]
print(git_version)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the print from here?

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()
Loading