Commit d6c9cf92 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'osw-remove-transaction-while-rebasing' into 'master'

Remove DB transaction from Rebase Gitaly operation

See merge request gitlab-org/gitlab!20739
parents 354ebce7 bdfafc7a
...@@ -1052,18 +1052,19 @@ class Repository ...@@ -1052,18 +1052,19 @@ class Repository
return rebase_deprecated(user, merge_request) return rebase_deprecated(user, merge_request)
end end
MergeRequest.transaction do raw.rebase(
raw.rebase( user,
user, merge_request.id,
merge_request.id, branch: merge_request.source_branch,
branch: merge_request.source_branch, branch_sha: merge_request.source_branch_sha,
branch_sha: merge_request.source_branch_sha, remote_repository: merge_request.target_project.repository.raw,
remote_repository: merge_request.target_project.repository.raw, remote_branch: merge_request.target_branch
remote_branch: merge_request.target_branch ) do |commit_id|
) do |commit_id| merge_request.update!(rebase_commit_sha: commit_id, merge_error: nil)
merge_request.update!(rebase_commit_sha: commit_id, merge_error: nil)
end
end end
rescue StandardError => error
merge_request.update!(rebase_commit_sha: nil)
raise error
end end
def squash(user, merge_request, message) 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 ...@@ -1530,7 +1530,7 @@ describe Repository do
expect(merge_request.reload.rebase_commit_sha).to eq(new_sha) expect(merge_request.reload.rebase_commit_sha).to eq(new_sha)
end 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) second_response = double(pre_receive_error: 'my_error', git_error: nil)
mock_gitaly(second_response) mock_gitaly(second_response)
...@@ -1541,6 +1541,17 @@ describe Repository do ...@@ -1541,6 +1541,17 @@ describe Repository do
expect(merge_request.reload.rebase_commit_sha).to be_nil expect(merge_request.reload.rebase_commit_sha).to be_nil
end 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) def mock_gitaly(second_response)
responses = [ responses = [
double(rebase_sha: new_sha).as_null_object, 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