GitRepositoryContext
The GitRepositoryContext
captures the information of a Git repository.
It can be created using the capsula.GitRepositoryContext.builder
method or the capsula.GitRepositoryContext.__init__
method.
capsula.GitRepositoryContext.builder
classmethod
builder(
name: str | None = None,
*,
path: Path | str | None = None,
path_relative_to_project_root: bool = False,
allow_dirty: bool = True
) -> Callable[[CapsuleParams], GitRepositoryContext]
PARAMETER | DESCRIPTION |
---|---|
name |
Name of the Git repository. If not provided, the name of the working directory will be used.
TYPE:
|
path |
Path to the Git repository. If not provided, the parent directories of the file where the function is defined will be searched for a Git repository.
TYPE:
|
path_relative_to_project_root |
Whether
TYPE:
|
allow_dirty |
Whether to allow the repository to be dirty
TYPE:
|
Source code in capsula/_context/_git.py
capsula.GitRepositoryContext.__init__
__init__(
name: str,
*,
path: Path | str,
diff_file: Path | str | None = None,
search_parent_directories: bool = False,
allow_dirty: bool = True
)
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
path |
TYPE:
|
diff_file |
TYPE:
|
search_parent_directories |
TYPE:
|
allow_dirty |
TYPE:
|
Source code in capsula/_context/_git.py
Configuration example
Via capsula.toml
[pre-run]
contexts = [
{ type = "GitRepositoryContext", name = "capsula", path = ".", path_relative_to_project_root = true },
]
Via @capsula.context
decorator
import capsula
@capsula.run()
@capsula.context(capsula.GitRepositoryContext.builder("capsula"), mode="pre")
def func(): ...
Output example
The following is an example of the output of the GitRepositoryContext
, reported by the JsonDumpReporter
:
"git": {
"capsula": {
"working_dir": "/home/nomura/ghq/github.com/shunichironomura/capsula",
"sha": "2fa930db2b9c00c467b4627e7d1c7dfb06d41279",
"remotes": {
"origin": "ssh://git@github.com/shunichironomura/capsula.git"
},
"branch": "improve-docs-index",
"is_dirty": true,
"diff_file": "/home/nomura/ghq/github.com/shunichironomura/capsula/vault/20240708_024409_coj0/capsula.diff"
}
}