@@ -20,9 +20,7 @@ class InvalidBuildOptions(ValueError):
20
20
"""Raised when a git version output is in an unexpected format.
21
21
22
22
>>> 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: ...')
26
24
"""
27
25
28
26
def __init__ (self , version : str , * args : object ) -> None :
@@ -1787,18 +1785,12 @@ def config(
1787
1785
def version (
1788
1786
self ,
1789
1787
* ,
1790
- build_options : bool | None = None ,
1791
1788
# libvcs special behavior
1792
1789
check_returncode : bool | None = None ,
1793
1790
** kwargs : t .Any ,
1794
1791
) -> Version :
1795
1792
"""Get git version. Wraps `git version <https://git-scm.com/docs/git-version>`_.
1796
1793
1797
- Parameters
1798
- ----------
1799
- build_options : bool, optional
1800
- Include build options in the output with ``--build-options``
1801
-
1802
1794
Returns
1803
1795
-------
1804
1796
Version
@@ -1816,16 +1808,9 @@ def version(
1816
1808
>>> version = git.version()
1817
1809
>>> isinstance(version.major, int)
1818
1810
True
1819
-
1820
- >>> version = git.version(build_options=True)
1821
- >>> isinstance(version.major, int)
1822
- True
1823
1811
"""
1824
1812
local_flags : list [str ] = []
1825
1813
1826
- if build_options is True :
1827
- local_flags .append ("--build-options" )
1828
-
1829
1814
output = self .run (
1830
1815
["version" , * local_flags ],
1831
1816
check_returncode = check_returncode ,
@@ -1837,7 +1822,7 @@ def version(
1837
1822
return parse_version (version_str )
1838
1823
1839
1824
# Raise exception if output format is unexpected
1840
- raise InvalidVersion (f"Unexpected git version output format: { output } " )
1825
+ raise InvalidVersion (output )
1841
1826
1842
1827
def build_options (
1843
1828
self ,
@@ -1880,7 +1865,7 @@ def build_options(
1880
1865
# First line is always "git version X.Y.Z"
1881
1866
lines = output .strip ().split ("\n " )
1882
1867
if not lines or not lines [0 ].startswith ("git version " ):
1883
- raise InvalidBuildOptions (f"Unexpected git version output format: { output } " )
1868
+ raise InvalidBuildOptions (output )
1884
1869
1885
1870
version_str = lines [0 ].replace ("git version " , "" ).strip ()
1886
1871
result .version = version_str
@@ -1916,8 +1901,10 @@ def build_options(
1916
1901
result .sizeof_size_t = value
1917
1902
elif key == "shell-path" :
1918
1903
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 ():
1921
1908
result .commit = line
1922
1909
1923
1910
return result
0 commit comments