Class: Daytona::Git
- Inherits:
-
Object
- Object
- Daytona::Git
- Includes:
- Instrumentation
- Defined in:
- lib/daytona/git.rb
Instance Attribute Summary collapse
-
#sandbox_id ⇒ String
readonly
The Sandbox ID.
-
#toolbox_api ⇒ DaytonaToolboxApiClient::GitApi
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:, otel_state: nil) ⇒ 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) ⇒ DaytonaToolboxApiClient::GitStatus
Gets the current Git repository status.
Methods included from Instrumentation
Constructor Details
#initialize(sandbox_id:, toolbox_api:, otel_state: nil) ⇒ Git
Initializes a new Git handler instance.
21 22 23 24 25 |
# File 'lib/daytona/git.rb', line 21 def initialize(sandbox_id:, toolbox_api:, otel_state: nil) @sandbox_id = sandbox_id @toolbox_api = toolbox_api @otel_state = otel_state end |
Instance Attribute Details
#sandbox_id ⇒ String (readonly)
Returns The Sandbox ID.
11 12 13 |
# File 'lib/daytona/git.rb', line 11 def sandbox_id @sandbox_id end |
#toolbox_api ⇒ DaytonaToolboxApiClient::GitApi (readonly)
Returns API client for Sandbox operations.
14 15 16 |
# File 'lib/daytona/git.rb', line 14 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.
46 47 48 49 50 51 52 |
# File 'lib/daytona/git.rb', line 46 def add(path, files) toolbox_api.add_files(DaytonaToolboxApiClient::GitAddRequest.new(path:, files:)) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to add files') rescue StandardError => e raise Sdk::Error, "Failed to add files: #{e.}" end |
#branches(path) ⇒ DaytonaApiClient::ListBranchResponse
Lists branches in the repository.
64 65 66 67 68 69 70 |
# File 'lib/daytona/git.rb', line 64 def branches(path) toolbox_api.list_branches(path) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to list branches') rescue StandardError => e raise Sdk::Error, "Failed to list branches: #{e.}" end |
#checkout_branch(path, branch) ⇒ void
This method returns an undefined value.
Checkout branch in the repository.
254 255 256 257 258 259 260 261 262 |
# File 'lib/daytona/git.rb', line 254 def checkout_branch(path, branch) toolbox_api.checkout_branch( DaytonaToolboxApiClient::GitCheckoutRequest.new(path:, branch:) ) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to checkout branch') rescue StandardError => e raise Sdk::Error, "Failed to checkout branch: #{e.}" 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.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/daytona/git.rb', line 110 def clone(url:, path:, branch: nil, commit_id: nil, username: nil, password: nil) # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists toolbox_api.clone_repository( DaytonaToolboxApiClient::GitCloneRequest.new( url: url, branch: branch, path: path, username: username, password: password, commit_id: commit_id ) ) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to clone repository') rescue StandardError => e raise Sdk::Error, "Failed to clone repository: #{e.}" 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.
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/daytona/git.rb', line 150 def commit(path:, message:, author:, email:, allow_empty: false) response = toolbox_api.commit_changes( DaytonaToolboxApiClient::GitCommitRequest.new(path:, message:, author:, email:, allow_empty:) ) GitCommitResponse.new(sha: response._hash) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to commit changes') rescue StandardError => e raise Sdk::Error, "Failed to commit changes: #{e.}" end |
#create_branch(path, name) ⇒ void
This method returns an undefined value.
Create branch in the repository.
276 277 278 279 280 281 282 283 284 |
# File 'lib/daytona/git.rb', line 276 def create_branch(path, name) toolbox_api.create_branch( DaytonaToolboxApiClient::GitBranchRequest.new(path:, name:) ) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to create branch') rescue StandardError => e raise Sdk::Error, "Failed to create branch: #{e.}" end |
#delete_branch(path, name) ⇒ void
This method returns an undefined value.
Delete branch in the repository.
297 298 299 300 301 302 303 304 305 |
# File 'lib/daytona/git.rb', line 297 def delete_branch(path, name) toolbox_api.delete_branch( DaytonaToolboxApiClient::GitDeleteBranchRequest.new(path:, name:) ) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to delete branch') rescue StandardError => e raise Sdk::Error, "Failed to delete branch: #{e.}" 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.
213 214 215 216 217 218 219 220 221 |
# File 'lib/daytona/git.rb', line 213 def pull(path:, username: nil, password: nil) toolbox_api.pull_changes( DaytonaToolboxApiClient::GitRepoRequest.new(path:, username:, password:) ) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to pull changes') rescue StandardError => e raise Sdk::Error, "Failed to pull changes: #{e.}" 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.
182 183 184 185 186 187 188 189 190 |
# File 'lib/daytona/git.rb', line 182 def push(path:, username: nil, password: nil) toolbox_api.push_changes( DaytonaToolboxApiClient::GitRepoRequest.new(path:, username:, password:) ) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to push changes') rescue StandardError => e raise Sdk::Error, "Failed to push changes: #{e.}" end |
#status(path) ⇒ DaytonaToolboxApiClient::GitStatus
Gets the current Git repository status.
235 236 237 238 239 240 241 |
# File 'lib/daytona/git.rb', line 235 def status(path) toolbox_api.get_status(path) rescue DaytonaToolboxApiClient::ApiError => e raise map_api_error(e, 'Failed to get status') rescue StandardError => e raise Sdk::Error, "Failed to get status: #{e.}" end |