Commit 65c40449 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'port-changes-ee-2467' into 'master'

Port of "2467-repository-sync-dirty-projects" to CE

See merge request !12523
parents 5870fc5d 26f37310
...@@ -1094,6 +1094,10 @@ class Project < ActiveRecord::Base ...@@ -1094,6 +1094,10 @@ class Project < ActiveRecord::Base
end end
end end
def ensure_repository
create_repository unless repository_exists?
end
def repository_exists? def repository_exists?
!!repository.exists? !!repository.exists?
end end
......
...@@ -149,6 +149,10 @@ class ProjectWiki ...@@ -149,6 +149,10 @@ class ProjectWiki
wiki wiki
end end
def ensure_repository
create_repo! unless repository_exists?
end
def hook_attrs def hook_attrs
{ {
web_url: web_url, web_url: web_url,
......
...@@ -1327,6 +1327,37 @@ describe Project, models: true do ...@@ -1327,6 +1327,37 @@ describe Project, models: true do
end end
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 '#user_can_push_to_empty_repo?' do describe '#user_can_push_to_empty_repo?' do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:user) { create(:user) } let(:user) { create(:user) }
......
...@@ -278,6 +278,24 @@ describe ProjectWiki, models: true do ...@@ -278,6 +278,24 @@ describe ProjectWiki, models: true do
end end
end end
describe '#ensure_repository' do
it 'creates the repository if it not exist' do
allow(subject).to receive(:repository_exists?).and_return(false)
expect(subject).to receive(:create_repo!)
subject.ensure_repository
end
it 'does not create the repository if it exists' do
allow(subject).to receive(:repository_exists?).and_return(true)
expect(subject).not_to receive(:create_repo!)
subject.ensure_repository
end
end
describe '#hook_attrs' do describe '#hook_attrs' do
it 'returns a hash with values' do it 'returns a hash with values' do
expect(subject.hook_attrs).to be_a Hash expect(subject.hook_attrs).to be_a Hash
......
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