hbutils.system.git.info

Git installation discovery and version inspection utilities.

This module provides public helpers to discover the Git executable and gather version information for both Git and Git LFS. It normalizes the executable path and caches lookup results to avoid repeated subprocess calls.

The module exposes the following public function:

  • git_info() - Retrieve details about Git and Git LFS availability

Note

Git LFS information is only available when Git itself is installed. When Git LFS is not installed, the lfs entry will be present with installed set to False and no version details.

Example:

>>> from hbutils.system.git import git_info
>>> info = git_info()
>>> if info['installed']:
...     print(f"Git version: {info['version']}")
...     if info['lfs']['installed']:
...         print(f"Git LFS version: {info['lfs']['version']}")

__all__

hbutils.system.git.info.__all__ = ['git_info']

Built-in mutable sequence.

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

git_info

hbutils.system.git.info.git_info(git_path: str | None = None) Dict[str, Any][source]

Get information about Git and Git LFS installations.

This function attempts to locate the Git executable and retrieve information about the Git and Git LFS installations. It first tries to use the provided git_path, then checks the system PATH, and finally falls back to None if Git is not found.

The function normalizes git_path to ensure consistent caching behavior across different path representations of the same executable.

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 using shutil.which().

Returns:

A dictionary containing information about Git and Git LFS installations. When Git is not installed, installed is False and lfs information is not included. When Git is installed, lfs is present, with installed indicating whether Git LFS is available.

Return type:

dict

Warns UserWarning:

If Git version information cannot be parsed or if Git LFS version information is unrecognizable.

Example::
>>> info = git_info()
>>> print(info['installed'])  # Check if Git is installed
True
>>> print(info['version'])    # Get Git version
'2.34.1'
>>> print(info['lfs']['installed'])  # Check if Git LFS is installed
True
Example with custom git path::
>>> info = git_info('/usr/local/bin/git')
>>> if info['installed']:
...     print(f"Using Git at: {info['exec']}")
Using Git at: /usr/local/bin/git

The returned dictionary has the following structure when Git is installed:

{
    'exec': str,          # Path to Git executable
    'installed': bool,    # Whether Git is installed
    'version_info': str,  # Full version string from 'git --version'
    'version': str,       # Parsed Git version
    'lfs': {              # Information about Git LFS
        'installed': bool,    # Whether Git LFS is installed
        'version_info': str,  # Full version string from 'git lfs version'
        'version': str        # Parsed Git LFS version
    }
}