summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-06-30 15:31:35 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-07-03 12:49:08 -0300
commitcd8edeedede144aca633c4a283fe0a3e43d76ea8 (patch)
treea9f38b4d04b3a6650b1b8a51642436b358a3e682
parent92cd381c0c3729f4e011545597c82a197b9caf1c (diff)
downloadgitlab-ce-9-3-allow-force-repo-create.tar.gz
Add an option to force Project#create_repository create a repository9-3-allow-force-repo-create
-rw-r--r--app/models/project.rb18
-rw-r--r--spec/models/project_spec.rb17
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