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

Verify the version of user's installed Git is acceptable #1915

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changes/1915.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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.
21 changes: 17 additions & 4 deletions src/briefcase/integrations/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class Git(Tool):
name = "git"
full_name = "Git"

MIN_VERSION = (2, 17, 0)
GIT_URL = "https://git-scm.com/"

@classmethod
def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:
"""Verify if git is installed.
Expand Down Expand Up @@ -42,14 +45,14 @@ def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:
# for this.
if tools.host_os == "Darwin":
raise BriefcaseCommandError(
"""\
f"""\
Briefcase requires git, but it is not installed. Xcode provides git; you should
be shown a dialog prompting you to install Xcode and the Command Line Developer
Tools. Select "Install" to install the Command Line Developer Tools.

Alternatively, you can visit:

https://git-scm.com/
{cls.GIT_URL}

to download and install git manually.

Expand All @@ -60,10 +63,10 @@ def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:

else:
raise BriefcaseCommandError(
"""\
f"""\
Briefcase requires git, but it is not installed (or is not on your PATH). Visit:

https://git-scm.com/
{cls.GIT_URL}

to download and install git manually.

Expand All @@ -72,6 +75,16 @@ def verify_install(cls, tools: ToolCache, **kwargs) -> ModuleType:
"""
) from e

installed_version = git.cmd.Git().version_info
if installed_version < cls.MIN_VERSION:
raise BriefcaseCommandError(
f"At least Git v{'.'.join(map(str, cls.MIN_VERSION))} is required; "
f"however, v{'.'.join(map(str, installed_version))} is installed.\n"
"\n"
f"Please update Git; downloads are available at {cls.GIT_URL}.",
skip_logfile=True,
)

tools.logger.configure_stdlib_logging("git")

tools.git = git
Expand Down
32 changes: 31 additions & 1 deletion tests/integrations/git/test_Git__verify.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
from unittest.mock import PropertyMock

import git
import pytest

from briefcase.console import LogLevel, RichLoggingHandler
from briefcase.exceptions import UnsupportedHostError
from briefcase.exceptions import BriefcaseCommandError, UnsupportedHostError
from briefcase.integrations.git import Git


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

# reset handlers since they are persistent
logging.getLogger("git").handlers.clear()


@pytest.mark.parametrize("version", [(2, 17, 0), (2, 45, 2), (3, 0, 0)])
def test_git_version_valid(mock_tools, version, monkeypatch):
"""A valid Git version is accepted."""
monkeypatch.setattr(
git.cmd.Git,
"version_info",
PropertyMock(return_value=version),
)

Git.verify(mock_tools)


@pytest.mark.parametrize("version", [(2, 16, 6), (2, 13, 2), (1, 0, 0)])
def test_git_version_invalid(mock_tools, version, monkeypatch):
"""An invalid Git version is rejected."""
monkeypatch.setattr(
git.cmd.Git,
"version_info",
PropertyMock(return_value=version),
)

with pytest.raises(
BriefcaseCommandError,
match=f"At least Git v2.17.0 is required; however, v{'.'.join(map(str, version))} is installed.",
):
Git.verify(mock_tools)