Git¶
git
¶
Functions:
| Name | Description |
|---|---|
commit |
Stage files and create a commit using a named commit message template. |
get_last_commit |
Get information about the last commit. |
get_local_repo |
Locate and return the git repository containing the current directory. |
get_submodule_sha |
Resolve the recorded SHA of a submodule at a given commit-ish. |
is_pull_request |
Determine whether a submodule represents a pull request. |
list_available_addons |
Yield addons found in each initialized submodule of the repository. |
read_gitmodules |
Open the .gitmodules file of a repository for reading and writing. |
show_diff |
Print the diff between remote files and their local counterparts. |
commit
¶
commit(local_repo: Repo, repo_root: Path, files: list, message_name: str, skip_hooks: bool = False, remove: bool = False, **kwargs: Optional[dict]) -> None
Stage files and create a commit using a named commit message template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Repo
|
GitPython Repo to commit into. |
required |
|
Path
|
Repository root used to resolve absolute file paths. |
required |
|
list
|
Relative paths of files to stage. |
required |
|
str
|
Attribute name on commit_messages holding the message template. |
required |
|
bool
|
If True, bypass pre-commit hooks. Defaults to False. |
False
|
|
bool
|
If True, remove files from the index instead of adding them. Defaults to False. |
False
|
|
Optional[dict]
|
Optional format arguments interpolated into the commit message template. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If message_name is not found or a template placeholder is missing. |
Source code in oops/services/git.py
get_last_commit
¶
get_last_commit(path: Optional[str] = None) -> Optional[CommitInfo]
Get information about the last commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[str]
|
Optional path to git repository (uses current directory if None) |
None
|
Returns:
| Type | Description |
|---|---|
Optional[CommitInfo]
|
CommitInfo object or None if not a git repo or no commits |
Source code in oops/services/git.py
get_local_repo
¶
Locate and return the git repository containing the current directory.
Returns:
| Type | Description |
|---|---|
tuple[Repo, Path]
|
Tuple of (Repo, repo_root_path). |
Raises:
| Type | Description |
|---|---|
ClickException
|
If no git repository is found or it has no working tree. |
Source code in oops/services/git.py
get_submodule_sha
¶
Resolve the recorded SHA of a submodule at a given commit-ish.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Repo
|
GitPython Repo containing the submodule. |
required |
|
str
|
Commit-ish (branch, tag, or SHA) to inspect. |
required |
|
str
|
Path of the submodule relative to the repository root. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
SHA string of the submodule at the given ref, or None if not found. |
Source code in oops/services/git.py
is_pull_request
¶
Determine whether a submodule represents a pull request.
Checks both the submodule path and name for pull-request path conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Submodule
|
GitPython Submodule to inspect. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the submodule path or name matches pull-request conventions. |
Source code in oops/services/git.py
list_available_addons
¶
Yield addons found in each initialized submodule of the repository.
Submodules that are not yet initialized on disk are initialized automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Repo
|
GitPython Repo object. |
required |
|
Path
|
Absolute path to the repository root. |
required |
Yields:
| Type | Description |
|---|---|
Generator[tuple[str, Path, dict]]
|
Tuple of (name, path, manifest) for each addon found in any submodule. |
Source code in oops/services/git.py
read_gitmodules
¶
read_gitmodules(repo: Repo) -> GitConfigParser
Open the .gitmodules file of a repository for reading and writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Repo
|
GitPython Repo object with a working tree. |
required |
Returns:
| Type | Description |
|---|---|
GitConfigParser
|
GitConfigParser instance pointing at .gitmodules. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the repository has no working tree directory. |
Source code in oops/services/git.py
show_diff
¶
Print the diff between remote files and their local counterparts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Directory containing the remote (downloaded) versions of the files. |
required |
|
list
|
Relative file paths to compare. |
required |
|
Repo
|
GitPython Repo used to run git diff --no-index. |
required |
|
Path
|
Local repository root where the files live. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if at least one file differs or is new, False if all files are identical. |