Commit ba0cf469 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fj-10871-import-lfs-object-in-pull-mirror' into 'master'

Copy LFS objects when a repository is pull mirrored

Closes #10871

See merge request gitlab-org/gitlab-ee!10779
parents bff46421 11e9e518
......@@ -7,6 +7,10 @@ module MirrorHelper
project_mirror_endpoint: project_mirror_path(@project, :json)
}
end
def mirror_lfs_sync_message
_('The Git LFS objects will <strong>not</strong> be synced.').html_safe
end
end
MirrorHelper.prepend(EE::MirrorHelper)
......@@ -7,7 +7,7 @@
%li
- 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 }
%li= _('The Git LFS objects will <strong>not</strong> be synced.').html_safe
%li= mirror_lfs_sync_message
%li
= _('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.')
......@@ -36,5 +36,12 @@ module EE
count = project.mirror == true ? 1 : 0
count + @project.remote_mirrors.to_a.count { |mirror| mirror.enabled }
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
......@@ -19,6 +19,7 @@ module Projects
end
update_branches
update_lfs_objects
success
rescue Gitlab::Shell::Error, Gitlab::Git::BaseError, UpdateError => e
......@@ -94,6 +95,12 @@ module Projects
fetch_result
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)
if project.mirror_overwrites_diverged_branches?
newrev = upstream.dereferenced_target.sha
......
......@@ -6,7 +6,7 @@
Mirror repository
.form-text.text-muted
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?
.form-text.text-muted
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
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
stub_fetch_mirror(project)
......
......@@ -5712,6 +5712,9 @@ msgstr ""
msgid "Git LFS is not enabled on this GitLab server, contact your admin."
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"
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