Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e0e144c

Browse filesBrowse files
committed
!squash git version
1 parent b951173 commit e0e144c
Copy full SHA for e0e144c

File tree

Expand file treeCollapse file tree

3 files changed

+11
-58
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+11
-58
lines changed

‎src/libvcs/cmd/git.py

Copy file name to clipboardExpand all lines: src/libvcs/cmd/git.py
+7-20Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ class InvalidBuildOptions(ValueError):
2020
"""Raised when a git version output is in an unexpected format.
2121
2222
>>> InvalidBuildOptions("...")
23-
Traceback (most recent call last):
24-
...
25-
libvcs.cmd.git.InvalidBuildOptions: Unexpected git version output format: ...
23+
InvalidBuildOptions('Unexpected git version output format: ...')
2624
"""
2725

2826
def __init__(self, version: str, *args: object) -> None:
@@ -1787,18 +1785,12 @@ def config(
17871785
def version(
17881786
self,
17891787
*,
1790-
build_options: bool | None = None,
17911788
# libvcs special behavior
17921789
check_returncode: bool | None = None,
17931790
**kwargs: t.Any,
17941791
) -> Version:
17951792
"""Get git version. Wraps `git version <https://git-scm.com/docs/git-version>`_.
17961793
1797-
Parameters
1798-
----------
1799-
build_options : bool, optional
1800-
Include build options in the output with ``--build-options``
1801-
18021794
Returns
18031795
-------
18041796
Version
@@ -1816,16 +1808,9 @@ def version(
18161808
>>> version = git.version()
18171809
>>> isinstance(version.major, int)
18181810
True
1819-
1820-
>>> version = git.version(build_options=True)
1821-
>>> isinstance(version.major, int)
1822-
True
18231811
"""
18241812
local_flags: list[str] = []
18251813

1826-
if build_options is True:
1827-
local_flags.append("--build-options")
1828-
18291814
output = self.run(
18301815
["version", *local_flags],
18311816
check_returncode=check_returncode,
@@ -1837,7 +1822,7 @@ def version(
18371822
return parse_version(version_str)
18381823

18391824
# Raise exception if output format is unexpected
1840-
raise InvalidVersion(f"Unexpected git version output format: {output}")
1825+
raise InvalidVersion(output)
18411826

18421827
def build_options(
18431828
self,
@@ -1880,7 +1865,7 @@ def build_options(
18801865
# First line is always "git version X.Y.Z"
18811866
lines = output.strip().split("\n")
18821867
if not lines or not lines[0].startswith("git version "):
1883-
raise InvalidBuildOptions(f"Unexpected git version output format: {output}")
1868+
raise InvalidBuildOptions(output)
18841869

18851870
version_str = lines[0].replace("git version ", "").strip()
18861871
result.version = version_str
@@ -1916,8 +1901,10 @@ def build_options(
19161901
result.sizeof_size_t = value
19171902
elif key == "shell-path":
19181903
result.shell_path = value
1919-
# Special handling for the commit line which often has no colon
1920-
elif "commit" in line and "no commit" not in line.lower():
1904+
elif key == "commit":
1905+
result.commit = value
1906+
# Special handling for the "no commit" line which has no colon
1907+
elif "no commit associated with this build" in line.lower():
19211908
result.commit = line
19221909

19231910
return result

‎src/libvcs/sync/git.py

Copy file name to clipboardExpand all lines: src/libvcs/sync/git.py
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,8 @@ def get_git_version(self) -> str:
658658
-------
659659
git version
660660
"""
661-
VERSION_PFX = "git version "
662661
version = self.cmd.version()
663-
if version.startswith(VERSION_PFX):
664-
version = version[len(VERSION_PFX) :].split()[0]
665-
else:
666-
version = ""
667-
return ".".join(version.split(".")[:3])
662+
return ".".join([str(x) for x in (version.major, version.minor, version.micro)])
668663

669664
def status(self) -> GitStatus:
670665
"""Retrieve status of project in dict format.

‎tests/cmd/test_git.py

Copy file name to clipboardExpand all lines: tests/cmd/test_git.py
+3-32Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99

10-
from libvcs._vendor.version import Version
10+
from libvcs._vendor.version import InvalidVersion, Version
1111
from libvcs.cmd import git
1212

1313

@@ -36,35 +36,6 @@ def test_version_basic(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path)
3636
assert str(result) == "2.43.0"
3737

3838

39-
def test_version_with_build_options(
40-
monkeypatch: pytest.MonkeyPatch,
41-
tmp_path: pathlib.Path,
42-
) -> None:
43-
"""Test git version with build options."""
44-
git_cmd = git.Git(path=tmp_path)
45-
46-
sample_output = """git version 2.43.0
47-
cpu: x86_64
48-
no commit associated with this build
49-
sizeof-long: 8
50-
sizeof-size_t: 8
51-
shell-path: /bin/sh"""
52-
53-
def mock_run(cmd_args: list[str], **kwargs: t.Any) -> str:
54-
assert cmd_args == ["version", "--build-options"]
55-
assert kwargs.get("check_returncode") is None
56-
return sample_output
57-
58-
monkeypatch.setattr(git_cmd, "run", mock_run)
59-
60-
result = git_cmd.version(build_options=True)
61-
assert isinstance(result, Version)
62-
assert result.major == 2
63-
assert result.minor == 43
64-
assert result.micro == 0
65-
assert str(result) == "2.43.0"
66-
67-
6839
def test_build_options(monkeypatch: pytest.MonkeyPatch, tmp_path: pathlib.Path) -> None:
6940
"""Test build_options() method."""
7041
git_cmd = git.Git(path=tmp_path)
@@ -132,10 +103,10 @@ def test_version_invalid_format(
132103

133104
monkeypatch.setattr(git_cmd, "run", lambda *args, **kwargs: invalid_output)
134105

135-
with pytest.raises(git.InvalidVersion) as excinfo:
106+
with pytest.raises(InvalidVersion) as excinfo:
136107
git_cmd.version()
137108

138-
assert "Unexpected git version output format" in str(excinfo.value)
109+
assert f"Invalid version: '{invalid_output}'" in str(excinfo.value)
139110

140111

141112
def test_build_options_invalid_format(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.