hbutils.testing.requires.git

Git availability and version query utilities for testing environments.

This module provides lightweight helpers built on top of hbutils.system.git.info.git_info() to query Git and Git LFS installation status as well as retrieve their versions. The functions are intentionally minimal and designed for use in test requirements checks where a concise boolean or version object is more convenient than the full metadata dictionary.

The module contains the following main components:

Note

These helpers depend on hbutils.system.git.info.git_info() and therefore inherit its path resolution and caching behavior.

Example:

>>> from hbutils.testing.requires.git import is_git_installed, git_version
>>> if is_git_installed():
...     print(git_version())
2.34.1

__all__

hbutils.testing.requires.git.__all__ = ['is_git_installed', 'git_version', 'is_git_lfs_installed', 'git_lfs_version']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

is_git_installed

hbutils.testing.requires.git.is_git_installed(git_path: str | None = None) bool[source]

Check if Git is installed.

The function delegates to hbutils.system.git.info.git_info() and reports whether Git is available. When git_path is provided, it is used as the candidate Git executable path; otherwise, the system PATH is searched.

Parameters:

git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system PATH.

Returns:

True if Git is installed, False otherwise.

Return type:

bool

Example:

>>> is_git_installed()
True
>>> is_git_installed('/custom/path/to/git')
True

git_version

hbutils.testing.requires.git.git_version(git_path: str | None = None) VersionInfo | None[source]

Get the Git version.

This function returns a VersionInfo instance for the parsed Git version when Git is installed and its version information can be parsed. If Git is not installed or the version string cannot be recognized, it returns None.

Parameters:

git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system PATH.

Returns:

Git version wrapped as VersionInfo, or None if Git is not installed or the version cannot be determined.

Return type:

Optional[VersionInfo]

Note

This function may return None even if Git is installed, in cases where the git --version output is unrecognizable.

Example:

>>> version = git_version()
>>> if version:
...     print(f"Git version: {version}")
... else:
...     print("Git version could not be determined")
Git version: 2.34.1

is_git_lfs_installed

hbutils.testing.requires.git.is_git_lfs_installed(git_path: str | None = None) bool[source]

Check if Git LFS is installed.

The function reports True only when both Git and Git LFS are installed. It uses hbutils.system.git.info.git_info() to obtain this information.

Parameters:

git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system PATH.

Returns:

True if Git and Git LFS are installed, False otherwise.

Return type:

bool

Example:

>>> is_git_lfs_installed()
True
>>> is_git_lfs_installed('/custom/path/to/git')
False

git_lfs_version

hbutils.testing.requires.git.git_lfs_version(git_path: str | None = None) VersionInfo | None[source]

Get the Git LFS version.

This function returns a VersionInfo instance for the parsed Git LFS version when Git LFS is installed and its version information can be parsed. If Git LFS is not installed or the version string cannot be recognized, it returns None.

Parameters:

git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system PATH.

Returns:

Git LFS version wrapped as VersionInfo, or None if Git LFS is not installed or the version cannot be determined.

Return type:

Optional[VersionInfo]

Note

This function may return None even if Git LFS is installed, in cases where the git lfs version output is unrecognizable.

Example:

>>> version = git_lfs_version()
>>> if version:
...     print(f"Git LFS version: {version}")
... else:
...     print("Git LFS version could not be determined")
Git LFS version: 3.2.0