Skip to content

GitClient

Source: src/services/git.ts

GitClient(transport: Leap0Transport)

Runs git operations inside a sandbox repository.

  • Leap0Error: If an API call fails.
  • Error: If the service returns an unexpected empty response.
async clone(sandbox: SandboxRef, params: { url: string; path: string; branch?: string; commitId?: string; depth?: number; username?: string; password?: string; }, options?: RequestOptions): Promise<GitResult>

Clones a git repository into the sandbox filesystem.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Clone parameters.
  • params.url: Repository URL to clone.
  • params.path: Destination path inside the sandbox.
  • options: Optional request settings such as timeout and query params.
  • The git command result.
await sandbox.git.clone({
url: "https://github.com/example/repo.git",
path: "/workspace/repo",
branch: "main",
});
async status(sandbox: SandboxRef, path: string, options?: RequestOptions): Promise<GitResult>

Returns repository status information for a sandbox path.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • options: Optional request settings such as timeout and query params.
  • The git status result.
async branches(sandbox: SandboxRef, params: { path: string; branchType?: "local" | "remote" | "all"; contains?: string; notContains?: string; }, options?: RequestOptions): Promise<GitResult>

Lists branches for a repository path.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Branch listing parameters.
  • options: Optional request settings such as timeout and query params.
  • The git branch listing result.
async diffUnstaged(sandbox: SandboxRef, path: string, contextLines?: number, options?: RequestOptions): Promise<GitResult>

Returns the unstaged diff for a repository path.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • contextLines: Optional unified diff context line count.
  • options: Optional request settings such as timeout and query params.
  • The git diff result.
async diffStaged(sandbox: SandboxRef, path: string, contextLines?: number, options?: RequestOptions): Promise<GitResult>

Returns the staged diff for a repository path.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • contextLines: Optional unified diff context line count.
  • options: Optional request settings such as timeout and query params.
  • The git diff result.
async diff(sandbox: SandboxRef, path: string, target: string, contextLines?: number, options?: RequestOptions): Promise<GitResult>

Returns a diff against a target revision, branch, or commit.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • target: Revision, branch, or commit to diff against.
  • contextLines: Optional unified diff context line count.
  • options: Optional request settings such as timeout and query params.
  • The git diff result.
async reset(sandbox: SandboxRef, path: string, options?: RequestOptions): Promise<GitResult>

Resets staged and unstaged changes for a repository path.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • options: Optional request settings such as timeout and query params.
  • The git reset result.
async log(sandbox: SandboxRef, params: { path: string; maxCount?: number; startTimestamp?: string; endTimestamp?: string; }, options?: RequestOptions): Promise<GitResult>

Returns commit history for a repository path.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Log query parameters.
  • options: Optional request settings such as timeout and query params.
  • The git log result.
async show(sandbox: SandboxRef, path: string, revision = "HEAD", options?: RequestOptions): Promise<GitResult>

Shows a revision for a repository path.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • revision: Revision to show.
  • options: Optional request settings such as timeout and query params.
  • The git show result.
async createBranch(sandbox: SandboxRef, params: { path: string; name: string; checkout?: boolean; baseBranch?: string; }, options?: RequestOptions): Promise<GitResult>

Creates a new branch, optionally checking it out immediately.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Branch creation parameters.
  • options: Optional request settings such as timeout and query params.
  • The git branch creation result.
async checkoutBranch(sandbox: SandboxRef, params: { path: string; branch: string; create?: boolean; setUpstream?: boolean; }, options?: RequestOptions): Promise<GitResult>

Checks out an existing branch or creates one on demand.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Checkout parameters.
  • options: Optional request settings such as timeout and query params.
  • The git checkout result.
async deleteBranch(sandbox: SandboxRef, path: string, name: string, force = false, options?: RequestOptions): Promise<GitResult>

Deletes a branch from the repository.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • name: Branch name to delete.
  • force: Whether to force-delete the branch.
  • options: Optional request settings such as timeout and query params.
  • The git branch deletion result.
async add(sandbox: SandboxRef, path: string, files: string[], options?: RequestOptions): Promise<GitResult>

Adds files to the git index.

  • sandbox: Sandbox ID or sandbox-like object.
  • path: Repository path inside the sandbox.
  • files: File paths to stage.
  • options: Optional request settings such as timeout and query params.
  • The git add result.
async commit(sandbox: SandboxRef, params: { path: string; message: string; author?: string; email?: string; allowEmpty?: boolean; }, options?: RequestOptions): Promise<GitCommitResult>

Creates a git commit from staged changes.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Commit parameters.
  • params.path: Repository path inside the sandbox.
  • params.message: Commit message.
  • params.author: Optional author name.
  • params.email: Optional author email.
  • params.allowEmpty: Whether to allow empty commits.
  • options: Optional request settings such as timeout and query params.
  • The commit result, including the created commit ID when available.
async push(sandbox: SandboxRef, params: { path: string; remote?: string; branch?: string; setUpstream?: boolean; username?: string; password?: string; }, options?: RequestOptions): Promise<GitResult>

Pushes local commits to a remote.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Push parameters.
  • options: Optional request settings such as timeout and query params.
  • The git push result.
async pull(sandbox: SandboxRef, params: { path: string; remote?: string; branch?: string; rebase?: boolean; setUpstream?: boolean; username?: string; password?: string; }, options?: RequestOptions): Promise<GitResult>

Pulls remote changes into the local repository.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: Pull parameters.
  • options: Optional request settings such as timeout and query params.
  • The git pull result.