Use gitlab-shell to move repos. Requires gitlab-shell v1.1.0
This commit is contained in:
parent
b1e425511f
commit
59b36f2032
6 changed files with 71 additions and 125 deletions
|
@ -3,29 +3,27 @@
|
|||
# Used for transfer project to another namespace
|
||||
#
|
||||
class ProjectTransferService
|
||||
include Gitolited
|
||||
|
||||
attr_accessor :project
|
||||
|
||||
def transfer(project, new_namespace)
|
||||
Project.transaction do
|
||||
old_namespace = project.namespace
|
||||
project.namespace = new_namespace
|
||||
|
||||
old_dir = old_namespace.try(:path) || ''
|
||||
new_dir = new_namespace.try(:path) || ''
|
||||
|
||||
old_repo = if old_dir.present?
|
||||
File.join(old_dir, project.path)
|
||||
else
|
||||
project.path
|
||||
end
|
||||
old_path = project.path_with_namespace
|
||||
new_path = File.join(new_namespace.try(:path) || '', project.path)
|
||||
|
||||
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
|
||||
|
||||
Gitlab::ProjectMover.new(project, old_dir, new_dir).execute
|
||||
|
||||
project.namespace = new_namespace
|
||||
project.save!
|
||||
|
||||
unless gitlab_shell.mv_repository(old_path, new_path)
|
||||
raise TransferError.new('Cannot move project')
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
rescue Gitlab::ProjectMover::ProjectMoveError => ex
|
||||
raise Project::TransferError.new(ex.message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue