diff options
-rw-r--r-- | app/models/project.rb | 18 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 17 |
2 files changed, 24 insertions, 11 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index cf6515b9fa3..41c10dbf89c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1074,16 +1074,16 @@ class Project < ActiveRecord::Base merge_requests.where(source_project_id: self.id) end - def create_repository + def create_repository(force: false) # Forked import is handled asynchronously - unless forked? - if gitlab_shell.add_repository(repository_storage_path, path_with_namespace) - repository.after_create - true - else - errors.add(:base, 'Failed to create repository via gitlab-shell') - false - end + return if forked? && !force + + if gitlab_shell.add_repository(repository_storage_path, path_with_namespace) + repository.after_create + true + else + errors.add(:base, 'Failed to create repository via gitlab-shell') + false end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index d97866d695d..aa3d7478234 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1312,12 +1312,25 @@ describe Project, models: true do end context 'using a forked repository' do - it 'does nothing' do - expect(project).to receive(:forked?).and_return(true) + before do + allow(project).to receive(:forked?).and_return(true) + end + + it 'does not create the repository if the force flag is false' do expect(shell).not_to receive(:add_repository) project.create_repository end + + it 'creates the repository if the force flag is true' do + expect(shell).to receive(:add_repository). + with(project.repository_storage_path, project.path_with_namespace). + and_return(true) + + expect(project.repository).to receive(:after_create) + + expect(project.create_repository(force: true)).to eq(true) + end end end |