From a384167ae66b53e2041a4af311ffb7bb5eb91401 Mon Sep 17 00:00:00 2001 From: ghinfey Date: Tue, 29 Nov 2022 12:35:29 +0000 Subject: [PATCH] Delete repo immediately The wiki is scheduled for delection using container.run_after_commit. No commit is made to the project during restoration. Add repository.project.touch to delete the repo immediately. Changelog: changed MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/105348 --- lib/gitlab/import_export/repo_restorer.rb | 5 +++++ .../import_export/repo_restorer_spec.rb | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/gitlab/import_export/repo_restorer.rb b/lib/gitlab/import_export/repo_restorer.rb index 1c6629cf9428fc..cc214d730febe4 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 727ca4f630b5ea..3da7af7509ef65 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 -- GitLab