Make Project#ensure_repository force create a repo
In Geo, Project#ensure_repository is used to make sure that a Git repo is available to be fetched on a secondary. If a project were a fork, this directory would never be created. Closes gitlab-org/gitlab-ee#2800
This commit is contained in:
parent
5a983ac431
commit
9c8075c4b9
|
@ -1073,21 +1073,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(true) unless repository_exists?
|
||||
end
|
||||
|
||||
def repository_exists?
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Make Project#ensure_repository force create a repo
|
||||
merge_request:
|
||||
author:
|
|
@ -1357,6 +1357,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
|
||||
|
|
Loading…
Reference in New Issue