Add Project#ensure_repository

parent a014b5e4
......@@ -1080,6 +1080,10 @@ class Project < ActiveRecord::Base
end
end
def ensure_repository
create_repository unless repository_exists?
end
def repository_exists?
!!repository.exists?
end
......
......@@ -65,7 +65,7 @@ module Geo
finished_at = nil
begin
project.create_repository unless project.repository_exists?
project.ensure_repository
project.repository.fetch_geo_mirror(ssh_url_to_repo)
finished_at = DateTime.now
......
......@@ -1569,6 +1569,37 @@ describe Project, models: true do
end
end
describe '#ensure_repository' do
let(:project) { create(:project, :repository) }
let(:shell) { Gitlab::Shell.new }
before do
allow(project).to receive(:gitlab_shell).and_return(shell)
end
it 'creates the repository if it not exist' do
allow(project).to receive(:repository_exists?)
.and_return(false)
allow(shell).to receive(:add_repository)
.with(project.repository_storage_path, project.path_with_namespace)
.and_return(true)
expect(project).to receive(:create_repository)
project.ensure_repository
end
it 'does not create the repository if it exists' do
allow(project).to receive(:repository_exists?)
.and_return(true)
expect(project).not_to receive(:create_repository)
project.ensure_repository
end
end
describe 'handling import URL' do
context 'when project is a mirror' do
it 'returns the full URL' 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