utils¶
Git repository utility functions.
This module provides utility functions for working with local git repositories, including locating the repository root directory, extracting remote origin URLs, and determining the current branch.
- git_web_url.utils.locate_git_repo_dir(p_file: Path) Path[source]¶
Locate the git repository root directory for a given path.
Starting from the given file or directory path, this function traverses up the directory tree to find the git repository root. The root is identified by the presence of a
.git/configfile.- Parameters:
p_file – The path to a file or directory within a git repository.
- Returns:
The path to the git repository root directory.
- Raises:
NotGitRepoError – If the given path is not within a git repository.
- git_web_url.utils.extract_remote_origin_url(p_git_config: Path) str[source]¶
Extract the remote origin URL from a git config file.
Parses the
.git/configfile to retrieve the URL configured for theoriginremote.- Parameters:
p_git_config – The path to the
.git/configfile.- Returns:
The URL of the remote origin.
- git_web_url.utils.extract_current_branch(p_git_head: Path) str[source]¶
Extract the current branch name from a git HEAD file.
Reads the
.git/HEADfile and parses it to determine the currently checked-out branch. The HEAD file typically contains a reference likeref: refs/heads/<branch_name>.- Parameters:
p_git_head – The path to the
.git/HEADfile.- Returns:
The name of the current branch.