Skip to content
Snippets Groups Projects
Unverified Commit 95114453 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Doesn't synchronize default branch for push mirrors

We should not synchronize the source repository with
the target root ref while updating a push mirror.
parent 8f191590
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Loading
Loading
@@ -2076,12 +2076,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
Loading
Loading
Loading
Loading
@@ -24,7 +24,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)
 
Loading
Loading
Loading
Loading
@@ -12,7 +12,6 @@ module Projects
begin
remote_mirror.ensure_remote!
repository.fetch_remote(remote_mirror.remote_name, no_tags: true)
project.update_root_ref(remote_mirror.remote_name)
 
opts = {}
if remote_mirror.only_protected_branches?
Loading
Loading
Loading
Loading
@@ -3983,40 +3983,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
Loading
Loading
Loading
Loading
@@ -17,7 +17,6 @@ describe Projects::UpdateRemoteMirrorService do
 
it "ensures the remote exists" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name)
 
expect(remote_mirror).to receive(:ensure_remote!)
 
Loading
Loading
@@ -25,8 +24,6 @@ describe Projects::UpdateRemoteMirrorService do
end
 
it "fetches the remote repository" do
stub_find_remote_root_ref(project, remote_name: remote_name)
expect(project.repository)
.to receive(:fetch_remote)
.with(remote_mirror.remote_name, no_tags: true)
Loading
Loading
@@ -34,26 +31,8 @@ describe Projects::UpdateRemoteMirrorService do
service.execute(remote_mirror)
end
 
it "updates the default branch when HEAD has changed" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name, ref: "existing-branch")
expect { service.execute(remote_mirror) }
.to change { project.default_branch }
.from("master")
.to("existing-branch")
end
it "does not update the default branch when HEAD does not change" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name, ref: "master")
expect { service.execute(remote_mirror) }.not_to change { project.default_branch }
end
it "returns success when updated succeeds" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name)
 
result = service.execute(remote_mirror)
 
Loading
Loading
@@ -63,7 +42,6 @@ describe Projects::UpdateRemoteMirrorService do
context 'when syncing all branches' do
it "push all the branches the first time" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name)
 
expect(remote_mirror).to receive(:update_repository).with({})
 
Loading
Loading
@@ -74,7 +52,6 @@ describe Projects::UpdateRemoteMirrorService do
context 'when only syncing protected branches' do
it "sync updated protected branches" do
stub_fetch_remote(project, remote_name: remote_name)
stub_find_remote_root_ref(project, remote_name: remote_name)
protected_branch = create_protected_branch(project)
remote_mirror.only_protected_branches = true
 
Loading
Loading
@@ -92,13 +69,6 @@ describe Projects::UpdateRemoteMirrorService do
end
end
 
def stub_find_remote_root_ref(project, ref: 'master', remote_name:)
allow(project.repository)
.to receive(:find_remote_root_ref)
.with(remote_name)
.and_return(ref)
end
def stub_fetch_remote(project, remote_name:)
allow(project.repository)
.to receive(:fetch_remote)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment