Move directory with project. Fixed all related path methods to use namespace
This commit is contained in:
parent
e29ccece33
commit
71214bee75
9 changed files with 55 additions and 10 deletions
|
@ -1,6 +1,11 @@
|
|||
class ProjectObserver < ActiveRecord::Observer
|
||||
def after_save(project)
|
||||
project.update_repository
|
||||
|
||||
# Move repository if namespace changed
|
||||
if project.namespace_id_changed?
|
||||
move_project(project)
|
||||
end
|
||||
end
|
||||
|
||||
def after_destroy(project)
|
||||
|
@ -18,4 +23,19 @@ class ProjectObserver < ActiveRecord::Observer
|
|||
def log_info message
|
||||
Gitlab::AppLogger.info message
|
||||
end
|
||||
|
||||
def move_project(project)
|
||||
old_dir = Namespace.find_by_id(project.namespace_id_was).try(:code) || ''
|
||||
new_dir = Namespace.find_by_id(project.namespace_id).try(:code) || ''
|
||||
|
||||
# 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")
|
||||
|
||||
binding.pry
|
||||
`mv #{old_path} #{new_path}`
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue