From b103f61450a0553a4a266bd394ae6d6f3c4d10b1 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 17 Jan 2019 13:50:18 -0800 Subject: [PATCH] Add convenience methods for creating project and Wiki repositories This makes it easier to access other project arguments in the future. --- app/models/project.rb | 2 +- app/models/project_wiki.rb | 2 +- lib/backup/repository.rb | 2 +- lib/gitlab/shell.rb | 8 ++++++++ spec/models/project_wiki_spec.rb | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index e5edaa5eaac..8f746f6e094 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1288,7 +1288,7 @@ class Project < ActiveRecord::Base # Forked import is handled asynchronously return if forked? && !force - if gitlab_shell.create_repository(repository_storage, disk_path, full_path) + if gitlab_shell.create_project_repository(self) repository.after_create true else diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb index e29db623afd..c43bd45a62f 100644 --- a/app/models/project_wiki.rb +++ b/app/models/project_wiki.rb @@ -175,7 +175,7 @@ class ProjectWiki private def create_repo!(raw_repository) - gitlab_shell.create_repository(project.repository_storage, disk_path, project.full_path) + gitlab_shell.create_wiki_repository(project) raise CouldNotCreateWikiError unless raw_repository.exists? diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb index 89dc8014199..22ed1d8e7b4 100644 --- a/lib/backup/repository.rb +++ b/lib/backup/repository.rb @@ -93,7 +93,7 @@ module Backup progress.puts "Error: #{e}".color(:red) end else - restore_repo_success = gitlab_shell.create_repository(project.repository_storage, project.disk_path, project.full_path) + restore_repo_success = gitlab_shell.create_project_repository(project) end if restore_repo_success diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index c8d891500d7..9f2de59684c 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -64,6 +64,14 @@ module Gitlab end end + def create_project_repository(project) + create_repository(project.repository_storage, project.disk_path, project.full_path) + end + + def create_wiki_repository(project) + create_repository(project.repository_storage, project.wiki.disk_path, project.wiki.full_path) + end + # Init new repository # # storage - the shard key diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index be754fece75..3ccc706edf2 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -75,7 +75,7 @@ describe ProjectWiki do # Create a fresh project which will not have a wiki project_wiki = described_class.new(create(:project), user) gitlab_shell = double(:gitlab_shell) - allow(gitlab_shell).to receive(:create_repository) + allow(gitlab_shell).to receive(:create_wiki_repository) allow(project_wiki).to receive(:gitlab_shell).and_return(gitlab_shell) expect { project_wiki.send(:wiki) }.to raise_exception(ProjectWiki::CouldNotCreateWikiError)