2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-01 07:56:40 +00:00
|
|
|
class RepositoryForkWorker
|
2017-11-28 16:08:30 +00:00
|
|
|
include ApplicationWorker
|
2015-09-01 07:56:40 +00:00
|
|
|
include Gitlab::ShellAdapter
|
2017-10-10 09:09:49 +00:00
|
|
|
include ProjectStartImport
|
2017-12-11 11:35:03 +00:00
|
|
|
include ProjectImportOptions
|
2017-08-17 09:00:31 +00:00
|
|
|
|
2018-03-26 18:21:49 +00:00
|
|
|
def perform(*args)
|
|
|
|
target_project_id = args.shift
|
|
|
|
target_project = Project.find(target_project_id)
|
2017-08-17 09:00:31 +00:00
|
|
|
|
2018-06-19 10:17:54 +00:00
|
|
|
source_project = target_project.forked_from_project
|
|
|
|
unless source_project
|
|
|
|
return target_project.mark_import_as_failed('Source project cannot be found.')
|
2018-03-26 18:21:49 +00:00
|
|
|
end
|
2018-06-19 10:17:54 +00:00
|
|
|
|
|
|
|
fork_repository(target_project, source_project.repository_storage, source_project.disk_path)
|
2017-06-01 14:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-03-26 18:21:49 +00:00
|
|
|
def fork_repository(target_project, source_repository_storage_name, source_disk_path)
|
|
|
|
return unless start_fork(target_project)
|
|
|
|
|
2018-06-19 17:03:25 +00:00
|
|
|
Gitlab::Metrics.add_event(:fork_repository)
|
2018-03-26 18:21:49 +00:00
|
|
|
|
|
|
|
result = gitlab_shell.fork_repository(source_repository_storage_name, source_disk_path,
|
|
|
|
target_project.repository_storage, target_project.disk_path)
|
|
|
|
raise "Unable to fork project #{target_project.id} for repository #{source_disk_path} -> #{target_project.disk_path}" unless result
|
|
|
|
|
|
|
|
target_project.after_import
|
|
|
|
end
|
|
|
|
|
2017-08-17 09:00:31 +00:00
|
|
|
def start_fork(project)
|
2017-10-10 09:09:49 +00:00
|
|
|
return true if start(project)
|
2017-08-17 09:00:31 +00:00
|
|
|
|
|
|
|
Rails.logger.info("Project #{project.full_path} was in inconsistent state (#{project.import_status}) while forking.")
|
|
|
|
false
|
|
|
|
end
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|