Read about our upcoming Code of Conduct on this issue

Commit d5d8e76b authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Block renaming project or repository if it has container registry tags

parent 864735c07fc0
...@@ -127,6 +127,10 @@ def move_dir ...@@ -127,6 +127,10 @@ def move_dir
# Ensure old directory exists before moving it # Ensure old directory exists before moving it
gitlab_shell.add_namespace(path_was) gitlab_shell.add_namespace(path_was)
if any_project_has_container_registry_tags?
raise Exception.new('namespace cannot be moved, because at least one project has tags in container registry')
end
if gitlab_shell.mv_namespace(path_was, path) if gitlab_shell.mv_namespace(path_was, path)
Gitlab::UploadsTransfer.new.rename_namespace(path_was, path) Gitlab::UploadsTransfer.new.rename_namespace(path_was, path)
...@@ -148,6 +152,10 @@ def move_dir ...@@ -148,6 +152,10 @@ def move_dir
end end
end end
def any_project_has_container_registry_tags?
projects.any?(:has_container_registry_tags?)
end
def send_update_instructions def send_update_instructions
projects.each do |project| projects.each do |project|
project.send_move_instructions("#{path_was}/#{project.path}") project.send_move_instructions("#{path_was}/#{project.path}")
......
...@@ -391,6 +391,12 @@ def container_registry_repository_url ...@@ -391,6 +391,12 @@ def container_registry_repository_url
end end
end end
def has_container_registry_tags?
if container_registry_enabled? && Gitlab.config.registry.enabled
container_registry_repository.tags.any?
end
end
def commit(id = 'HEAD') def commit(id = 'HEAD')
repository.commit(id) repository.commit(id)
end end
...@@ -806,6 +812,11 @@ def rename_repo ...@@ -806,6 +812,11 @@ def rename_repo
expire_caches_before_rename(old_path_with_namespace) expire_caches_before_rename(old_path_with_namespace)
if has_container_registry_tags?
# we currently doesn't support renaming repository if it contains tags in container registry
raise Exception.new('repository cannot be renamed, due to tags in container registry')
end
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace) if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
# If repository moved successfully we need to send update instructions to users. # If repository moved successfully we need to send update instructions to users.
# However we cannot allow rollback since we moved repository # However we cannot allow rollback since we moved repository
......
...@@ -34,6 +34,11 @@ def transfer(project, new_namespace) ...@@ -34,6 +34,11 @@ def transfer(project, new_namespace)
raise TransferError.new("Project with same path in target namespace already exists") raise TransferError.new("Project with same path in target namespace already exists")
end end
if project.has_container_registry_tags?
# we currently doesn't support renaming repository if it contains tags in container registry
raise TransferError.new('Repository cannot be renamed, due to tags in container registry')
end
project.expire_caches_before_rename(old_path) project.expire_caches_before_rename(old_path)
# Apply new namespace id and visibility level # Apply new namespace id and visibility level
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment