Skip to content

Git

Git endpoints let you clone repositories, inspect diffs and history, manage branches, stage files, commit, push, and pull inside a running sandbox.

Clone a remote repository into the sandbox.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.clone(
url="https://github.com/octocat/Hello-World.git",
path="/workspace/repo",
branch="main",
username="x-access-token",
password="<personal-access-token>",
)
print(result.output)

Get the current repository status as raw git status --porcelain=v2 --branch output.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.status(path="/workspace/repo")
print(result.output)

List branches in the repository as raw git branch output.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.branches(path="/workspace/repo", branch_type="all")
print(result.output)

Show working tree changes that are not staged yet.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.diff_unstaged(path="/workspace/repo", context_lines=5)
print(result.output)

Show changes that are already staged for the next commit.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.diff_staged(path="/workspace/repo", context_lines=5)
print(result.output)

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

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.diff(path="/workspace/repo", target="origin/main", context_lines=3)
print(result.output)

Unstage all currently staged changes in the repository.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.reset(path="/workspace/repo")
print(result.output)

Show commit history with optional limits and date filters.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.log(path="/workspace/repo", max_count=10)
print(result.output)

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

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.show(path="/workspace/repo", revision="HEAD~1")
print(result.output)

Create a new branch. Set checkout to switch to it immediately, and optionally pass base_branch to branch from a specific revision.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.create_branch(
path="/workspace/repo",
name="feature/docs",
checkout=True,
base_branch="main",
)
print(result.output)

Switch to an existing branch.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.checkout_branch(path="/workspace/repo", branch="main")
print(result.output)

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

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.delete_branch(path="/workspace/repo", name="feature/docs", force=True)
print(result.output)

Stage files for the next commit.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.add(path="/workspace/repo", files=["README.md"])
print(result.output)

Create a commit from staged changes.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
commit = sandbox.git.commit(
path="/workspace/repo",
message="docs: update filesystem guide",
author="Leap0 Bot",
email="bot@example.com",
)
print(commit.sha)

Push commits to a remote.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.push(
path="/workspace/repo",
remote="origin",
branch="main",
set_upstream=True,
)
print(result.output)

Pull commits from a remote. Set rebase to rebase instead of merge. Set set_upstream to set upstream tracking for the branch.

from leap0 import Leap0Client
client = Leap0Client()
sandbox = client.sandboxes.create()
result = sandbox.git.pull(
path="/workspace/repo",
remote="origin",
branch="main",
rebase=True,
set_upstream=True,
)
print(result.output)