summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-06-28 16:01:34 +0000
committerDouwe Maan <douwe@gitlab.com>2017-06-28 16:01:34 +0000
commit65c40449401a4f70f25d154f52c21517bdcdc1ce (patch)
tree59644aed06ea561b0c8723e2df4eff487b8c7bda
parent5870fc5daf0b96c26479ee6f7601bc6e8a243c24 (diff)
parent26f3731021e8c5c6417fe874c53a5bf2065b8888 (diff)
downloadgitlab-ce-65c40449401a4f70f25d154f52c21517bdcdc1ce.tar.gz
Merge branch 'port-changes-ee-2467' into 'master'
Port of "2467-repository-sync-dirty-projects" to CE See merge request !12523
-rw-r--r--app/models/project.rb4
-rw-r--r--app/models/project_wiki.rb4
-rw-r--r--spec/models/project_spec.rb31
-rw-r--r--spec/models/project_wiki_spec.rb18
4 files changed, 57 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 1176bec8873..35d8f9a0154 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1094,6 +1094,10 @@ class Project < ActiveRecord::Base
end
end
+ def ensure_repository
+ create_repository unless repository_exists?
+ end
+
def repository_exists?
!!repository.exists?
end
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index f38fbda7839..f26ee57510c 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -149,6 +149,10 @@ class ProjectWiki
wiki
end
+ def ensure_repository
+ create_repo! unless repository_exists?
+ end
+
def hook_attrs
{
web_url: web_url,
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index d7fcadb895e..cc22b8a4edc 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1327,6 +1327,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 '#user_can_push_to_empty_repo?' do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb
index bf74ac5ea25..1f314791479 100644
--- a/spec/models/project_wiki_spec.rb
+++ b/spec/models/project_wiki_spec.rb
@@ -278,6 +278,24 @@ describe ProjectWiki, models: true do
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
it 'returns a hash with values' do
expect(subject.hook_attrs).to be_a Hash