Commit e7895851 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'kborges/remove-reposity-folder-when-import-fail' into 'master'

Ensure to remove reposity folder when import fails

See merge request gitlab-org/gitlab!33461
parents 6344740e 03356540
...@@ -16,6 +16,8 @@ module Gitlab ...@@ -16,6 +16,8 @@ module Gitlab
repository.create_from_bundle(path_to_bundle) repository.create_from_bundle(path_to_bundle)
rescue => e rescue => e
Repositories::DestroyService.new(repository).execute
shared.error(e) shared.error(e)
false false
end end
......
...@@ -13,11 +13,8 @@ describe Gitlab::ImportExport::RepoRestorer do ...@@ -13,11 +13,8 @@ describe Gitlab::ImportExport::RepoRestorer do
let(:shared) { project.import_export_shared } let(:shared) { project.import_export_shared }
let(:bundler) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) } let(:bundler) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) }
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
let(:restorer) do
described_class.new(path_to_bundle: bundle_path, subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: project) }
shared: shared,
project: project)
end
before do before do
allow_next_instance_of(Gitlab::ImportExport) do |instance| allow_next_instance_of(Gitlab::ImportExport) do |instance|
...@@ -36,7 +33,25 @@ describe Gitlab::ImportExport::RepoRestorer do ...@@ -36,7 +33,25 @@ describe Gitlab::ImportExport::RepoRestorer do
end end
it 'restores the repo successfully' do it 'restores the repo successfully' do
expect(restorer.restore).to be_truthy expect(subject.restore).to be_truthy
end
context 'when the repository creation fails' do
before do
allow_next_instance_of(Repositories::DestroyService) do |instance|
expect(instance).to receive(:execute).and_call_original
end
end
it 'logs the error' do
allow(project.repository)
.to receive(:create_from_bundle)
.and_raise('9:CreateRepositoryFromBundle: target directory is non-empty')
expect(shared).to receive(:error).and_call_original
expect(subject.restore).to be_falsey
end
end 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