GitClient
Source: src/services/git.ts
Signature
Section titled “Signature”GitClient(transport: Leap0Transport)Overview
Section titled “Overview”Runs git operations inside a sandbox repository.
Throws
Section titled “Throws”Leap0Error: If an API call fails.Error: If the service returns an unexpected empty response.
Methods
Section titled “Methods”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.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- The git command result.
Examples
Section titled “Examples”await sandbox.git.clone({ url: "https://github.com/example/repo.git", path: "/workspace/repo", branch: "main",});status
Section titled “status”async status(sandbox: SandboxRef, path: string, options?: RequestOptions): Promise<GitResult>Returns repository status information for a sandbox path.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.path: Repository path inside the sandbox.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- The git status result.
branches
Section titled “branches”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.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.params: Branch listing parameters.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- The git branch listing result.
diffUnstaged
Section titled “diffUnstaged”async diffUnstaged(sandbox: SandboxRef, path: string, contextLines?: number, options?: RequestOptions): Promise<GitResult>Returns the unstaged diff for a repository path.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- The git diff result.
diffStaged
Section titled “diffStaged”async diffStaged(sandbox: SandboxRef, path: string, contextLines?: number, options?: RequestOptions): Promise<GitResult>Returns the staged diff for a repository path.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- 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.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- The git diff result.
async reset(sandbox: SandboxRef, path: string, options?: RequestOptions): Promise<GitResult>Resets staged and unstaged changes for a repository path.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.path: Repository path inside the sandbox.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- 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.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.params: Log query parameters.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- The git log result.
async show(sandbox: SandboxRef, path: string, revision = "HEAD", options?: RequestOptions): Promise<GitResult>Shows a revision for a repository path.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- The git show result.
createBranch
Section titled “createBranch”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.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.params: Branch creation parameters.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- The git branch creation result.
checkoutBranch
Section titled “checkoutBranch”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.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.params: Checkout parameters.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- The git checkout result.
deleteBranch
Section titled “deleteBranch”async deleteBranch(sandbox: SandboxRef, path: string, name: string, force = false, options?: RequestOptions): Promise<GitResult>Deletes a branch from the repository.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- The git branch deletion result.
async add(sandbox: SandboxRef, path: string, files: string[], options?: RequestOptions): Promise<GitResult>Adds files to the git index.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- The git add result.
commit
Section titled “commit”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.
Parameters
Section titled “Parameters”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.
Returns
Section titled “Returns”- 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.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.params: Push parameters.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- 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.
Parameters
Section titled “Parameters”sandbox: Sandbox ID or sandbox-like object.params: Pull parameters.options: Optional request settings such as timeout and query params.
Returns
Section titled “Returns”- The git pull result.