-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_git_version.py
More file actions
37 lines (28 loc) · 1.18 KB
/
check_git_version.py
File metadata and controls
37 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from subprocess import run, PIPE
import re
class GitVersionError(Exception):
"""Custom exception for Git version compatibility issues."""
pass
def validate_git_installation():
"""
Validates if the installed Git version meets the minimum requirement (2.38).
Raises:
GitVersionError: If Git version is below 2.38
"""
try:
# Execute git version command and capture output
result = run(["git", "--version"], stdout=PIPE, text=True)
version_string = result.stdout.strip()
# Extract version number using regex
match = re.search(r"(\d+\.\d+)", version_string)
if not match:
raise GitVersionError("Unable to determine Git version")
installed_version = float(match.group(1))
MINIMUM_VERSION = 2.38
if installed_version < MINIMUM_VERSION:
raise GitVersionError(
f"Git version {installed_version} is not supported. "
f"Please upgrade to version {MINIMUM_VERSION} or higher."
)
except FileNotFoundError:
raise GitVersionError("Git is not installed or not found in system PATH")