Skip to content

Commit 77cb18e

Browse files
authored
Merge pull request #1915 from rmartin16/verify-git-version
Verify the version of user's installed Git is acceptable
2 parents 4628336 + d79650d commit 77cb18e

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

changes/1915.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When the available version if Git is older than v2.17.0, an error message now prompts the user to upgrade their install of Git to proceed.

src/briefcase/integrations/git.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class Git(Tool):
1010
name = "git"
1111
full_name = "Git"
1212

13+
MIN_VERSION = (2, 17, 0)
14+
GIT_URL = "https://git-scm.com/"
15+
1316
@classmethod
1417
def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:
1518
"""Verify if git is installed.
@@ -42,14 +45,14 @@ def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:
4245
# for this.
4346
if tools.host_os == "Darwin":
4447
raise BriefcaseCommandError(
45-
"""\
48+
f"""\
4649
Briefcase requires git, but it is not installed. Xcode provides git; you should
4750
be shown a dialog prompting you to install Xcode and the Command Line Developer
4851
Tools. Select "Install" to install the Command Line Developer Tools.
4952
5053
Alternatively, you can visit:
5154
52-
https://git-scm.com/
55+
{cls.GIT_URL}
5356
5457
to download and install git manually.
5558
@@ -60,10 +63,10 @@ def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:
6063

6164
else:
6265
raise BriefcaseCommandError(
63-
"""\
66+
f"""\
6467
Briefcase requires git, but it is not installed (or is not on your PATH). Visit:
6568
66-
https://git-scm.com/
69+
{cls.GIT_URL}
6770
6871
to download and install git manually.
6972
@@ -72,6 +75,16 @@ def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:
7275
"""
7376
) from e
7477

78+
installed_version = git.cmd.Git().version_info
79+
if installed_version < cls.MIN_VERSION:
80+
raise BriefcaseCommandError(
81+
f"At least Git v{'.'.join(map(str, cls.MIN_VERSION))} is required; "
82+
f"however, v{'.'.join(map(str, installed_version))} is installed.\n"
83+
"\n"
84+
f"Please update Git; downloads are available at {cls.GIT_URL}.",
85+
skip_logfile=True,
86+
)
87+
7588
tools.logger.configure_stdlib_logging("git")
7689

7790
tools.git = git

tests/integrations/git/test_Git__verify.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import logging
2+
from unittest.mock import PropertyMock
23

4+
import git
35
import pytest
46

57
from briefcase.console import LogLevel, RichLoggingHandler
6-
from briefcase.exceptions import UnsupportedHostError
8+
from briefcase.exceptions import BriefcaseCommandError, UnsupportedHostError
79
from briefcase.integrations.git import Git
810

911

@@ -49,3 +51,31 @@ def test_git_stdlib_logging(mock_tools, logging_level, handler_expected):
4951

5052
# reset handlers since they are persistent
5153
logging.getLogger("git").handlers.clear()
54+
55+
56+
@pytest.mark.parametrize("version", [(2, 17, 0), (2, 45, 2), (3, 0, 0)])
57+
def test_git_version_valid(mock_tools, version, monkeypatch):
58+
"""A valid Git version is accepted."""
59+
monkeypatch.setattr(
60+
git.cmd.Git,
61+
"version_info",
62+
PropertyMock(return_value=version),
63+
)
64+
65+
Git.verify(mock_tools)
66+
67+
68+
@pytest.mark.parametrize("version", [(2, 16, 6), (2, 13, 2), (1, 0, 0)])
69+
def test_git_version_invalid(mock_tools, version, monkeypatch):
70+
"""An invalid Git version is rejected."""
71+
monkeypatch.setattr(
72+
git.cmd.Git,
73+
"version_info",
74+
PropertyMock(return_value=version),
75+
)
76+
77+
with pytest.raises(
78+
BriefcaseCommandError,
79+
match=f"At least Git v2.17.0 is required; however, v{'.'.join(map(str, version))} is installed.",
80+
):
81+
Git.verify(mock_tools)

0 commit comments

Comments
 (0)