Commit 16e89580 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'feature/migrate-is-rebase-in-progress-to-gitaly' into 'master'

Migrate rebase_in_progress? to Gitaly

Closes gitaly#866

See merge request gitlab-org/gitlab-ce!16286
parents 58724265 92d62ff6
...@@ -1254,7 +1254,13 @@ module Gitlab ...@@ -1254,7 +1254,13 @@ module Gitlab
end end
def rebase_in_progress?(rebase_id) def rebase_in_progress?(rebase_id)
fresh_worktree?(worktree_path(REBASE_WORKTREE_PREFIX, rebase_id)) gitaly_migrate(:rebase_in_progress) do |is_enabled|
if is_enabled
gitaly_repository_client.rebase_in_progress?(rebase_id)
else
fresh_worktree?(worktree_path(REBASE_WORKTREE_PREFIX, rebase_id))
end
end
end end
def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:) def squash(user, squash_id, branch:, start_sha:, end_sha:, author:, message:)
......
...@@ -100,6 +100,23 @@ module Gitlab ...@@ -100,6 +100,23 @@ module Gitlab
) )
end end
def rebase_in_progress?(rebase_id)
request = Gitaly::IsRebaseInProgressRequest.new(
repository: @gitaly_repo,
rebase_id: rebase_id.to_s
)
response = GitalyClient.call(
@storage,
:repository_service,
:is_rebase_in_progress,
request,
timeout: GitalyClient.default_timeout
)
response.in_progress
end
def fetch_source_branch(source_repository, source_branch, local_ref) def fetch_source_branch(source_repository, source_branch, local_ref)
request = Gitaly::FetchSourceBranchRequest.new( request = Gitaly::FetchSourceBranchRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
......
...@@ -1910,38 +1910,44 @@ describe MergeRequest do ...@@ -1910,38 +1910,44 @@ describe MergeRequest do
end end
describe '#rebase_in_progress?' do describe '#rebase_in_progress?' do
# Create merge request and project before we stub file calls shared_examples 'checking whether a rebase is in progress' do
before do let(:repo_path) { subject.source_project.repository.path }
subject let(:rebase_path) { File.join(repo_path, "gitlab-worktree", "rebase-#{subject.id}") }
end
it 'returns true when there is a current rebase directory' do before do
allow(File).to receive(:exist?).and_return(true) system(*%W(#{Gitlab.config.git.bin_path} -C #{repo_path} worktree add --detach #{rebase_path} master))
allow(File).to receive(:mtime).and_return(Time.now) end
expect(subject.rebase_in_progress?).to be_truthy it 'returns true when there is a current rebase directory' do
end expect(subject.rebase_in_progress?).to be_truthy
end
it 'returns false when there is no rebase directory' do it 'returns false when there is no rebase directory' do
allow(File).to receive(:exist?).and_return(false) FileUtils.rm_rf(rebase_path)
expect(subject.rebase_in_progress?).to be_falsey expect(subject.rebase_in_progress?).to be_falsey
end end
it 'returns false when the rebase directory has expired' do
time = 20.minutes.ago.to_time
File.utime(time, time, rebase_path)
it 'returns false when the rebase directory has expired' do expect(subject.rebase_in_progress?).to be_falsey
allow(File).to receive(:exist?).and_return(true) end
allow(File).to receive(:mtime).and_return(20.minutes.ago)
expect(subject.rebase_in_progress?).to be_falsey it 'returns false when the source project has been removed' do
allow(subject).to receive(:source_project).and_return(nil)
expect(subject.rebase_in_progress?).to be_falsey
end
end end
it 'returns false when the source project has been removed' do context 'when Gitaly rebase_in_progress is enabled' do
allow(subject).to receive(:source_project).and_return(nil) it_behaves_like 'checking whether a rebase is in progress'
allow(File).to receive(:exist?).and_return(true) end
allow(File).to receive(:mtime).and_return(Time.now)
expect(File).not_to have_received(:exist?) context 'when Gitaly rebase_in_progress is enabled', :disable_gitaly do
expect(subject.rebase_in_progress?).to be_falsey it_behaves_like 'checking whether a rebase is in progress'
end end
end end
end end
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