Commit 12e97d39 authored by Stan Hu's avatar Stan Hu

Merge branch '51725-push-mirrors-default-branch-reset-to-master' into 'master'

Doesn't synchronize default branch for push mirrors

Closes #51725

See merge request gitlab-org/gitlab-ce!21861
parents 00bb83f7 44bf0c77
......@@ -2078,12 +2078,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
......
......@@ -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)
......
......@@ -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?
......
---
title: Doesn't synchronize the default branch for push mirrors
merge_request: 21861
author:
type: fixed
......@@ -3995,40 +3995,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
......
......@@ -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!)
......@@ -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)
......@@ -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)
......@@ -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({})
......@@ -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
......@@ -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)
......
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