From 8cf0ea4469290815daa1d64c4f3e16cbba8c00c1 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 22 Dec 2017 16:58:05 +0100 Subject: [PATCH 1/3] Handle Gitaly aborted merge due to branch update --- lib/gitlab/gitaly_client/operation_service.rb | 1 + spec/lib/gitlab/git/repository_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/gitlab/gitaly_client/operation_service.rb b/lib/gitlab/gitaly_client/operation_service.rb index c7732764880..ae1753ff0ae 100644 --- a/lib/gitlab/gitaly_client/operation_service.rb +++ b/lib/gitlab/gitaly_client/operation_service.rb @@ -101,6 +101,7 @@ module Gitlab request_enum.push(Gitaly::UserMergeBranchRequest.new(apply: true)) branch_update = response_enum.next.branch_update + return if branch_update.nil? raise Gitlab::Git::CommitError.new('failed to apply merge to branch') unless branch_update.commit_id.present? Gitlab::Git::OperationService::BranchUpdate.from_gitaly(branch_update) diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 0e4292026df..c8ed0494f68 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1719,6 +1719,20 @@ describe Gitlab::Git::Repository, seed_helper: true do expect(result.repo_created).to eq(false) expect(result.branch_created).to eq(false) end + + it 'returns nil if there was a concurrent branch update' do + concurrent_update_id = '33f3729a45c02fc67d00adb1b8bca394b0e761d9' + result = repository.merge(user, source_sha, target_branch, 'Test merge') do + # This ref update should make the merge fail + repository.write_ref(Gitlab::Git::BRANCH_REF_PREFIX + target_branch, concurrent_update_id) + end + + # This 'nil' signals that the merge was not applied + expect(result).to be_nil + + # Our concurrent ref update should not have been reversed + expect(repository.find_branch(target_branch).target).to eq(concurrent_update_id) + end end context 'with gitaly' do From 8d8550c78ba0b7d6ac4a26b77b9b2def203d4eec Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 3 Jan 2018 12:44:57 +0100 Subject: [PATCH 2/3] Fix method lookup --- lib/gitlab/gitaly_client/conflicts_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/gitaly_client/conflicts_service.rb b/lib/gitlab/gitaly_client/conflicts_service.rb index 1e631e4bd3d..40f032cf873 100644 --- a/lib/gitlab/gitaly_client/conflicts_service.rb +++ b/lib/gitlab/gitaly_client/conflicts_service.rb @@ -1,6 +1,8 @@ module Gitlab module GitalyClient class ConflictsService + include Gitlab::EncodingHelper + MAX_MSG_SIZE = 128.kilobytes.freeze def initialize(repository, our_commit_oid, their_commit_oid) @@ -22,7 +24,7 @@ module Gitlab end def resolve_conflicts(target_repository, resolution, source_branch, target_branch) - reader = GitalyClient.binary_stringio(resolution.files.to_json) + reader = binary_stringio(resolution.files.to_json) req_enum = Enumerator.new do |y| header = resolve_conflicts_request_header(target_repository, resolution, source_branch, target_branch) From 449b59ec69f7da2be9e75fdaf282592f048b9853 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 3 Jan 2018 12:54:47 +0100 Subject: [PATCH 3/3] Better English --- spec/lib/gitlab/git/repository_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index c8ed0494f68..21379ae0f45 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1730,7 +1730,7 @@ describe Gitlab::Git::Repository, seed_helper: true do # This 'nil' signals that the merge was not applied expect(result).to be_nil - # Our concurrent ref update should not have been reversed + # Our concurrent ref update should not have been undone expect(repository.find_branch(target_branch).target).to eq(concurrent_update_id) end end