class for moving project
This commit is contained in:
parent
d71a68af41
commit
4023d9f852
5 changed files with 56 additions and 24 deletions
37
lib/gitlab/project_mover.rb
Normal file
37
lib/gitlab/project_mover.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
# ProjectMover class
|
||||
#
|
||||
# Used for moving project repositories from one subdir to another
|
||||
module Gitlab
|
||||
class ProjectMover
|
||||
attr_reader :project, :old_dir, :new_dir
|
||||
|
||||
def initialize(project, old_dir, new_dir)
|
||||
@project = project
|
||||
@old_dir = old_dir
|
||||
@new_dir = new_dir
|
||||
end
|
||||
|
||||
def execute
|
||||
# Create new dir if missing
|
||||
new_dir_path = File.join(Gitlab.config.git_base_path, new_dir)
|
||||
Dir.mkdir(new_dir_path) unless File.exists?(new_dir_path)
|
||||
|
||||
old_path = File.join(Gitlab.config.git_base_path, old_dir, "#{project.path}.git")
|
||||
new_path = File.join(new_dir_path, "#{project.path}.git")
|
||||
|
||||
if system("mv #{old_path} #{new_path}")
|
||||
log_info "Project #{project.name} was moved from #{old_path} to #{new_path}"
|
||||
true
|
||||
else
|
||||
log_info "Error! Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def log_info message
|
||||
Gitlab::AppLogger.info message
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue