diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-07-03 22:29:26 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-07-03 22:29:26 +0300 |
commit | 049d4baed0f3532359feb729c5f0938d3d4518ef (patch) | |
tree | 523d6aae47f594a3b658d7c070e66f909e1a53a0 | |
parent | 65745f52833694f9fac956fb7e0c03233e646684 (diff) | |
parent | 73f5b02b4fa275bbd3a5880144114ea69f594307 (diff) |
Merge branch 'sh-allow-force-repo-create' into 'master'
Make Project#ensure_repository force create a repo
Closes gitlab-ee#2800
See merge request !12580
-rw-r--r-- | app/models/project.rb | 20 | ||||
-rw-r--r-- | changelogs/unreleased/sh-allow-force-repo-create.yml | 4 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 15 |
3 files changed, 28 insertions, 11 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index a6708cf48ac..241e7e60dd2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1074,21 +1074,21 @@ 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 def ensure_repository - create_repository unless repository_exists? + create_repository(force: true) unless repository_exists? end def repository_exists? diff --git a/changelogs/unreleased/sh-allow-force-repo-create.yml b/changelogs/unreleased/sh-allow-force-repo-create.yml new file mode 100644 index 00000000000..2a65ba807bb --- /dev/null +++ b/changelogs/unreleased/sh-allow-force-repo-create.yml @@ -0,0 +1,4 @@ +--- +title: Make Project#ensure_repository force create a repo +merge_request: +author: diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 6ff4ec3d417..ad98b4b669f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1346,7 +1346,7 @@ describe Project, models: true do .with(project.repository_storage_path, project.path_with_namespace) .and_return(true) - expect(project).to receive(:create_repository) + expect(project).to receive(:create_repository).with(force: true) project.ensure_repository end @@ -1359,6 +1359,19 @@ describe Project, models: true do project.ensure_repository end + + it 'creates the repository if it is a fork' do + expect(project).to receive(:forked?).and_return(true) + + allow(project).to receive(:repository_exists?) + .and_return(false) + + expect(shell).to receive(:add_repository) + .with(project.repository_storage_path, project.path_with_namespace) + .and_return(true) + + project.ensure_repository + end end describe '#user_can_push_to_empty_repo?' do |