Commit bdfafc7a authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Remove DB transaction from Rebase operation

Instead keeping a transaction open, which can fail
if Gitaly takes more time than expected to process,
now we rescue possible Gitaly errors, cleaning up
the merge request object accordingly.
parent 0ac44e6b
......@@ -1052,18 +1052,19 @@ class Repository
return rebase_deprecated(user, merge_request)
end
MergeRequest.transaction do
raw.rebase(
user,
merge_request.id,
branch: merge_request.source_branch,
branch_sha: merge_request.source_branch_sha,
remote_repository: merge_request.target_project.repository.raw,
remote_branch: merge_request.target_branch
) do |commit_id|
merge_request.update!(rebase_commit_sha: commit_id, merge_error: nil)
end
raw.rebase(
user,
merge_request.id,
branch: merge_request.source_branch,
branch_sha: merge_request.source_branch_sha,
remote_repository: merge_request.target_project.repository.raw,
remote_branch: merge_request.target_branch
) do |commit_id|
merge_request.update!(rebase_commit_sha: commit_id, merge_error: nil)
end
rescue StandardError => error
merge_request.update!(rebase_commit_sha: nil)
raise error
end
def squash(user, merge_request, message)
......
---
title: Remove DB transaction from Rebase operation
merge_request: 20739
author:
type: fixed
......@@ -1530,7 +1530,7 @@ describe Repository do
expect(merge_request.reload.rebase_commit_sha).to eq(new_sha)
end
it 'does rollback when an error is encountered in the second step' do
it 'does rollback when a PreReceiveError is encountered in the second step' do
second_response = double(pre_receive_error: 'my_error', git_error: nil)
mock_gitaly(second_response)
......@@ -1541,6 +1541,17 @@ describe Repository do
expect(merge_request.reload.rebase_commit_sha).to be_nil
end
it 'does rollback when a GitError is encountered in the second step' do
second_response = double(pre_receive_error: nil, git_error: 'git error')
mock_gitaly(second_response)
expect do
repository.rebase(user, merge_request)
end.to raise_error(Gitlab::Git::Repository::GitError)
expect(merge_request.reload.rebase_commit_sha).to be_nil
end
def mock_gitaly(second_response)
responses = [
double(rebase_sha: new_sha).as_null_object,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment