Commit c0a78957 authored by Tiago Botelho's avatar Tiago Botelho

Adds skip_branch method to remote mirror update service

parent cf6fbda0
...@@ -102,7 +102,7 @@ module Projects ...@@ -102,7 +102,7 @@ module Projects
end end
def skip_branch?(name) def skip_branch?(name)
project.only_mirror_protected_branches && !ProtectedBranch.protected?(project,name) project.only_mirror_protected_branches && !ProtectedBranch.protected?(project, name)
end end
end end
end end
...@@ -31,9 +31,7 @@ module Projects ...@@ -31,9 +31,7 @@ module Projects
def local_branches def local_branches
@local_branches ||= repository.local_branches.each_with_object({}) do |branch, branches| @local_branches ||= repository.local_branches.each_with_object({}) do |branch, branches|
next if mirror.only_protected_branches? && !protected_branch?(branch.name) branches[branch.name] = branch unless skip_branch?(branch.name)
branches[branch.name] = branch
end end
end end
...@@ -115,7 +113,7 @@ module Projects ...@@ -115,7 +113,7 @@ module Projects
remote_refs.each_with_object([]) do |(name, remote_ref), refs_to_delete| remote_refs.each_with_object([]) do |(name, remote_ref), refs_to_delete|
next if local_refs[name] # skip if branch or tag exist in local repo next if local_refs[name] # skip if branch or tag exist in local repo
next if type == :branches && mirror.only_protected_branches? && !protected_branch?(name) next if type == :branches && skip_branch?(name)
remote_ref_id = remote_ref.dereferenced_target.try(:id) remote_ref_id = remote_ref.dereferenced_target.try(:id)
...@@ -125,8 +123,8 @@ module Projects ...@@ -125,8 +123,8 @@ module Projects
end end
end end
def protected_branch?(name) def skip_branch?(name)
ProtectedBranch.protected?(project, name) mirror.only_protected_branches? && !ProtectedBranch.protected?(project, name)
end end
end end
end end
...@@ -63,14 +63,9 @@ describe Gitlab::BackgroundMigration::PopulateForkNetworksRange, :migration, sch ...@@ -63,14 +63,9 @@ describe Gitlab::BackgroundMigration::PopulateForkNetworksRange, :migration, sch
expect(base2_membership).not_to be_nil expect(base2_membership).not_to be_nil
end end
<<<<<<< HEAD
it 'creates a fork network for the fork of which the source was deleted' do it 'creates a fork network for the fork of which the source was deleted' do
fork = create(:project) fork = projects.create
forked_project_links.create(id: 6, forked_from_project_id: 99999, forked_to_project_id: fork.id) forked_project_links.create(id: 6, forked_from_project_id: 99999, forked_to_project_id: fork.id)
=======
it 'skips links that had their source project deleted' do
forked_project_links.create(id: 6, forked_from_project_id: 99999, forked_to_project_id: projects.create.id)
>>>>>>> Create models directly in migration specs
migration.perform(5, 8) migration.perform(5, 8)
......
...@@ -74,7 +74,7 @@ describe Projects::UpdateMirrorService do ...@@ -74,7 +74,7 @@ describe Projects::UpdateMirrorService do
expect(project.repository.branch_names).to include(new_protected_branch_name) expect(project.repository.branch_names).to include(new_protected_branch_name)
end end
it 'does not create a unprotected branch' do it 'does not create an unprotected branch' do
stub_fetch_mirror(project) stub_fetch_mirror(project)
described_class.new(project, project.owner).execute described_class.new(project, project.owner).execute
......
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