diff --git a/lib/gitlab/import_export/repo_restorer.rb b/lib/gitlab/import_export/repo_restorer.rb index 1c6629cf9428fc8949308885e01f60c98b0f4efe..cc214d730febe4fe5c1cda6d0101c7b87852b26c 100644 --- a/lib/gitlab/import_export/repo_restorer.rb +++ b/lib/gitlab/import_export/repo_restorer.rb @@ -46,6 +46,11 @@ def ensure_repository_does_not_exist! ) Repositories::DestroyService.new(repository).execute + + # Because Gitlab::Git::Repository#remove happens inside a run_after_commit + # callback in the Repositories::DestroyService#execute we need to trigger + # the callback. + repository.project.touch end end end diff --git a/spec/lib/gitlab/import_export/repo_restorer_spec.rb b/spec/lib/gitlab/import_export/repo_restorer_spec.rb index 727ca4f630b5ea7bae55738f4fc9bd327821a5c8..3da7af7509ef65dedd6da846090c4ecdb28c27f8 100644 --- a/spec/lib/gitlab/import_export/repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/repo_restorer_spec.rb @@ -34,7 +34,7 @@ Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path) end - it 'restores the repo successfully' do + it 'restores the repo successfully', :aggregate_failures do expect(project.repository.exists?).to be false expect(subject.restore).to be_truthy @@ -42,7 +42,7 @@ end context 'when the repository already exists' do - it 'deletes the existing repository before importing' do + it 'deletes the existing repository before importing', :aggregate_failures do allow(project.repository).to receive(:exists?).and_return(true) allow(project.repository).to receive(:disk_path).and_return('repository_path') @@ -69,7 +69,7 @@ Gitlab::Shell.new.remove_repository(project.wiki.repository_storage, project.wiki.disk_path) end - it 'restores the wiki repo successfully' do + it 'restores the wiki repo successfully', :aggregate_failures do expect(project.wiki_repository_exists?).to be false subject.restore @@ -83,10 +83,21 @@ let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(exportable: project_without_wiki, shared: shared) } - it 'does not creates an empty wiki' do + it 'does not creates an empty wiki', :aggregate_failures do expect(subject.restore).to be true expect(project.wiki_repository_exists?).to be false end end + + context 'when wiki already exists' do + subject do + described_class.new(path_to_bundle: bundle_path, shared: shared, importable: ProjectWiki.new(project_with_repo)) + end + + it 'does not cause an error when restoring', :aggregate_failures do + expect(subject.restore).to be true + expect(shared.errors).to be_empty + end + end end end