Port of 51725-push-mirrors-default-branch-reset-to-master to EE

parent 3c77a0b5
......@@ -2088,12 +2088,6 @@ class Project < ActiveRecord::Base
auto_cancel_pending_pipelines == 'enabled'
end
# Update the default branch querying the remote to determine its HEAD
def update_root_ref(remote_name)
root_ref = repository.find_remote_root_ref(remote_name)
change_head(root_ref) if root_ref.present? && root_ref != default_branch
end
private
# rubocop: disable CodeReuse/ServiceClass
......
......@@ -29,7 +29,6 @@ class Repository
delegate :ref_name_for_sha, to: :raw_repository
delegate :bundle_to_disk, to: :raw_repository
delegate :find_remote_root_ref, to: :raw_repository
CreateTreeError = Class.new(StandardError)
......
......@@ -549,6 +549,12 @@ module EE
end
end
# Update the default branch querying the remote to determine its HEAD
def update_root_ref(remote_name)
root_ref = repository.find_remote_root_ref(remote_name)
change_head(root_ref) if root_ref.present? && root_ref != default_branch
end
private
def set_override_pull_mirror_available
......
......@@ -10,7 +10,7 @@ module EE
MIRROR_REMOTE = "upstream".freeze
prepended do
delegate :checksum, to: :raw_repository
delegate :checksum, :find_remote_root_ref, to: :raw_repository
end
# Transiently sets a configuration variable
......
......@@ -4298,40 +4298,6 @@ describe Project do
end
end
describe '#update_root_ref' do
let(:project) { create(:project, :repository) }
it 'updates the default branch when HEAD has changed' do
stub_find_remote_root_ref(project, ref: 'feature')
expect { project.update_root_ref('origin') }
.to change { project.default_branch }
.from('master')
.to('feature')
end
it 'does not update the default branch when HEAD does not change' do
stub_find_remote_root_ref(project, ref: 'master')
expect { project.update_root_ref('origin') }
.not_to change { project.default_branch }
end
it 'does not update the default branch when HEAD does not exist' do
stub_find_remote_root_ref(project, ref: 'foo')
expect { project.update_root_ref('origin') }
.not_to change { project.default_branch }
end
def stub_find_remote_root_ref(project, ref:)
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('origin')
.and_return(ref)
end
end
def rugged_config
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
project.repository.rugged.config
......
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