Commit 049d4bae authored by Sean McGivern's avatar Sean McGivern

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
parents 65745f52 73f5b02b
...@@ -1074,21 +1074,21 @@ class Project < ActiveRecord::Base ...@@ -1074,21 +1074,21 @@ class Project < ActiveRecord::Base
merge_requests.where(source_project_id: self.id) merge_requests.where(source_project_id: self.id)
end end
def create_repository def create_repository(force: false)
# Forked import is handled asynchronously # Forked import is handled asynchronously
unless forked? return if forked? && !force
if gitlab_shell.add_repository(repository_storage_path, path_with_namespace)
repository.after_create if gitlab_shell.add_repository(repository_storage_path, path_with_namespace)
true repository.after_create
else true
errors.add(:base, 'Failed to create repository via gitlab-shell') else
false errors.add(:base, 'Failed to create repository via gitlab-shell')
end false
end end
end end
def ensure_repository def ensure_repository
create_repository unless repository_exists? create_repository(force: true) unless repository_exists?
end end
def repository_exists? def repository_exists?
......
---
title: Make Project#ensure_repository force create a repo
merge_request:
author:
...@@ -1346,7 +1346,7 @@ describe Project, models: true do ...@@ -1346,7 +1346,7 @@ describe Project, models: true do
.with(project.repository_storage_path, project.path_with_namespace) .with(project.repository_storage_path, project.path_with_namespace)
.and_return(true) .and_return(true)
expect(project).to receive(:create_repository) expect(project).to receive(:create_repository).with(force: true)
project.ensure_repository project.ensure_repository
end end
...@@ -1359,6 +1359,19 @@ describe Project, models: true do ...@@ -1359,6 +1359,19 @@ describe Project, models: true do
project.ensure_repository project.ensure_repository
end 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 end
describe '#user_can_push_to_empty_repo?' do describe '#user_can_push_to_empty_repo?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment