diff options
| author | Robert Speicher <robert@gitlab.com> | 2018-07-09 16:12:18 +0000 | 
|---|---|---|
| committer | Robert Speicher <robert@gitlab.com> | 2018-07-09 16:12:18 +0000 | 
| commit | 2cedb243ee7cd146004b462763cbca3a4f0808a9 (patch) | |
| tree | acaeea92cc015b36084e16a4173aec848e8857c8 | |
| parent | 55db9338123fba3d32ed5e16a6566599c5a99473 (diff) | |
| parent | 4a4338fcc60dcee33b0075213213ae51e8395a6f (diff) | |
| download | gitlab-ce-2cedb243ee7cd146004b462763cbca3a4f0808a9.tar.gz | |
Merge branch 'gitaly-update-branch' into 'master'
Use Gitaly's OperationService.UserUpdateBranch RPC
Closes gitaly#1252
See merge request gitlab-org/gitlab-ce!20231
| -rw-r--r-- | lib/gitlab/git/repository.rb | 8 | ||||
| -rw-r--r-- | lib/gitlab/gitaly_client/operation_service.rb | 16 | ||||
| -rw-r--r-- | spec/lib/gitlab/gitaly_client/operation_service_spec.rb | 41 | 
3 files changed, 64 insertions, 1 deletions
| diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 420790f45d0..25b0ab577da 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -625,7 +625,13 @@ module Gitlab        end        def update_branch(branch_name, user:, newrev:, oldrev:) -        OperationService.new(user, self).update_branch(branch_name, newrev, oldrev) +        gitaly_migrate(:operation_user_update_branch) do |is_enabled| +          if is_enabled +            gitaly_operations_client.user_update_branch(branch_name, user, newrev, oldrev) +          else +            OperationService.new(user, self).update_branch(branch_name, newrev, oldrev) +          end +        end        end        def rm_branch(branch_name, user:) diff --git a/lib/gitlab/gitaly_client/operation_service.rb b/lib/gitlab/gitaly_client/operation_service.rb index ab2c61f6782..555733d1834 100644 --- a/lib/gitlab/gitaly_client/operation_service.rb +++ b/lib/gitlab/gitaly_client/operation_service.rb @@ -68,6 +68,22 @@ module Gitlab          raise Gitlab::Git::Repository::InvalidRef, ex        end +      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 = GitalyClient.call(@repository.storage, :operation_service, :user_update_branch, request) + +        if pre_receive_error = response.pre_receive_error.presence +          raise Gitlab::Git::PreReceiveError, pre_receive_error +        end +      end +        def user_delete_branch(branch_name, user)          request = Gitaly::UserDeleteBranchRequest.new(            repository: @gitaly_repo, diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index 9709f1f5646..031d1e87dc1 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -53,6 +53,47 @@ describe Gitlab::GitalyClient::OperationService do      end    end +  describe '#user_update_branch' do +    let(:branch_name) { 'my-branch' } +    let(:newrev) { '01e' } +    let(:oldrev) { '01d' } +    let(:request) do +      Gitaly::UserUpdateBranchRequest.new( +        repository: repository.gitaly_repository, +        branch_name: branch_name, +        newrev: newrev, +        oldrev: oldrev, +        user: gitaly_user +      ) +    end +    let(:response) { Gitaly::UserUpdateBranchResponse.new } + +    subject { client.user_update_branch(branch_name, user, newrev, oldrev) } + +    it 'sends a user_update_branch message' do +      expect_any_instance_of(Gitaly::OperationService::Stub) +        .to receive(:user_update_branch).with(request, kind_of(Hash)) +        .and_return(response) + +      subject +    end + +    context "when pre_receive_error is present" do +      let(:response) do +        Gitaly::UserUpdateBranchResponse.new(pre_receive_error: "something failed") +      end + +      it "throws a PreReceive exception" do +        expect_any_instance_of(Gitaly::OperationService::Stub) +          .to receive(:user_update_branch).with(request, kind_of(Hash)) +          .and_return(response) + +        expect { subject }.to raise_error( +          Gitlab::Git::PreReceiveError, "something failed") +      end +    end +  end +    describe '#user_delete_branch' do      let(:branch_name) { 'my-branch' }      let(:request) do | 
