Commit 11e9e518 authored by Francisco Javier López's avatar Francisco Javier López Committed by Sean McGivern

Importing LFS objects in pull mirror

Added the feature to download LFS objects with pull mirrors. The
service used to download the LFS objects is the same one used for
project import.
parent bff46421
...@@ -7,6 +7,10 @@ module MirrorHelper ...@@ -7,6 +7,10 @@ module MirrorHelper
project_mirror_endpoint: project_mirror_path(@project, :json) project_mirror_endpoint: project_mirror_path(@project, :json)
} }
end end
def mirror_lfs_sync_message
_('The Git LFS objects will <strong>not</strong> be synced.').html_safe
end
end end
MirrorHelper.prepend(EE::MirrorHelper) MirrorHelper.prepend(EE::MirrorHelper)
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
%li %li
- minutes = Gitlab.config.gitlab_shell.git_timeout / 60 - minutes = Gitlab.config.gitlab_shell.git_timeout / 60
= _("The update action will time out after %{number_of_minutes} minutes. For big repositories, use a clone/push combination.") % { number_of_minutes: minutes } = _("The update action will time out after %{number_of_minutes} minutes. For big repositories, use a clone/push combination.") % { number_of_minutes: minutes }
%li= _('The Git LFS objects will <strong>not</strong> be synced.').html_safe %li= mirror_lfs_sync_message
%li %li
= _('This user will be the author of all events in the activity feed that are the result of an update, = _('This user will be the author of all events in the activity feed that are the result of an update,
like new branches being created or new commits being pushed to existing branches.') like new branches being created or new commits being pushed to existing branches.')
...@@ -36,5 +36,12 @@ module EE ...@@ -36,5 +36,12 @@ module EE
count = project.mirror == true ? 1 : 0 count = project.mirror == true ? 1 : 0
count + @project.remote_mirrors.to_a.count { |mirror| mirror.enabled } count + @project.remote_mirrors.to_a.count { |mirror| mirror.enabled }
end end
def mirror_lfs_sync_message
docs_link_url = help_page_path('workflow/lfs/manage_large_binaries_with_git_lfs')
docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: docs_link_url }
_('Git LFS objects will be synced in pull mirrors if LFS is %{docs_link_start}enabled for the project%{docs_link_end}. They will <strong>not</strong> be synced in push mirrors.').html_safe % { docs_link_start: docs_link_start, docs_link_end: '</a>'.html_safe }
end
end end
end end
...@@ -19,6 +19,7 @@ module Projects ...@@ -19,6 +19,7 @@ module Projects
end end
update_branches update_branches
update_lfs_objects
success success
rescue Gitlab::Shell::Error, Gitlab::Git::BaseError, UpdateError => e rescue Gitlab::Shell::Error, Gitlab::Git::BaseError, UpdateError => e
...@@ -94,6 +95,12 @@ module Projects ...@@ -94,6 +95,12 @@ module Projects
fetch_result fetch_result
end end
def update_lfs_objects
result = Projects::LfsPointers::LfsImportService.new(project).execute
raise UpdateError, result[:message] if result[:status] == :error
end
def handle_diverged_branch(upstream, local, branch_name, errors) def handle_diverged_branch(upstream, local, branch_name, errors)
if project.mirror_overwrites_diverged_branches? if project.mirror_overwrites_diverged_branches?
newrev = upstream.dereferenced_target.sha newrev = upstream.dereferenced_target.sha
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
Mirror repository Mirror repository
.form-text.text-muted .form-text.text-muted
Automatically update this project's branches and tags from the upstream Automatically update this project's branches and tags from the upstream
repository every hour. The Git LFS objects will not be synced. repository every hour.
- if Gitlab::CurrentSettings.should_check_namespace_plan? - if Gitlab::CurrentSettings.should_check_namespace_plan?
.form-text.text-muted .form-text.text-muted
Mirroring will only be available if the feature is included in the plan of the selected group or user. Mirroring will only be available if the feature is included in the plan of the selected group or user.
---
title: Copy LFS objects from pull mirror
merge_request: 10779
author:
type: added
...@@ -201,6 +201,45 @@ describe Projects::UpdateMirrorService do ...@@ -201,6 +201,45 @@ describe Projects::UpdateMirrorService do
end end
end end
context 'updating Lfs objects' do
before do
stub_fetch_mirror(project)
end
context 'when Lfs is disabled in the project' do
it 'does not update Lfs objects' do
allow(project).to receive(:lfs_enabled?).and_return(false)
expect(Projects::LfsPointers::LfsObjectDownloadListService).not_to receive(:new)
service.execute
end
end
context 'when Lfs is enabled in the project' do
before do
allow(project).to receive(:lfs_enabled?).and_return(true)
end
it 'updates Lfs objects' do
expect(Projects::LfsPointers::LfsImportService).to receive(:new).and_call_original
expect_any_instance_of(Projects::LfsPointers::LfsObjectDownloadListService).to receive(:execute).and_return({})
service.execute
end
context 'when Lfs import fails' do
it 'the mirror operation fails' do
expect_any_instance_of(Projects::LfsPointers::LfsImportService).to receive(:execute).and_return(status: :error, message: 'error message')
result = subject.execute
expect(result[:status]).to eq :error
expect(result[:message]).to eq 'error message'
end
end
end
end
it "fails when the mirror user doesn't have access" do it "fails when the mirror user doesn't have access" do
stub_fetch_mirror(project) stub_fetch_mirror(project)
......
...@@ -5712,6 +5712,9 @@ msgstr "" ...@@ -5712,6 +5712,9 @@ msgstr ""
msgid "Git LFS is not enabled on this GitLab server, contact your admin." msgid "Git LFS is not enabled on this GitLab server, contact your admin."
msgstr "" msgstr ""
msgid "Git LFS objects will be synced in pull mirrors if LFS is %{docs_link_start}enabled for the project%{docs_link_end}. They will <strong>not</strong> be synced in push mirrors."
msgstr ""
msgid "Git global setup" msgid "Git global setup"
msgstr "" msgstr ""
......
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