API Reference

class darca_space_git.space_git.SpaceGitManager[source]

Bases: object

Manages Git operations within darca-space-managed logical spaces.

This manager ensures that all Git interactions occur within paths allocated by the SpaceManager. All operations are scoped to these managed spaces and avoid any direct user interaction with the file system.

checkout_branch(space_name: str, branch: str, create: bool = False, dry_run: bool = False) bool[source]

Checkout an existing or new branch.

Args:

branch (str): Branch name. create (bool): Whether to create the branch. dry_run (bool): If True, simulate without making changes.

Returns:

bool: True if successful or simulated.

Raises:

SpaceGitException: If checkout fails.

checkout_path(space_name: str, paths: str | List[str], dry_run: bool = False) bool[source]

Revert file(s) in the working directory to the last committed state.

Args:

paths (str | List[str]): File path(s) relative to space root. dry_run (bool): If True, simulate the operation.

Returns:

bool: True if successful or simulated.

Raises:

SpaceGitException: If file is missing or operation fails.

checkout_path_from_branch(space_name: str, paths: str | List[str], branch: str, dry_run: bool = False) bool[source]

Restore file(s) from a specific branch into the working directory.

Args:

paths (str | List[str]): Path(s) to restore. branch (str): Source branch. dry_run (bool): If True, simulate the operation.

Returns:

bool: True if successful or simulated.

Raises:

SpaceGitException: If restore fails.

clone_repo(space_name: str, repo_url: str) bool[source]

Clone a Git repository into the given space.

Args:

repo_url (str): URL of the remote repository.

Returns:

bool: True if successful.

Raises:

SpaceGitException: If cloning fails.

commit_all(space_name: str, message: str) bool[source]

Stage and commit all changes in the repository.

Args:

message (str): Commit message.

Returns:

bool: True if successful.

Raises:

SpaceGitException: If committing fails.

commit_file(space_name: str, relative_path: str, message: str, content: str | dict | None = None) bool[source]

Commit a specific file. Creates the file if it doesn’t exist and content is provided.

Args:

relative_path (str): Path to the file relative to the space root. message (str): Commit message. content (Optional[str | dict]): Optional file content to create if missing.

Returns:

bool: True if successful.

Raises:

SpaceGitException: If file is missing with no content, or commit fails.

get_status(space_name: str, porcelain: bool = True) str[source]

Retrieve the Git status of the repository.

Args:

porcelain (bool): Whether to return porcelain output.

Returns:

str: Output of git status.

Raises:

SpaceGitException: If status command fails.

init_repo(space_name: str) bool[source]

Initialize a new Git repository in the given space.

Returns:

bool: True if successful.

Raises:

SpaceGitException: If initialization fails.

pull_repo(space_name: str) bool[source]

Pull the latest changes from the remote repository.

Returns:

bool: True if successful.

Raises:

SpaceGitException: If pull operation fails.

push_repo(space_name: str, remote_url: str | None = None) bool[source]

Push local changes to the remote repository.

Args:

remote_url (Optional[str]): Optional remote URL to push to.

Returns:

bool: True if successful.

Raises:

SpaceGitException: If push operation fails.