Class: Gitlab::GitalyClient::OperationService
- Inherits:
-
Object
- Object
- Gitlab::GitalyClient::OperationService
- Includes:
- EncodingHelper, WithFeatureFlagActors
- Defined in:
- lib/gitlab/gitaly_client/operation_service.rb
Constant Summary collapse
- MAX_MSG_SIZE =
128.kilobytes.freeze
- CUSTOM_HOOK_FALLBACK_MESSAGE =
'Prevented by server hooks'
Constants included from EncodingHelper
EncodingHelper::BOM_UTF8, EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, EncodingHelper::ESCAPED_CHARS, EncodingHelper::UNICODE_REPLACEMENT_CHARACTER
Instance Attribute Summary
Attributes included from WithFeatureFlagActors
Instance Method Summary collapse
- #add_tag(tag_name, user, target, message) ⇒ Object
-
#initialize(repository) ⇒ OperationService
constructor
A new instance of OperationService.
- #rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: []) ⇒ Object
- #rm_tag(tag_name, user) ⇒ Object
-
#user_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, author_name: nil, author_email: nil, dry_run: false, target_sha: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#user_commit_files(user, branch_name, commit_message, actions, author_email, author_name, start_branch_name, start_repository, force = false, start_sha = nil, sign = true, target_sha = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#user_commit_patches(user, branch_name:, patches:, target_sha: nil) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #user_create_branch(branch_name, user, start_point) ⇒ Object
- #user_delete_branch(branch_name, user, target_sha: nil) ⇒ Object
- #user_ff_branch(user, source_sha:, target_branch:, target_sha: nil) ⇒ Object
- #user_merge_branch(user, source_sha:, target_branch:, message:, target_sha: nil) ⇒ Object
- #user_merge_to_ref(user, source_sha:, branch:, target_ref:, message:, first_parent_ref:, expected_old_oid: "") ⇒ Object
- #user_rebase_to_ref(user, source_sha:, target_ref:, first_parent_ref:, expected_old_oid: "") ⇒ Object
-
#user_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #user_squash(user, start_sha, end_sha, author, message, time = Time.now.utc) ⇒ Object
- #user_update_branch(branch_name, user, newrev, oldrev) ⇒ Object
- #user_update_submodule(user:, submodule:, commit_sha:, branch:, message:) ⇒ Object
Methods included from WithFeatureFlagActors
#gitaly_client_call, #gitaly_feature_flag_actors, #group_actor, #project_actor, #user_actor
Methods included from EncodingHelper
#binary_io, #detect_binary?, #detect_encoding, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8, #encode_utf8_no_detect, #encode_utf8_with_escaping!, #encode_utf8_with_replacement_character, #force_encode_utf8, #strip_bom, #unquote_path
Constructor Details
#initialize(repository) ⇒ OperationService
Returns a new instance of OperationService.
13 14 15 16 17 18 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 13 def initialize(repository) @gitaly_repo = repository.gitaly_repository @repository = repository self.repository_actor = repository end |
Instance Method Details
#add_tag(tag_name, user, target, message) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 34 def add_tag(tag_name, user, target, ) request = Gitaly::UserCreateTagRequest.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, tag_name: encode_binary(tag_name), target_revision: encode_binary(target), message: encode_binary(.to_s), timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) ) response = gitaly_client_call(@repository.storage, :operation_service, :user_create_tag, request, timeout: GitalyClient.long_timeout) Gitlab::Git::Tag.new(@repository, response.tag) rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :access_check access_check_error = detailed_error.access_check # These messages were returned from internal/allowed API calls raise Gitlab::Git::PreReceiveError.new(fallback_message: access_check_error.) when :custom_hook raise Gitlab::Git::PreReceiveError.new((detailed_error.custom_hook), fallback_message: CUSTOM_HOOK_FALLBACK_MESSAGE) when :reference_exists raise Gitlab::Git::Repository::TagExistsError else if e.code == GRPC::Core::StatusCodes::FAILED_PRECONDITION raise Gitlab::Git::Repository::InvalidRef, e end raise end end |
#rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: []) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 363 def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: []) request_enum = QueueEnumerator.new response_enum = gitaly_client_call( @repository.storage, :operation_service, :user_rebase_confirmable, request_enum.each, timeout: GitalyClient.long_timeout, remote_storage: remote_repository.storage ) # First request request_enum.push( Gitaly::UserRebaseConfirmableRequest.new( header: Gitaly::UserRebaseConfirmableRequest::Header.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, rebase_id: rebase_id.to_s, branch: encode_binary(branch), branch_sha: branch_sha, remote_repository: remote_repository.gitaly_repository, remote_branch: encode_binary(remote_branch), git_push_options: , timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) ) ) ) response = response_enum.next rebase_sha = response.rebase_sha yield rebase_sha # Second request confirms with gitaly to finalize the rebase request_enum.push(Gitaly::UserRebaseConfirmableRequest.new(apply: true)) request_enum.close response_enum.next (response_enum) rebase_sha rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :access_check access_check_error = detailed_error.access_check # These messages were returned from internal/allowed API calls raise Gitlab::Git::PreReceiveError.new(fallback_message: access_check_error.) when :rebase_conflict raise Gitlab::Git::Repository::GitError, e.details else raise e end ensure request_enum.close end |
#rm_tag(tag_name, user) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 20 def rm_tag(tag_name, user) request = Gitaly::UserDeleteTagRequest.new( repository: @gitaly_repo, tag_name: encode_binary(tag_name), user: Gitlab::Git::User.from_gitlab(user).to_gitaly ) response = gitaly_client_call(@repository.storage, :operation_service, :user_delete_tag, request, timeout: GitalyClient.long_timeout) if pre_receive_error = response.pre_receive_error.presence raise Gitlab::Git::PreReceiveError, pre_receive_error end end |
#user_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, author_name: nil, author_email: nil, dry_run: false, target_sha: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 262 def user_cherry_pick( user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, author_name: nil, author_email: nil, dry_run: false, target_sha: nil) request = Gitaly::UserCherryPickRequest.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, commit: commit.to_gitaly_commit, branch_name: encode_binary(branch_name), message: encode_binary(), start_branch_name: encode_binary(start_branch_name.to_s), start_repository: start_repository.gitaly_repository, commit_author_name: encode_binary(), commit_author_email: encode_binary(), dry_run: dry_run, timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i), expected_old_oid: target_sha ) response = gitaly_client_call( @repository.storage, :operation_service, :user_cherry_pick, request, remote_storage: start_repository.storage, timeout: GitalyClient.long_timeout ) Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update) rescue GRPC::InvalidArgument => ex raise Gitlab::Git::CommandError, ex rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :access_check access_check_error = detailed_error.access_check # These messages were returned from internal/allowed API calls raise Gitlab::Git::PreReceiveError.new(fallback_message: access_check_error.) when :cherry_pick_conflict raise Gitlab::Git::Repository::CreateTreeError, 'CONFLICT' when :changes_already_applied raise Gitlab::Git::Repository::CreateTreeError, 'EMPTY' when :target_branch_diverged raise Gitlab::Git::CommitError, 'branch diverged' else raise e end end |
#user_commit_files(user, branch_name, commit_message, actions, author_email, author_name, start_branch_name, start_repository, force = false, start_sha = nil, sign = true, target_sha = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 509 def user_commit_files( user, branch_name, , actions, , , start_branch_name, start_repository, force = false, start_sha = nil, sign = true, target_sha = nil) req_enum = Enumerator.new do |y| header = user_commit_files_request_header(user, branch_name, , actions, , , start_branch_name, start_repository, force, start_sha, sign, target_sha) y.yield Gitaly::UserCommitFilesRequest.new(header: header) actions.each do |action| action_header = user_commit_files_action_header(action) y.yield Gitaly::UserCommitFilesRequest.new( action: Gitaly::UserCommitFilesAction.new(header: action_header) ) reader = binary_io(action[:content]) until reader.eof? chunk = reader.read(MAX_MSG_SIZE) y.yield Gitaly::UserCommitFilesRequest.new( action: Gitaly::UserCommitFilesAction.new(content: chunk) ) end end end response = gitaly_client_call( @repository.storage, :operation_service, :user_commit_files, req_enum, timeout: GitalyClient.long_timeout, remote_storage: start_repository&.storage) if (pre_receive_error = response.pre_receive_error.presence) raise Gitlab::Git::PreReceiveError, pre_receive_error end if (index_error = response.index_error.presence) raise Gitlab::Git::Index::IndexError, index_error end Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update) rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :access_check access_check_error = detailed_error.access_check # These messages were returned from internal/allowed API calls raise Gitlab::Git::PreReceiveError.new(fallback_message: access_check_error.) when :custom_hook raise Gitlab::Git::PreReceiveError.new((detailed_error.custom_hook), fallback_message: CUSTOM_HOOK_FALLBACK_MESSAGE) when :index_update raise Gitlab::Git::Index::IndexError, (detailed_error.index_update) else handle_undetailed_bad_status_errors(e) raise e end end |
#user_commit_patches(user, branch_name:, patches:, target_sha: nil) ⇒ Object
rubocop:enable Metrics/ParameterLists
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 571 def user_commit_patches(user, branch_name:, patches:, target_sha: nil) header = Gitaly::UserApplyPatchRequest::Header.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, target_branch: encode_binary(branch_name), timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i), expected_old_oid: target_sha ) reader = binary_io(patches) chunks = Enumerator.new do |chunk| chunk.yield Gitaly::UserApplyPatchRequest.new(header: header) until reader.eof? patch_chunk = reader.read(MAX_MSG_SIZE) chunk.yield(Gitaly::UserApplyPatchRequest.new(patches: patch_chunk)) end end response = gitaly_client_call(@repository.storage, :operation_service, :user_apply_patch, chunks, timeout: GitalyClient.long_timeout) Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update) end |
#user_create_branch(branch_name, user, start_point) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 69 def user_create_branch(branch_name, user, start_point) request = Gitaly::UserCreateBranchRequest.new( repository: @gitaly_repo, branch_name: encode_binary(branch_name), user: Gitlab::Git::User.from_gitlab(user).to_gitaly, start_point: encode_binary(start_point) ) response = gitaly_client_call(@repository.storage, :operation_service, :user_create_branch, request, timeout: GitalyClient.long_timeout) branch = response.branch return unless branch target_commit = Gitlab::Git::Commit.decorate(@repository, branch.target_commit) Gitlab::Git::Branch.new(@repository, branch.name, target_commit.id, target_commit) rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :custom_hook raise Gitlab::Git::PreReceiveError.new((detailed_error.custom_hook), fallback_message: CUSTOM_HOOK_FALLBACK_MESSAGE) else if e.code == GRPC::Core::StatusCodes::FAILED_PRECONDITION raise Gitlab::Git::Repository::InvalidRef, e end raise end end |
#user_delete_branch(branch_name, user, target_sha: nil) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 117 def user_delete_branch(branch_name, user, target_sha: nil) request = Gitaly::UserDeleteBranchRequest.new( repository: @gitaly_repo, branch_name: encode_binary(branch_name), user: Gitlab::Git::User.from_gitlab(user).to_gitaly, expected_old_oid: target_sha ) gitaly_client_call(@repository.storage, :operation_service, :user_delete_branch, request, timeout: GitalyClient.long_timeout) rescue GRPC::InvalidArgument => ex raise Gitlab::Git::CommandError, ex rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :custom_hook raise Gitlab::Git::PreReceiveError.new((detailed_error.custom_hook), fallback_message: CUSTOM_HOOK_FALLBACK_MESSAGE) else raise end end |
#user_ff_branch(user, source_sha:, target_branch:, target_sha: nil) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 218 def user_ff_branch(user, source_sha:, target_branch:, target_sha: nil) request = Gitaly::UserFFBranchRequest.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, commit_id: source_sha, branch: encode_binary(target_branch), expected_old_oid: target_sha ) response = gitaly_client_call( @repository.storage, :operation_service, :user_ff_branch, request, timeout: GitalyClient.long_timeout ) if response.pre_receive_error.present? raise Gitlab::Git::PreReceiveError.new(response.pre_receive_error, fallback_message: "pre-receive hook failed.") end Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update) rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :custom_hook raise Gitlab::Git::PreReceiveError.new((detailed_error.custom_hook), fallback_message: CUSTOM_HOOK_FALLBACK_MESSAGE) when :reference_update # Historically UserFFBranch returned a successful response with a missing BranchUpdate if # updating the reference failed. The RPC has been updated to return a bad status when the # reference update fails. Match the previous behavior until call sites have been adapted. nil else if e.code == GRPC::Core::StatusCodes::FAILED_PRECONDITION raise Gitlab::Git::CommitError, e end raise end end |
#user_merge_branch(user, source_sha:, target_branch:, message:, target_sha: nil) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 160 def user_merge_branch(user, source_sha:, target_branch:, message:, target_sha: nil) request_enum = QueueEnumerator.new response_enum = gitaly_client_call( @repository.storage, :operation_service, :user_merge_branch, request_enum.each, timeout: GitalyClient.long_timeout ) request_enum.push( Gitaly::UserMergeBranchRequest.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, commit_id: source_sha, branch: encode_binary(target_branch), expected_old_oid: target_sha, message: encode_binary(), timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) ) ) yield response_enum.next.commit_id request_enum.push(Gitaly::UserMergeBranchRequest.new(apply: true)) request_enum.close second_response = response_enum.next branch_update = second_response.branch_update return if branch_update.nil? raise Gitlab::Git::CommitError, 'failed to apply merge to branch' unless branch_update.commit_id.present? (response_enum) Gitlab::Git::OperationService::BranchUpdate.from_gitaly(branch_update) rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :access_check access_check_error = detailed_error.access_check # These messages were returned from internal/allowed API calls raise Gitlab::Git::PreReceiveError.new(fallback_message: access_check_error.) when :custom_hook raise Gitlab::Git::PreReceiveError.new((detailed_error.custom_hook), fallback_message: CUSTOM_HOOK_FALLBACK_MESSAGE) when :reference_update # We simply ignore any reference update errors which are typically an # indicator of multiple RPC calls trying to update the same reference # at the same point in time. else raise end ensure request_enum.close end |
#user_merge_to_ref(user, source_sha:, branch:, target_ref:, message:, first_parent_ref:, expected_old_oid: "") ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 141 def user_merge_to_ref(user, source_sha:, branch:, target_ref:, message:, first_parent_ref:, expected_old_oid: "") request = Gitaly::UserMergeToRefRequest.new( repository: @gitaly_repo, source_sha: source_sha, branch: encode_binary(branch), target_ref: encode_binary(target_ref), user: Gitlab::Git::User.from_gitlab(user).to_gitaly, message: encode_binary(), first_parent_ref: encode_binary(first_parent_ref), expected_old_oid: expected_old_oid, timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) ) response = gitaly_client_call(@repository.storage, :operation_service, :user_merge_to_ref, request, timeout: GitalyClient.long_timeout) response.commit_id end |
#user_rebase_to_ref(user, source_sha:, target_ref:, first_parent_ref:, expected_old_oid: "") ⇒ Object
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 421 def user_rebase_to_ref(user, source_sha:, target_ref:, first_parent_ref:, expected_old_oid: "") request = Gitaly::UserRebaseToRefRequest.new( user: Gitlab::Git::User.from_gitlab(user).to_gitaly, repository: @gitaly_repo, source_sha: source_sha, target_ref: encode_binary(target_ref), first_parent_ref: encode_binary(first_parent_ref), expected_old_oid: expected_old_oid, timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) ) response = gitaly_client_call(@repository.storage, :operation_service, :user_rebase_to_ref, request, timeout: GitalyClient.long_timeout) response.commit_id end |
#user_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false) ⇒ Object
rubocop:enable Metrics/ParameterLists
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 313 def user_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false) request = Gitaly::UserRevertRequest.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, commit: commit.to_gitaly_commit, branch_name: encode_binary(branch_name), message: encode_binary(), start_branch_name: encode_binary(start_branch_name.to_s), start_repository: start_repository.gitaly_repository, dry_run: dry_run, timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) ) response = gitaly_client_call( @repository.storage, :operation_service, :user_revert, request, remote_storage: start_repository.storage, timeout: GitalyClient.long_timeout ) if response.pre_receive_error.presence raise Gitlab::Git::PreReceiveError, response.pre_receive_error elsif response.commit_error.presence raise Gitlab::Git::CommitError, response.commit_error elsif response.create_tree_error.presence raise Gitlab::Git::Repository::CreateTreeError, response.create_tree_error_code end Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update) rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :merge_conflict raise Gitlab::Git::Repository::CreateTreeError, 'CONFLICT' when :changes_already_applied raise Gitlab::Git::Repository::CreateTreeError, 'EMPTY' when :custom_hook raise Gitlab::Git::PreReceiveError.new((detailed_error.custom_hook), fallback_message: CUSTOM_HOOK_FALLBACK_MESSAGE) when :not_ancestor raise Gitlab::Git::CommitError, 'branch diverged' else raise e end end |
#user_squash(user, start_sha, end_sha, author, message, time = Time.now.utc) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 438 def user_squash(user, start_sha, end_sha, , , time = Time.now.utc) request = Gitaly::UserSquashRequest.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, start_sha: start_sha, end_sha: end_sha, author: Gitlab::Git::User.from_gitlab().to_gitaly, commit_message: encode_binary(), timestamp: Google::Protobuf::Timestamp.new(seconds: time.to_i) ) response = gitaly_client_call( @repository.storage, :operation_service, :user_squash, request, timeout: GitalyClient.long_timeout ) response.squash_sha rescue GRPC::BadStatus => e detailed_error = GitalyClient.decode_detailed_error(e) case detailed_error.try(:error) when :resolve_revision, :rebase_conflict # Theoretically, we could now raise specific errors based on the type # of the detailed error. Most importantly, we get error details when # Gitaly was not able to resolve the `start_sha` or `end_sha` via a # ResolveRevisionError, and we get information about which files are # conflicting via a MergeConflictError. # # We don't do this now though such that we can maintain backwards # compatibility with the minimum required set of changes during the # transitory period where we're migrating UserSquash to use # structured errors. We thus continue to just return a GitError, like # we previously did. raise Gitlab::Git::Repository::GitError, e.details else raise end end |
#user_update_branch(branch_name, user, newrev, oldrev) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 100 def user_update_branch(branch_name, user, newrev, oldrev) request = Gitaly::UserUpdateBranchRequest.new( repository: @gitaly_repo, branch_name: encode_binary(branch_name), user: Gitlab::Git::User.from_gitlab(user).to_gitaly, newrev: encode_binary(newrev), oldrev: encode_binary(oldrev) ) response = gitaly_client_call(@repository.storage, :operation_service, :user_update_branch, request, timeout: GitalyClient.long_timeout) if pre_receive_error = response.pre_receive_error.presence raise Gitlab::Git::PreReceiveError, pre_receive_error end end |
#user_update_submodule(user:, submodule:, commit_sha:, branch:, message:) ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'lib/gitlab/gitaly_client/operation_service.rb', line 480 def user_update_submodule(user:, submodule:, commit_sha:, branch:, message:) request = Gitaly::UserUpdateSubmoduleRequest.new( repository: @gitaly_repo, user: Gitlab::Git::User.from_gitlab(user).to_gitaly, commit_sha: commit_sha, branch: encode_binary(branch), submodule: encode_binary(submodule), commit_message: encode_binary(), timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) ) response = gitaly_client_call( @repository.storage, :operation_service, :user_update_submodule, request, timeout: GitalyClient.long_timeout ) if response.pre_receive_error.present? raise Gitlab::Git::PreReceiveError, response.pre_receive_error elsif response.commit_error.present? raise Gitlab::Git::CommitError, response.commit_error else Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update) end end |