Git
Main class for a new Git handler instance.
Constructors
new Git()
def initialize(sandbox_id:, toolbox_api:)Initializes a new Git handler instance.
Parameters:
sandbox_idString - The Sandbox ID.toolbox_apiDaytonaToolboxApiClient:GitApi - API client for Sandbox operations.
Returns:
Git- a new instance of Git
Methods
sandbox_id()
def sandbox_id()Returns:
String- The Sandbox ID
toolbox_api()
def toolbox_api()Returns:
DaytonaToolboxApiClient:GitApi- API client for Sandbox operations
add()
def add(path, files)Stages the specified files for the next commit, similar to running ‘git add’ on the command line.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.filesArray<String> - List of file paths or directories to stage, relative to the repository root.
Returns:
void
Raises:
Daytona:Sdk:Error- if adding files fails
Examples:
# Stage a single filesandbox.git.add("workspace/repo", ["file.txt"])
# Stage multiple filessandbox.git.add("workspace/repo", [ "src/main.rb", "spec/main_spec.rb", "README.md"])branches()
def branches(path)Lists branches in the repository.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.
Returns:
DaytonaApiClient:ListBranchResponse- List of branches in the repository.
Raises:
Daytona:Sdk:Error- if listing branches fails
Examples:
response = sandbox.git.branches("workspace/repo")puts "Branches: #{response.branches}"clone()
def clone(url:, path:, branch:, commit_id:, username:, password:)Clones a Git repository into the specified path. It supports cloning specific branches or commits, and can authenticate with the remote repository if credentials are provided.
Parameters:
urlString - Repository URL to clone from.pathString - Path where the repository should be cloned. Relative paths are resolved based on the sandbox working directory.branchString, nil - Specific branch to clone. If not specified, clones the default branch.commit_idString, nil - Specific commit to clone. If specified, the repository will be left in a detached HEAD state at this commit.usernameString, nil - Git username for authentication.passwordString, nil - Git password or token for authentication.
Returns:
void
Raises:
Daytona:Sdk:Error- if cloning repository fails
Examples:
# Clone the default branchsandbox.git.clone( url: "https://github.com/user/repo.git", path: "workspace/repo")
# Clone a specific branch with authenticationsandbox.git.clone( url: "https://github.com/user/private-repo.git", path: "workspace/private", branch: "develop", username: "user", password: "token")
# Clone a specific commitsandbox.git.clone( url: "https://github.com/user/repo.git", path: "workspace/repo-old", commit_id: "abc123")commit()
def commit(path:, message:, author:, email:, allow_empty:)Creates a new commit with the staged changes. Make sure to stage changes using the add() method before committing.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.messageString - Commit message describing the changes.authorString - Name of the commit author.emailString - Email address of the commit author.allow_emptyBoolean - Allow creating an empty commit when no changes are staged. Defaults to false.
Returns:
GitCommitResponse- Response containing the commit SHA.
Raises:
Daytona:Sdk:Error- if committing changes fails
Examples:
# Stage and commit changessandbox.git.add("workspace/repo", ["README.md"])commit_response = sandbox.git.commit( path: "workspace/repo", message: "Update documentation", author: "John Doe", email: "john@example.com", allow_empty: true)puts "Commit SHA: #{commit_response.sha}"push()
def push(path:, username:, password:)Pushes all local commits on the current branch to the remote repository. If the remote repository requires authentication, provide username and password/token.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.usernameString, nil - Git username for authentication.passwordString, nil - Git password or token for authentication.
Returns:
void
Raises:
Daytona:Sdk:Error- if pushing changes fails
Examples:
# Push without authentication (for public repos or SSH)sandbox.git.push("workspace/repo")
# Push with authenticationsandbox.git.push( path: "workspace/repo", username: "user", password: "github_token")pull()
def pull(path:, username:, password:)Pulls changes from the remote repository. If the remote repository requires authentication, provide username and password/token.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.usernameString, nil - Git username for authentication.passwordString, nil - Git password or token for authentication.
Returns:
void
Raises:
Daytona:Sdk:Error- if pulling changes fails
Examples:
# Pull without authenticationsandbox.git.pull("workspace/repo")
# Pull with authenticationsandbox.git.pull( path: "workspace/repo", username: "user", password: "github_token")status()
def status(path)Gets the current Git repository status.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.
Returns:
DaytonaToolboxApiClient:GitStatus- Repository status information including:
Raises:
Daytona:Sdk:Error- if getting status fails
Examples:
status = sandbox.git.status("workspace/repo")puts "On branch: #{status.current_branch}"puts "Commits ahead: #{status.ahead}"puts "Commits behind: #{status.behind}"checkout_branch()
def checkout_branch(path, branch)Checkout branch in the repository.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.branchString - Name of the branch to checkout
Returns:
void
Raises:
Daytona:Sdk:Error- if checking out branch fails
Examples:
# Checkout a branchsandbox.git.checkout_branch("workspace/repo", "feature-branch")create_branch()
def create_branch(path, name)Create branch in the repository.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.nameString - Name of the new branch to create
Returns:
void
Raises:
Daytona:Sdk:Error- if creating branch fails
Examples:
# Create a new branchsandbox.git.create_branch("workspace/repo", "new-feature")delete_branch()
def delete_branch(path, name)Delete branch in the repository.
Parameters:
pathString - Path to the Git repository root. Relative paths are resolved based on the sandbox working directory.nameString - Name of the branch to delete
Returns:
void
Raises:
Daytona:Sdk:Error- if deleting branch fails
Examples:
# Delete a branchsandbox.git.delete_branch("workspace/repo", "old-feature")