Class: Daytona::Git
- Inherits:
-
Object
- Object
- Daytona::Git
- Defined in:
- lib/daytona/git.rb
Instance Attribute Summary collapse
-
#sandbox_id ⇒ String
readonly
The Sandbox ID.
-
#toolbox_api ⇒ DaytonaApiClient::ToolboxApi
readonly
API client for Sandbox operations.
Instance Method Summary collapse
-
#add(path, files) ⇒ void
Stages the specified files for the next commit, similar to running 'git add' on the command line.
-
#branches(path) ⇒ DaytonaApiClient::ListBranchResponse
Lists branches in the repository.
-
#checkout_branch(path, branch) ⇒ void
Checkout branch in the repository.
-
#clone(url:, path:, branch: nil, commit_id: nil, username: nil, password: nil) ⇒ void
Clones a Git repository into the specified path.
-
#commit(path:, message:, author:, email:, allow_empty: false) ⇒ GitCommitResponse
Creates a new commit with the staged changes.
-
#create_branch(path, name) ⇒ void
Create branch in the repository.
-
#delete_branch(path, name) ⇒ void
Delete branch in the repository.
-
#initialize(sandbox_id:, toolbox_api:) ⇒ Git
constructor
Initializes a new Git handler instance.
-
#pull(path:, username: nil, password: nil) ⇒ void
Pulls changes from the remote repository.
-
#push(path:, username: nil, password: nil) ⇒ void
Pushes all local commits on the current branch to the remote repository.
-
#status(path) ⇒ DaytonaApiClient::GitStatus
Gets the current Git repository status.
Constructor Details
#initialize(sandbox_id:, toolbox_api:) ⇒ Git
Initializes a new Git handler instance.
15 16 17 18 |
# File 'lib/daytona/git.rb', line 15 def initialize(sandbox_id:, toolbox_api:) @sandbox_id = sandbox_id @toolbox_api = toolbox_api end |
Instance Attribute Details
#sandbox_id ⇒ String (readonly)
6 7 8 |
# File 'lib/daytona/git.rb', line 6 def sandbox_id @sandbox_id end |
#toolbox_api ⇒ DaytonaApiClient::ToolboxApi (readonly)
9 10 11 |
# File 'lib/daytona/git.rb', line 9 def toolbox_api @toolbox_api end |
Instance Method Details
#add(path, files) ⇒ void
This method returns an undefined value.
Stages the specified files for the next commit, similar to running 'git add' on the command line.
39 40 41 42 43 |
# File 'lib/daytona/git.rb', line 39 def add(path, files) toolbox_api.git_add_files(sandbox_id, DaytonaApiClient::GitAddRequest.new(path:, files:)) rescue StandardError => e raise Sdk::Error, "Failed to add files: #{e.message}" end |
#branches(path) ⇒ DaytonaApiClient::ListBranchResponse
Lists branches in the repository.
55 56 57 58 59 |
# File 'lib/daytona/git.rb', line 55 def branches(path) toolbox_api.git_list_branches(sandbox_id, path) rescue StandardError => e raise Sdk::Error, "Failed to list branches: #{e.message}" end |
#checkout_branch(path, branch) ⇒ void
This method returns an undefined value.
Checkout branch in the repository.
237 238 239 240 241 242 243 244 |
# File 'lib/daytona/git.rb', line 237 def checkout_branch(path, branch) toolbox_api.git_checkout_branch( sandbox_id, DaytonaApiClient::GitCheckoutRequest.new(path:, branch:) ) rescue StandardError => e raise Sdk::Error, "Failed to checkout branch: #{e.message}" end |
#clone(url:, path:, branch: nil, commit_id: nil, username: nil, password: nil) ⇒ void
This method returns an undefined value.
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.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/daytona/git.rb', line 99 def clone(url:, path:, branch: nil, commit_id: nil, username: nil, password: nil) # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists toolbox_api.git_clone_repository( sandbox_id, DaytonaApiClient::GitCloneRequest.new( url: url, branch: branch, path: path, username: username, password: password, commit_id: commit_id ) ) rescue StandardError => e raise Sdk::Error, "Failed to clone repository: #{e.message}" end |
#commit(path:, message:, author:, email:, allow_empty: false) ⇒ GitCommitResponse
Creates a new commit with the staged changes. Make sure to stage changes using the add() method before committing.
138 139 140 141 142 143 144 145 146 |
# File 'lib/daytona/git.rb', line 138 def commit(path:, message:, author:, email:, allow_empty: false) response = toolbox_api.git_commit_changes( sandbox_id, DaytonaApiClient::GitCommitRequest.new(path:, message:, author:, email:, allow_empty:) ) GitCommitResponse.new(sha: response.hash) rescue StandardError => e raise Sdk::Error, "Failed to commit changes: #{e.message}" end |
#create_branch(path, name) ⇒ void
This method returns an undefined value.
Create branch in the repository.
258 259 260 261 262 263 264 265 |
# File 'lib/daytona/git.rb', line 258 def create_branch(path, name) toolbox_api.git_create_branch( sandbox_id, DaytonaApiClient::GitBranchRequest.new(path:, name:) ) rescue StandardError => e raise Sdk::Error, "Failed to create branch: #{e.message}" end |
#delete_branch(path, name) ⇒ void
This method returns an undefined value.
Delete branch in the repository.
278 279 280 281 282 283 284 285 |
# File 'lib/daytona/git.rb', line 278 def delete_branch(path, name) toolbox_api.git_delete_branch( sandbox_id, DaytonaApiClient::GitDeleteBranchRequest.new(path:, name:) ) rescue StandardError => e raise Sdk::Error, "Failed to delete branch: #{e.message}" end |
#pull(path:, username: nil, password: nil) ⇒ void
This method returns an undefined value.
Pulls changes from the remote repository. If the remote repository requires authentication, provide username and password/token.
199 200 201 202 203 204 205 206 |
# File 'lib/daytona/git.rb', line 199 def pull(path:, username: nil, password: nil) toolbox_api.git_pull_changes( sandbox_id, DaytonaApiClient::GitRepoRequest.new(path:, username:, password:) ) rescue StandardError => e raise Sdk::Error, "Failed to pull changes: #{e.message}" end |
#push(path:, username: nil, password: nil) ⇒ void
This method returns an undefined value.
Pushes all local commits on the current branch to the remote repository. If the remote repository requires authentication, provide username and password/token.
169 170 171 172 173 174 175 176 |
# File 'lib/daytona/git.rb', line 169 def push(path:, username: nil, password: nil) toolbox_api.git_push_changes( sandbox_id, DaytonaApiClient::GitRepoRequest.new(path:, username:, password:) ) rescue StandardError => e raise Sdk::Error, "Failed to push changes: #{e.message}" end |
#status(path) ⇒ DaytonaApiClient::GitStatus
Gets the current Git repository status.
220 221 222 223 224 |
# File 'lib/daytona/git.rb', line 220 def status(path) toolbox_api.git_get_status(sandbox_id, path) rescue StandardError => e raise Sdk::Error, "Failed to get status: #{e.message}" end |