Commit 229ac39a authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Bob Van Landuyt

Don't break rolling back when a namespace or project was renamed

parent 1ebb2255
...@@ -43,15 +43,15 @@ module Gitlab ...@@ -43,15 +43,15 @@ module Gitlab
reverts_for_type('namespace') do |path_before_rename, current_path| reverts_for_type('namespace') do |path_before_rename, current_path|
matches_path = MigrationClasses::Route.arel_table[:path].matches(current_path) matches_path = MigrationClasses::Route.arel_table[:path].matches(current_path)
namespace = MigrationClasses::Namespace.joins(:route) namespace = MigrationClasses::Namespace.joins(:route)
.where(matches_path).first.becomes(MigrationClasses::Namespace) .where(matches_path).first&.becomes(MigrationClasses::Namespace)
if namespace if namespace
perform_rename(namespace, current_path, path_before_rename) perform_rename(namespace, current_path, path_before_rename)
rename_namespace_dependencies(namespace, current_path, path_before_rename) rename_namespace_dependencies(namespace, current_path, path_before_rename)
else else
say "Couldn't rename namespace##{namespace.id} from #{current_path} "\ say "Couldn't rename namespace from #{current_path} back to #{path_before_rename} "\
" back to #{path_before_rename}, namespace no longer exists" "namespace was renamed, or no longer exists at the expected path"
end end
end end
end end
......
...@@ -38,8 +38,10 @@ module Gitlab ...@@ -38,8 +38,10 @@ module Gitlab
move_project_folders(project, current_path, path_before_rename) move_project_folders(project, current_path, path_before_rename)
else else
say "Couldn't rename project##{project.id} from #{current_path} "\ say "Couldn't rename Project from #{current_path} back to "\
"back to #{path_before_rename}, project no longer exists" "#{path_before_rename}, project was renamed or no longer "\
"exists at the expected path."
end end
end end
end end
......
...@@ -278,5 +278,12 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, : ...@@ -278,5 +278,12 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect(File.directory?(expected_path)).to be_truthy expect(File.directory?(expected_path)).to be_truthy
end end
it "doesn't break when the namespace was renamed" do
subject.rename_namespace(namespace)
namespace.update_attributes!(path: 'renamed-afterwards')
expect { subject.revert_renames }.not_to raise_error
end
end end
end end
...@@ -149,5 +149,12 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr ...@@ -149,5 +149,12 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr
expect(File.directory?(expected_path)).to be_truthy expect(File.directory?(expected_path)).to be_truthy
end end
it "doesn't break when the project was renamed" do
subject.rename_project(project)
project.update_attributes!(path: 'renamed-afterwards')
expect { subject.revert_renames }.not_to raise_error
end
end end
end end
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