summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/project.rb6
-rw-r--r--app/models/repository.rb1
-rw-r--r--app/services/projects/update_remote_mirror_service.rb1
-rw-r--r--changelogs/unreleased/51725-push-mirrors-default-branch-reset-to-master.yml5
-rw-r--r--spec/models/project_spec.rb34
-rw-r--r--spec/services/projects/update_remote_mirror_service_spec.rb30
6 files changed, 5 insertions, 72 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 3e14064a556..0a5099b27b1 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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
diff --git a/app/models/repository.rb b/app/models/repository.rb
index ad65881ff43..12fbf7d5d1d 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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)
diff --git a/app/services/projects/update_remote_mirror_service.rb b/app/services/projects/update_remote_mirror_service.rb
index 85b9eb02803..9d0877d1ab2 100644
--- a/app/services/projects/update_remote_mirror_service.rb
+++ b/app/services/projects/update_remote_mirror_service.rb
@@ -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?
diff --git a/changelogs/unreleased/51725-push-mirrors-default-branch-reset-to-master.yml b/changelogs/unreleased/51725-push-mirrors-default-branch-reset-to-master.yml
new file mode 100644
index 00000000000..b3caa119253
--- /dev/null
+++ b/changelogs/unreleased/51725-push-mirrors-default-branch-reset-to-master.yml
@@ -0,0 +1,5 @@
+---
+title: Doesn't synchronize the default branch for push mirrors
+merge_request: 21861
+author:
+type: fixed
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 567b66b54eb..afc9ea1917e 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -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
diff --git a/spec/services/projects/update_remote_mirror_service_spec.rb b/spec/services/projects/update_remote_mirror_service_spec.rb
index 56a36432462..cd903bfe8a5 100644
--- a/spec/services/projects/update_remote_mirror_service_spec.rb
+++ b/spec/services/projects/update_remote_mirror_service_spec.rb
@@ -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)