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
|
|
|
|
2017-11-30 21:34:31 +00:00
|
|
|
def perform(project_id, forked_from_repository_storage_path, source_disk_path)
|
2017-08-17 09:00:31 +00:00
|
|
|
project = Project.find(project_id)
|
|
|
|
|
|
|
|
return unless start_fork(project)
|
|
|
|
|
2016-08-16 14:18:48 +00:00
|
|
|
Gitlab::Metrics.add_event(:fork_repository,
|
2017-11-30 21:34:31 +00:00
|
|
|
source_path: source_disk_path,
|
|
|
|
target_path: project.disk_path)
|
2016-08-16 14:18:48 +00:00
|
|
|
|
2017-11-30 21:34:31 +00:00
|
|
|
result = gitlab_shell.fork_repository(forked_from_repository_storage_path, source_disk_path,
|
|
|
|
project.repository_storage_path, project.disk_path)
|
2017-12-11 11:35:03 +00:00
|
|
|
raise "Unable to fork project #{project_id} for repository #{source_disk_path} -> #{project.disk_path}" unless result
|
2015-09-01 07:56:40 +00:00
|
|
|
|
2018-01-14 11:12:43 +00:00
|
|
|
project.after_import
|
2017-06-01 14:27:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
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
|