2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe 'forked project import' do
|
2018-03-17 18:26:18 +05:30
|
|
|
include ProjectForksHelper
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let!(:project_with_repo) { create(:project, :repository, name: 'test-repo-restorer', path: 'test-repo-restorer') }
|
|
|
|
let!(:project) { create(:project, name: 'test-repo-restorer-no-repo', path: 'test-repo-restorer-no-repo') }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:shared) { project.import_export_shared }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:forked_from_project) { create(:project, :repository) }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:forked_project) { fork_project(project_with_repo, nil, repository: true) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:repo_saver) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) }
|
|
|
|
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
|
|
|
|
|
|
|
|
let(:repo_restorer) do
|
|
|
|
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: bundle_path, shared: shared, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:merge_request) do
|
2018-03-17 18:26:18 +05:30
|
|
|
create(:merge_request, source_project: forked_project, target_project: project_with_repo)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:saver) do
|
|
|
|
Gitlab::ImportExport::ProjectTreeSaver.new(project: project_with_repo, current_user: user, shared: shared)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:restorer) do
|
|
|
|
Gitlab::ImportExport::ProjectTreeRestorer.new(user: user, shared: shared, project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2020-01-01 13:55:28 +05:30
|
|
|
allow_next_instance_of(Gitlab::ImportExport) do |instance|
|
|
|
|
allow(instance).to receive(:storage_path).and_return(export_path)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
saver.save
|
|
|
|
repo_saver.save
|
|
|
|
|
|
|
|
repo_restorer.restore
|
|
|
|
restorer.restore
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm_rf(export_path)
|
2018-11-08 19:23:39 +05:30
|
|
|
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
|
|
|
FileUtils.rm_rf(project_with_repo.repository.path_to_repo)
|
|
|
|
FileUtils.rm_rf(project.repository.path_to_repo)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it 'can access the MR', :sidekiq_might_not_need_inline do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.merge_requests.first.fetch_ref!
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
expect(project.repository.ref_exists?('refs/merge-requests/1/head')).to be_truthy
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|