hbutils.system.git¶
This module provides functionality for checking and retrieving information about Git and Git LFS installations.
It includes functions to:
Check if Git is installed and get its version information.
Check if Git LFS is installed and get its version information.
Cache the results of these checks for improved performance.
The module uses subprocess to run Git commands and parse their output, providing detailed information about the Git and Git LFS installations on the system.
git_info¶
-
hbutils.system.git.
git_info
(git_path: Optional[str] = None)[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.
- 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:
A dictionary containing information about Git and Git LFS installations.
- Return type:
dict
- Raises:
subprocess.CalledProcessError – If there’s an error running Git commands.
- Warns UserWarning:
If Git version information cannot be parsed or if Git LFS version unrecognizable.
- Usage:
>>> info = git_info() >>> print(info['installed']) # Check if Git is installed >>> print(info['version']) # Get Git version >>> print(info['lfs']['installed']) # Check if Git LFS is installed
The returned dictionary has the following structure:
1 2 3 4 5 6 7 8 9 10 11
{ '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 } }