clabe.repository ¶
GitRepositoryMetadata ¶
Bases: BaseModel
A serializable snapshot of a Git repository's provenance state.
Paths are relative to the current working directory when the snapshot is made, or absolute when the checkout is on another drive.
GitRepository ¶
Bases: Repo
A wrapper around the git.Repo class that provides additional methods
for managing Git repositories and their submodules.
Extends the functionality of GitPython's Repo class with additional utilities for repository management, submodule handling, and cleanup operations.
Methods:
| Name | Description |
|---|---|
reset_repo |
Resets the repository to the last committed state |
clean_repo |
Cleans the repository by removing untracked files |
is_dirty_with_submodules |
Checks if the repository or submodules are dirty |
uncommitted_changes |
Returns a list of uncommitted changes |
init_and_update_submodules |
Initializes and updates all submodules recursively |
submodules_sync |
Synchronizes submodules |
full_reset |
Performs a full reset of the repository and submodules |
try_prompt_full_reset |
Prompts the user to perform a full reset |
Initializes the GitRepository instance and validates the presence of Git.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Arguments passed to the parent Repo class |
()
|
**kwargs
|
Any
|
Keyword arguments passed to the parent Repo class |
{}
|
Example
Source code in src/clabe/repository.py
reset_repo ¶
reset_repo() -> Self
Resets the repository to the last committed state.
Performs a hard reset to discard all uncommitted changes in the working directory and staging area, reverting to the last commit.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The current instance for method chaining. |
Source code in src/clabe/repository.py
clean_repo ¶
clean_repo() -> Self
Cleans the repository by removing untracked files and directories.
Removes all untracked files and directories from the working tree that are not ignored by .gitignore rules.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The current instance for method chaining. |
Example
Source code in src/clabe/repository.py
is_dirty_with_submodules ¶
is_dirty_with_submodules() -> bool
Checks if the repository or any of its submodules is dirty.
A repository is considered dirty if it has uncommitted changes, including untracked files. This method also checks all submodules.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the repository or any submodules have uncommitted changes. |
Example
Source code in src/clabe/repository.py
get_metadata ¶
get_metadata() -> GitRepositoryMetadata
Return a serializable snapshot of this repository and its submodules.
The snapshot includes every declared submodule recursively when its parent
is initialized. An uninitialized submodule records its configured URL and
gitlink commit SHA with is_initialized=False. branch is None
when a repository is in a detached-HEAD state, and tag is None
when HEAD has no exact tag. describe identifies the nearest reachable
tag and the number of commits since it.
Returns:
| Name | Type | Description |
|---|---|---|
GitRepositoryMetadata |
GitRepositoryMetadata
|
Repository provenance information suitable for inclusion in experiment or data metadata. |
Source code in src/clabe/repository.py
uncommitted_changes ¶
Retrieves a list of unstaged and untracked files in the repository and its submodules.
Combines modified files, staged changes, and untracked files from both the main repository and all submodules.
Returns:
| Type | Description |
|---|---|
list[str]
|
List[str]: A list of file paths with uncommitted changes. |
Example
Source code in src/clabe/repository.py
init_and_update_submodules ¶
Initializes and updates all submodules recursively.
Executes git submodule update --init --recursive to ensure all submodules,
including nested ones, are initialized and updated to the commit specified
in the parent repository. This is idempotent - if submodules are already
up to date, no changes are made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
If True, passes --force flag to checkout even if local changes would be overwritten in submodules. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The current instance for method chaining. |
Raises:
| Type | Description |
|---|---|
GitCommandError
|
If the git command fails (e.g., network error, invalid submodule configuration). |
Example
Source code in src/clabe/repository.py
submodules_sync ¶
submodules_sync() -> Self
Synchronizes submodule URLs with the parent repository.
Updates the submodule URLs to match those defined in the parent repository's .gitmodules file.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The current instance for method chaining. |
Source code in src/clabe/repository.py
full_reset ¶
full_reset() -> Self
Performs a full reset of the repository and its submodules.
Executes a complete cleanup including resetting the repository, synchronizing submodules, updating them, and cleaning untracked files. Also recursively resets all submodules.
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The current instance for method chaining. |
Example
Source code in src/clabe/repository.py
try_prompt_full_reset ¶
Prompts the user to perform a full reset if the repository is dirty.
Checks if the repository has uncommitted changes and either asks the user (through the active
clabe.ui session) or automatically performs a full reset based on force_reset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_reset
|
bool
|
Whether to skip the prompt and force a reset |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The current instance for method chaining. |