Rewrite and improve git backend logic. Fix project movind. Raise exception to prevent unexpected issues
This commit is contained in:
parent
70bf7f6e19
commit
f5551efdfd
20 changed files with 146 additions and 99 deletions
|
@ -35,6 +35,10 @@ class Namespace < ActiveRecord::Base
|
|||
where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
|
||||
end
|
||||
|
||||
def self.global_id
|
||||
'GLN'
|
||||
end
|
||||
|
||||
def to_param
|
||||
path
|
||||
end
|
||||
|
@ -51,6 +55,9 @@ class Namespace < ActiveRecord::Base
|
|||
def move_dir
|
||||
old_path = File.join(Gitlab.config.git_base_path, path_was)
|
||||
new_path = File.join(Gitlab.config.git_base_path, path)
|
||||
if File.exists?(new_path)
|
||||
raise "Already exists"
|
||||
end
|
||||
system("mv #{old_path} #{new_path}")
|
||||
end
|
||||
|
||||
|
|
|
@ -111,12 +111,14 @@ class Project < ActiveRecord::Base
|
|||
|
||||
# Apply namespace if user has access to it
|
||||
# else fallback to user namespace
|
||||
project.namespace_id = user.namespace_id
|
||||
if namespace_id != Namespace.global_id
|
||||
project.namespace_id = user.namespace_id
|
||||
|
||||
if namespace_id
|
||||
group = Group.find_by_id(namespace_id)
|
||||
if user.can? :manage_group, group
|
||||
project.namespace_id = namespace_id
|
||||
if namespace_id
|
||||
group = Group.find_by_id(namespace_id)
|
||||
if user.can? :manage_group, group
|
||||
project.namespace_id = namespace_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -254,12 +256,16 @@ class Project < ActiveRecord::Base
|
|||
old_dir = old_namespace.try(:path) || ''
|
||||
new_dir = new_namespace.try(:path) || ''
|
||||
|
||||
old_repo = File.join(old_dir, self.path)
|
||||
|
||||
git_host.move_repository(old_repo, self.path_with_namespace, self)
|
||||
old_repo = if old_dir.present?
|
||||
File.join(old_dir, self.path)
|
||||
else
|
||||
self.path
|
||||
end
|
||||
|
||||
Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
|
||||
|
||||
git_host.move_repository(old_repo, self.path_with_namespace, self)
|
||||
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue