Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/gitaly_client/operation_service.rb')
-rw-r--r--lib/gitlab/gitaly_client/operation_service.rb120
1 files changed, 53 insertions, 67 deletions
diff --git a/lib/gitlab/gitaly_client/operation_service.rb b/lib/gitlab/gitaly_client/operation_service.rb
index 66f70ed9dc6..313334737c0 100644
--- a/lib/gitlab/gitaly_client/operation_service.rb
+++ b/lib/gitlab/gitaly_client/operation_service.rb
@@ -40,11 +40,6 @@ module Gitlab
)
response = gitaly_client_call(@repository.storage, :operation_service, :user_create_tag, request, timeout: GitalyClient.long_timeout)
- if pre_receive_error = response.pre_receive_error.presence
- raise Gitlab::Git::PreReceiveError, pre_receive_error
- elsif response.exists
- raise Gitlab::Git::Repository::TagExistsError
- end
Gitlab::Git::Tag.new(@repository, response.tag)
rescue GRPC::BadStatus => e
@@ -79,10 +74,6 @@ module Gitlab
response = gitaly_client_call(@repository.storage, :operation_service,
:user_create_branch, request, timeout: GitalyClient.long_timeout)
- if response.pre_receive_error.present?
- raise Gitlab::Git::PreReceiveError, response.pre_receive_error
- end
-
branch = response.branch
return unless branch
@@ -128,12 +119,8 @@ module Gitlab
user: Gitlab::Git::User.from_gitlab(user).to_gitaly
)
- response = gitaly_client_call(@repository.storage, :operation_service,
- :user_delete_branch, request, timeout: GitalyClient.long_timeout)
-
- if pre_receive_error = response.pre_receive_error.presence
- raise Gitlab::Git::PreReceiveError, pre_receive_error
- end
+ gitaly_client_call(@repository.storage, :operation_service,
+ :user_delete_branch, request, timeout: GitalyClient.long_timeout)
rescue GRPC::BadStatus => e
detailed_error = GitalyClient.decode_detailed_error(e)
@@ -165,7 +152,7 @@ module Gitlab
response.commit_id
end
- def user_merge_branch(user, source_sha, target_branch, message)
+ def user_merge_branch(user, source_sha:, target_branch:, message:, target_sha: nil)
request_enum = QueueEnumerator.new
response_enum = gitaly_client_call(
@repository.storage,
@@ -181,6 +168,7 @@ module Gitlab
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(message),
timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i)
)
@@ -197,7 +185,6 @@ module Gitlab
raise Gitlab::Git::CommitError, 'failed to apply merge to branch' unless branch_update.commit_id.present?
Gitlab::Git::OperationService::BranchUpdate.from_gitaly(branch_update)
-
rescue GRPC::BadStatus => e
detailed_error = GitalyClient.decode_detailed_error(e)
@@ -220,12 +207,13 @@ module Gitlab
request_enum.close
end
- def user_ff_branch(user, source_sha, target_branch)
+ 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)
+ branch: encode_binary(target_branch),
+ expected_old_oid: target_sha
)
response = gitaly_client_call(
@@ -246,25 +234,54 @@ module Gitlab
end
def user_cherry_pick(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
- call_cherry_pick_or_revert(:cherry_pick,
- user: user,
- commit: commit,
- branch_name: branch_name,
- message: message,
- start_branch_name: start_branch_name,
- start_repository: start_repository,
- dry_run: dry_run)
+ response = call_cherry_pick_or_revert(:cherry_pick,
+ user: user,
+ commit: commit,
+ branch_name: branch_name,
+ message: message,
+ start_branch_name: start_branch_name,
+ start_repository: start_repository,
+ dry_run: dry_run)
+
+ Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update)
+ rescue GRPC::BadStatus => e
+ detailed_error = GitalyClient.decode_detailed_error(e)
+
+ case detailed_error&.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.error_message)
+ 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
def user_revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false)
- call_cherry_pick_or_revert(:revert,
- user: user,
- commit: commit,
- branch_name: branch_name,
- message: message,
- start_branch_name: start_branch_name,
- start_repository: start_repository,
- dry_run: dry_run)
+ response = call_cherry_pick_or_revert(:revert,
+ user: user,
+ commit: commit,
+ branch_name: branch_name,
+ message: message,
+ start_branch_name: start_branch_name,
+ start_repository: start_repository,
+ dry_run: dry_run)
+
+ 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)
end
def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: [])
@@ -520,7 +537,7 @@ module Gitlab
dry_run: dry_run
)
- response = gitaly_client_call(
+ gitaly_client_call(
@repository.storage,
:operation_service,
:"user_#{rpc}",
@@ -528,37 +545,6 @@ module Gitlab
remote_storage: start_repository.storage,
timeout: GitalyClient.long_timeout
)
-
- handle_cherry_pick_or_revert_response(response)
- rescue GRPC::BadStatus => e
- detailed_error = GitalyClient.decode_detailed_error(e)
-
- case detailed_error&.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.error_message)
- 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
-
- def handle_cherry_pick_or_revert_response(response)
- 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)
end
# rubocop:disable Metrics/ParameterLists