Skip to content

Commit d5d8e76

Browse files
committed
Block renaming project or repository if it has container registry tags
1 parent b5043d5 commit d5d8e76

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

app/models/namespace.rb

+8
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def move_dir
127127
# Ensure old directory exists before moving it
128128
gitlab_shell.add_namespace(path_was)
129129

130+
if any_project_has_container_registry_tags?
131+
raise Exception.new('namespace cannot be moved, because at least one project has tags in container registry')
132+
end
133+
130134
if gitlab_shell.mv_namespace(path_was, path)
131135
Gitlab::UploadsTransfer.new.rename_namespace(path_was, path)
132136

@@ -148,6 +152,10 @@ def move_dir
148152
end
149153
end
150154

155+
def any_project_has_container_registry_tags?
156+
projects.any?(:has_container_registry_tags?)
157+
end
158+
151159
def send_update_instructions
152160
projects.each do |project|
153161
project.send_move_instructions("#{path_was}/#{project.path}")

app/models/project.rb

+11
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ def container_registry_repository_url
391391
end
392392
end
393393

394+
def has_container_registry_tags?
395+
if container_registry_enabled? && Gitlab.config.registry.enabled
396+
container_registry_repository.tags.any?
397+
end
398+
end
399+
394400
def commit(id = 'HEAD')
395401
repository.commit(id)
396402
end
@@ -806,6 +812,11 @@ def rename_repo
806812

807813
expire_caches_before_rename(old_path_with_namespace)
808814

815+
if has_container_registry_tags?
816+
# we currently doesn't support renaming repository if it contains tags in container registry
817+
raise Exception.new('repository cannot be renamed, due to tags in container registry')
818+
end
819+
809820
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
810821
# If repository moved successfully we need to send update instructions to users.
811822
# However we cannot allow rollback since we moved repository

app/services/projects/transfer_service.rb

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def transfer(project, new_namespace)
3434
raise TransferError.new("Project with same path in target namespace already exists")
3535
end
3636

37+
if project.has_container_registry_tags?
38+
# we currently doesn't support renaming repository if it contains tags in container registry
39+
raise TransferError.new('Repository cannot be renamed, due to tags in container registry')
40+
end
41+
3742
project.expire_caches_before_rename(old_path)
3843

3944
# Apply new namespace id and visibility level

0 commit comments

Comments
 (0)