2013-02-26 22:14:32 +01:00
|
|
|
# ProjectTransferService class
|
|
|
|
#
|
|
|
|
# Used for transfer project to another namespace
|
|
|
|
#
|
|
|
|
class ProjectTransferService
|
2013-03-21 20:01:14 +01:00
|
|
|
include Gitlab::ShellAdapter
|
2013-03-12 11:37:53 +01:00
|
|
|
|
2013-03-25 09:47:47 +01:00
|
|
|
class TransferError < StandardError; end
|
|
|
|
|
2013-02-26 22:14:32 +01:00
|
|
|
attr_accessor :project
|
|
|
|
|
|
|
|
def transfer(project, new_namespace)
|
|
|
|
Project.transaction do
|
2013-03-12 11:37:53 +01:00
|
|
|
old_path = project.path_with_namespace
|
|
|
|
new_path = File.join(new_namespace.try(:path) || '', project.path)
|
2013-02-26 22:14:32 +01:00
|
|
|
|
|
|
|
if Project.where(path: project.path, namespace_id: new_namespace.try(:id)).present?
|
|
|
|
raise TransferError.new("Project with same path in target namespace already exists")
|
|
|
|
end
|
|
|
|
|
2013-03-12 11:37:53 +01:00
|
|
|
project.namespace = new_namespace
|
2013-02-27 11:27:10 +01:00
|
|
|
project.save!
|
2013-03-12 11:37:53 +01:00
|
|
|
|
2013-03-25 09:47:47 +01:00
|
|
|
# Move main repository
|
2013-03-12 11:37:53 +01:00
|
|
|
unless gitlab_shell.mv_repository(old_path, new_path)
|
|
|
|
raise TransferError.new('Cannot move project')
|
|
|
|
end
|
|
|
|
|
2013-03-25 09:47:47 +01:00
|
|
|
# Move wiki repo also if present
|
2013-03-25 14:52:54 +01:00
|
|
|
gitlab_shell.mv_repository("#{old_path}.wiki", "#{new_path}.wiki")
|
2013-03-25 09:47:47 +01:00
|
|
|
|
2013-03-12 11:37:53 +01:00
|
|
|
true
|
2013-02-26 22:14:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|