Commit 3ec81542 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-fix-geo-repository-move-worker' into 'master'

Fix broken Geo::MoveRepositoryService and add spec

Closes #1826

See merge request !1353
parents dc02c5da 7b5389ec
...@@ -16,14 +16,16 @@ module Geo ...@@ -16,14 +16,16 @@ module Geo
project.expire_caches_before_rename(old_path_with_namespace) project.expire_caches_before_rename(old_path_with_namespace)
# Make sure target directory exists (used when transfering repositories) # Make sure target directory exists (used when transfering repositories)
project.namespace.ensure_dir_exist project.ensure_dir_exist
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace) if gitlab_shell.mv_repository(project.repository_storage_path,
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
# So we basically we mute exceptions in next actions # So we basically we mute exceptions in next actions
begin begin
gitlab_shell.mv_repository("#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki") gitlab_shell.mv_repository(project.repository_storage_path,
"#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki")
rescue rescue
# Returning false does not rollback after_* transaction but gives # Returning false does not rollback after_* transaction but gives
# us information about failing some of tasks # us information about failing some of tasks
...@@ -34,6 +36,8 @@ module Geo ...@@ -34,6 +36,8 @@ module Geo
# db changes in order to prevent out of sync between db and fs # db changes in order to prevent out of sync between db and fs
raise Exception.new('repository cannot be renamed') raise Exception.new('repository cannot be renamed')
end end
true
end end
end end
end end
require 'spec_helper'
describe Geo::MoveRepositoryService, services: true do
let(:project) { create(:project) }
let(:new_path) { project.path_with_namespace + '+renamed' }
let(:full_new_path) { File.join(project.repository_storage_path, new_path) }
subject { Geo::MoveRepositoryService.new(project.id, project.name, project.path_with_namespace, new_path) }
describe '#execute' do
it 'renames the path' do
old_path = project.repository.path_to_repo
expect(File.directory?(old_path)).to be_truthy
expect(subject.execute).to eq(true)
expect(File.directory?(old_path)).to be_falsey
expect(File.directory?("#{full_new_path}.git")).to be_truthy
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