Skip to content

GitClient

Source: leap0/_sync/git.py

GitClient(transport: Transport)

Clone repositories, inspect diffs and history, manage branches, stage files, commit, push, and pull inside a running sandbox.

This client is useful when you want to automate Git workflows without shelling out manually through :class:ProcessClient.

Attributes: None.

clone(sandbox: SandboxRef, *, url: str, path: str, branch: str | None = None, commit_id: str | None = None, depth: int | None = None, username: str | None = None, password: str | None = None, http_timeout: float | None = None) -> GitResult

Clone a remote repository into the sandbox.

Args: sandbox: Sandbox ID or object. url: Repository URL. path: Destination path inside the sandbox. branch: Branch to clone. commit_id: Specific commit to checkout after cloning. depth: Shallow clone depth. username: Auth username (for private repos). password: Auth password or token (for private repos). http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: GitResult: Command output and exit status from the clone operation.

status(sandbox: SandboxRef, *, path: str, http_timeout: float | None = None) -> GitResult

Get the current repository status.

Returns: GitResult: Git status output and exit status.

Args: sandbox: Sandbox ID or object. path: Path used by this operation. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

branches(sandbox: SandboxRef, *, path: str, branch_type: str = 'local', contains: str | None = None, not_contains: str | None = None, http_timeout: float | None = None) -> GitResult

List branches in the repository.

Args: sandbox: Sandbox ID or object. path: Path to the git repo. branch_type: Filter by "local", "remote", or "all". contains: Only branches containing this commit SHA. not_contains: Exclude branches containing this commit SHA. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

diff_unstaged(sandbox: SandboxRef, *, path: str, context_lines: int | None = None, http_timeout: float | None = None) -> GitResult

Show working tree changes that are not staged yet.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

diff_staged(sandbox: SandboxRef, *, path: str, context_lines: int | None = None, http_timeout: float | None = None) -> GitResult

Show changes that are already staged for the next commit.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

diff(sandbox: SandboxRef, *, path: str, target: str, context_lines: int | None = None, http_timeout: float | None = None) -> GitResult

Compare the current state against a branch, tag, or commit.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

reset(sandbox: SandboxRef, *, path: str, http_timeout: float | None = None) -> GitResult

Unstage all currently staged changes.

Args: sandbox: Sandbox ID or object. path: Path used by this operation.

Returns: object: Result returned by this operation.

log(sandbox: SandboxRef, *, path: str, max_count: int | None = None, start_timestamp: str | None = None, end_timestamp: str | None = None, http_timeout: float | None = None) -> GitResult

Show commit history with optional limits and date filters.

Args: sandbox: Sandbox ID or object. path: Path to the git repo. max_count: Maximum number of commits to return (default 10). start_timestamp: Start timestamp filter. end_timestamp: End timestamp filter. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

show(sandbox: SandboxRef, *, path: str, revision: str = 'HEAD', http_timeout: float | None = None) -> GitResult

Show the full output for a commit, branch, or tag revision.

Args: sandbox: Sandbox ID or object. path: Path used by this operation. revision: Parameter for this operation.

Returns: object: Result returned by this operation.

create_branch(sandbox: SandboxRef, *, path: str, name: str, checkout: bool | None = None, base_branch: str | None = None, http_timeout: float | None = None) -> GitResult

Create a new branch.

Args: sandbox: Sandbox ID or object. path: Path to the git repo. name: New branch name. checkout: Switch to the new branch immediately. base_branch: Branch from a specific revision. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

checkout_branch(sandbox: SandboxRef, *, path: str, branch: str, create: bool | None = None, http_timeout: float | None = None) -> GitResult

Switch to an existing branch. Set create to create it if it does not exist.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

delete_branch(sandbox: SandboxRef, *, path: str, name: str, force: bool = False, http_timeout: float | None = None) -> GitResult

Delete a branch. Set force to delete even if unmerged.

Args: sandbox: Sandbox ID or object. path: Path used by this operation. name: Name used by this operation. force: Parameter for this operation.

Returns: object: Result returned by this operation.

add(sandbox: SandboxRef, *, path: str, files: list[str], http_timeout: float | None = None) -> GitResult

Stage files for the next commit.

Args: http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

commit(sandbox: SandboxRef, *, path: str, message: str, author: str | None = None, email: str | None = None, allow_empty: bool | None = None, http_timeout: float | None = None) -> GitCommitResult

Create a commit from staged changes.

Args: sandbox: Sandbox ID or object. path: Path to the git repo. message: Commit message. author: Author name. email: Author email. allow_empty: Allow creating an empty commit. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: GitCommitResult: Commit result including commit ID when successful.

push(sandbox: SandboxRef, *, path: str, remote: str | None = None, branch: str | None = None, set_upstream: bool | None = None, username: str | None = None, password: str | None = None, http_timeout: float | None = None) -> GitResult

Push commits to a remote.

Args: sandbox: Sandbox ID or object. path: Path used by this operation. remote: Parameter for this operation. branch: Parameter for this operation. set_upstream: Parameter for this operation. username: Parameter for this operation. password: Parameter for this operation. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.

pull(sandbox: SandboxRef, *, path: str, remote: str | None = None, branch: str | None = None, rebase: bool | None = None, set_upstream: bool | None = None, username: str | None = None, password: str | None = None, http_timeout: float | None = None) -> GitResult

Pull commits from a remote. Set rebase to rebase instead of merge.

Args: sandbox: Sandbox ID or object. path: Path to the git repo. remote: Remote name (default "origin"). branch: Branch name. rebase: Rebase instead of merge. set_upstream: Set upstream tracking. username: Auth username. password: Auth password or token. http_timeout: Optional HTTP request timeout in seconds for this SDK call.

Returns: object: Result returned by this operation.