onyo.lib.git module
- class onyo.lib.git.GitRepo(path, find_root=False)[source]
Bases:
objectRepresentation of a Git repository.
Uses
subprocessto execute git commands on a repository.Bare repositories are not supported.
- root
The absolute Path of the root of the git repository.
- __init__(path, find_root=False)[source]
Instantiate a
GitRepoobject withpathas the root directory.- Parameters:
path (
Path) – The absolute Path of a git repository.find_root (
bool(default:False)) – Replacepathwith the results offind_root(). Thus any directory of a git repository can be passed aspath, not just the repo root.
- check_ignore(ignore, paths)[source]
Get the subset of
pathsthat match patterns defined inignore.- Parameters:
ignore (
Path) – Path to a file containing exclude patterns (in the style of.gitignore).paths (
list[Path]) – Paths to check
- Raises:
ValueError – Path is outside of the repository.
- Return type:
list[Path]
- clear_cache()[source]
Clear the cache of this instance of GitRepo.
When the repository is modified using only the public API functions, the cache is consistent. This method is only necessary if the repository is modified otherwise.
- Return type:
- property files: list[Path]
Get the absolute
Paths of all tracked files.This property is cached, and is reset automatically by
commit().
- static find_root(path)[source]
Return the absolute path of the git worktree root that
pathbelongs to.Checks
pathitself and each of its parents.- Parameters:
path (
Path) – The Path to find the git worktree root for.- Raises:
OnyoInvalidRepoError – Neither
pathnor its parents are a git repository.- Return type:
Path
- get_config(key, path=None)[source]
Get the value of a configuration key.
If no
pathis given, the configuration key is acquired according togit-config’s order of precedence (worktree, local, global, system).
- get_hexsha(commitish=None, short=False)[source]
Return the hexsha of a given commit-ish.
Will return
Noneif querying the mother of all commits (i.e. “HEAD” of an empty repository).
- history(path=None, n=None)[source]
Yield commit dicts representing the history of
path.The history is acquired via
git log(git log --followif apathis given).
- init_without_reinit()[source]
Initialize
self.rootas a git repo, but not if it’s already one.- Return type:
- static is_git_path(path)[source]
Whether
pathis a git file or directory.A “git path” is a path that is used by git itself (tracked or not) and therefore not valid for use by Onyo.
Any path underneath a directory called
.gitand any basename starting with.gitis considered a git path. e.g..git/*,.gitignore,gitattributes,.gitmodules, etc.- Parameters:
path (
Path) – The path to check.- Return type:
- set_config(key, value, location=None)[source]
Set the value of a configuration key.
- Parameters:
key (
str) – The name of the configuration key to set.value (
str) – The value to set the configuration key to.location (
Union[Literal['system','global','local','worktree'],Path,None] (default:None)) – The location to set the key/value in. Valid locations are standard git-config locations ('system','global','local', and'worktree') or a Path of a file.Nonewill usegit-config’s default location ('local').
- Raises:
ValueError –
locationis invalid.- Return type: