Commit fd0a2b68 authored by Jarka Košanová's avatar Jarka Košanová

Merge branch '25095-remove-gitlab-shell-references' into 'master'

Remove Gitlab::Shell#create_repository

See merge request gitlab-org/gitlab!26924
parents 9b75e1e0 c861a0a0
...@@ -66,7 +66,7 @@ module SubmoduleHelper ...@@ -66,7 +66,7 @@ module SubmoduleHelper
project].join('') project].join('')
url_with_dotgit = url_no_dotgit + '.git' url_with_dotgit = url_no_dotgit + '.git'
url_with_dotgit == Gitlab::Shell.new.url_to_repo([namespace, '/', project].join('')) url_with_dotgit == Gitlab::Shell.url_to_repo([namespace, '/', project].join(''))
end end
def relative_self_url?(url) def relative_self_url?(url)
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
# needs any special behavior. # needs any special behavior.
module HasRepository module HasRepository
extend ActiveSupport::Concern extend ActiveSupport::Concern
include Gitlab::ShellAdapter
include AfterCommitQueue include AfterCommitQueue
include Referable include Referable
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
...@@ -78,7 +77,7 @@ module HasRepository ...@@ -78,7 +77,7 @@ module HasRepository
end end
def url_to_repo def url_to_repo
gitlab_shell.url_to_repo(full_path) Gitlab::Shell.url_to_repo(full_path)
end end
def ssh_url_to_repo def ssh_url_to_repo
......
...@@ -1460,14 +1460,15 @@ class Project < ApplicationRecord ...@@ -1460,14 +1460,15 @@ class Project < ApplicationRecord
# Forked import is handled asynchronously # Forked import is handled asynchronously
return if forked? && !force return if forked? && !force
if gitlab_shell.create_project_repository(self) repository.create_repository
repository.after_create repository.after_create
true true
else rescue => err
errors.add(:base, _('Failed to create repository via gitlab-shell')) Gitlab::ErrorTracking.track_exception(err, project: { id: id, full_path: full_path, disk_path: disk_path })
errors.add(:base, _('Failed to create repository'))
false false
end end
end
def hook_attrs(backward: true) def hook_attrs(backward: true)
attrs = { attrs = {
......
# frozen_string_literal: true # frozen_string_literal: true
class ProjectWiki class ProjectWiki
include Gitlab::ShellAdapter
include Storage::LegacyProjectWiki include Storage::LegacyProjectWiki
include Gitlab::Utils::StrongMemoize
MARKUPS = { MARKUPS = {
'Markdown' => :markdown, 'Markdown' => :markdown,
...@@ -47,7 +47,7 @@ class ProjectWiki ...@@ -47,7 +47,7 @@ class ProjectWiki
end end
def url_to_repo def url_to_repo
gitlab_shell.url_to_repo(full_path) Gitlab::Shell.url_to_repo(full_path)
end end
def ssh_url_to_repo def ssh_url_to_repo
...@@ -64,14 +64,15 @@ class ProjectWiki ...@@ -64,14 +64,15 @@ class ProjectWiki
# Returns the Gitlab::Git::Wiki object. # Returns the Gitlab::Git::Wiki object.
def wiki def wiki
@wiki ||= begin strong_memoize(:wiki) do
gl_repository = Gitlab::GlRepository::WIKI.identifier_for_container(project) repository.create_if_not_exists
raw_repository = Gitlab::Git::Repository.new(project.repository_storage, disk_path + '.git', gl_repository, full_path) raise CouldNotCreateWikiError unless repository_exists?
create_repo!(raw_repository) unless raw_repository.exists? Gitlab::Git::Wiki.new(repository.raw)
Gitlab::Git::Wiki.new(raw_repository)
end end
rescue => err
Gitlab::ErrorTracking.track_exception(err, project_wiki: { project_id: project.id, full_path: full_path, disk_path: disk_path })
raise CouldNotCreateWikiError
end end
def repository_exists? def repository_exists?
...@@ -193,14 +194,6 @@ class ProjectWiki ...@@ -193,14 +194,6 @@ class ProjectWiki
private private
def create_repo!(raw_repository)
gitlab_shell.create_wiki_repository(project)
raise CouldNotCreateWikiError unless raw_repository.exists?
repository.after_create
end
def commit_details(action, message = nil, title = nil) def commit_details(action, message = nil, title = nil)
commit_message = message.presence || default_message(action, title) commit_message = message.presence || default_message(action, title)
git_user = Gitlab::Git::User.from_gitlab(@user) git_user = Gitlab::Git::User.from_gitlab(@user)
......
...@@ -52,11 +52,14 @@ module Projects ...@@ -52,11 +52,14 @@ module Projects
checksum = repository.checksum checksum = repository.checksum
# Initialize a git repository on the target path # Initialize a git repository on the target path
gitlab_shell.create_repository(new_storage_key, raw_repository.relative_path, full_path) new_repository = Gitlab::Git::Repository.new(
new_repository = Gitlab::Git::Repository.new(new_storage_key, new_storage_key,
raw_repository.relative_path, raw_repository.relative_path,
raw_repository.gl_repository, raw_repository.gl_repository,
full_path) full_path
)
new_repository.create_repository
new_repository.replicate(raw_repository) new_repository.replicate(raw_repository)
new_checksum = new_repository.checksum new_checksum = new_repository.checksum
......
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
%p %p
GitLab Shell GitLab Shell
%span.float-right %span.float-right
= Gitlab::Shell.new.version = Gitlab::Shell.version
%p %p
GitLab Workhorse GitLab Workhorse
%span.float-right %span.float-right
......
unless Rails.env.test? unless Rails.env.test?
required_version = Gitlab::VersionInfo.parse(Gitlab::Shell.version_required) required_version = Gitlab::VersionInfo.parse(Gitlab::Shell.version_required)
current_version = Gitlab::VersionInfo.parse(Gitlab::Shell.new.version) current_version = Gitlab::VersionInfo.parse(Gitlab::Shell.version)
unless current_version.valid? && required_version <= current_version unless current_version.valid? && required_version <= current_version
warn "WARNING: This version of GitLab depends on gitlab-shell #{required_version}, but you're running #{current_version}. Please update gitlab-shell." warn "WARNING: This version of GitLab depends on gitlab-shell #{required_version}, but you're running #{current_version}. Please update gitlab-shell."
......
...@@ -72,10 +72,7 @@ module Geo ...@@ -72,10 +72,7 @@ module Geo
log_info("Attempting to fetch repository via git") log_info("Attempting to fetch repository via git")
# `git fetch` needs an empty bare repository to fetch into # `git fetch` needs an empty bare repository to fetch into
unless gitlab_shell.create_repository(project.repository_storage, disk_path_temp, project.full_path) temp_repo.create_repository
raise Gitlab::Shell::Error, 'Can not create a temporary repository'
end
fetch_geo_mirror(temp_repo) fetch_geo_mirror(temp_repo)
set_temp_repository_as_main set_temp_repository_as_main
......
...@@ -4,7 +4,6 @@ require 'yaml' ...@@ -4,7 +4,6 @@ require 'yaml'
module Backup module Backup
class Repository class Repository
include Gitlab::ShellAdapter
attr_reader :progress attr_reader :progress
def initialize(progress) def initialize(progress)
...@@ -71,22 +70,13 @@ module Backup ...@@ -71,22 +70,13 @@ module Backup
def restore def restore
Project.find_each(batch_size: 1000) do |project| Project.find_each(batch_size: 1000) do |project|
progress.print " * #{project.full_path} ... " progress.print " * #{project.full_path} ... "
path_to_project_bundle = path_to_bundle(project)
project.repository.remove rescue nil
restore_repo_success = nil
if File.exist?(path_to_project_bundle) restore_repo_success =
begin begin
project.repository.create_from_bundle(path_to_project_bundle) try_restore_repository(project)
restore_custom_hooks(project) rescue => err
restore_repo_success = true progress.puts "Error: #{err}".color(:red)
rescue => e false
restore_repo_success = false
progress.puts "Error: #{e}".color(:red)
end
else
restore_repo_success = gitlab_shell.create_project_repository(project)
end end
if restore_repo_success if restore_repo_success
...@@ -118,6 +108,20 @@ module Backup ...@@ -118,6 +108,20 @@ module Backup
protected protected
def try_restore_repository(project)
path_to_project_bundle = path_to_bundle(project)
project.repository.remove rescue nil
if File.exist?(path_to_project_bundle)
project.repository.create_from_bundle(path_to_project_bundle)
restore_custom_hooks(project)
else
project.repository.create_repository
end
true
end
def path_to_bundle(project) def path_to_bundle(project)
File.join(backup_repos_path, project.disk_path + '.bundle') File.join(backup_repos_path, project.disk_path + '.bundle')
end end
......
...@@ -6,8 +6,6 @@ require 'securerandom' ...@@ -6,8 +6,6 @@ require 'securerandom'
module Gitlab module Gitlab
class Shell class Shell
GITLAB_SHELL_ENV_VARS = %w(GIT_TERMINAL_PROMPT).freeze
Error = Class.new(StandardError) Error = Class.new(StandardError)
class << self class << self
...@@ -36,8 +34,31 @@ module Gitlab ...@@ -36,8 +34,31 @@ module Gitlab
.join('GITLAB_SHELL_VERSION')).strip .join('GITLAB_SHELL_VERSION')).strip
end end
# Return GitLab shell version
#
# @return [String] version
def version
@version ||= File.read(gitlab_shell_version_file).chomp if File.readable?(gitlab_shell_version_file)
end
# Return a SSH url for a given project path
#
# @param [String] full_path project path (URL)
# @return [String] SSH URL
def url_to_repo(full_path)
Gitlab.config.gitlab_shell.ssh_path_prefix + "#{full_path}.git"
end
private private
def gitlab_shell_path
File.expand_path(Gitlab.config.gitlab_shell.path)
end
def gitlab_shell_version_file
File.join(gitlab_shell_path, 'VERSION')
end
# Create (if necessary) and link the secret token file # Create (if necessary) and link the secret token file
def generate_and_link_secret_token def generate_and_link_secret_token
secret_file = Gitlab.config.gitlab_shell.secret_file secret_file = Gitlab.config.gitlab_shell.secret_file
...@@ -56,47 +77,6 @@ module Gitlab ...@@ -56,47 +77,6 @@ module Gitlab
end end
end end
# Initialize a new project repository using a Project model
#
# @param [Project] project
# @return [Boolean] whether repository could be created
def create_project_repository(project)
create_repository(project.repository_storage, project.disk_path, project.full_path)
end
# Initialize a new wiki repository using a Project model
#
# @param [Project] project
# @return [Boolean] whether repository could be created
def create_wiki_repository(project)
create_repository(project.repository_storage, project.wiki.disk_path, project.wiki.full_path)
end
# Init new repository
#
# @example Create a repository
# create_repository("default", "path/to/gitlab-ci", "gitlab/gitlab-ci")
#
# @param [String] storage the shard key
# @param [String] disk_path project path on disk
# @param [String] gl_project_path project name
# @return [Boolean] whether repository could be created
def create_repository(storage, disk_path, gl_project_path)
relative_path = disk_path.dup
relative_path << '.git' unless relative_path.end_with?('.git')
# During creation of a repository, gl_repository may not be known
# because that depends on a yet-to-be assigned project ID in the
# database (e.g. project-1234), so for now it is blank.
repository = Gitlab::Git::Repository.new(storage, relative_path, '', gl_project_path)
wrapped_gitaly_errors { repository.gitaly_repository_client.create_repository }
true
rescue => err # Once the Rugged codes gets removes this can be improved
Rails.logger.error("Failed to add repository #{storage}/#{disk_path}: #{err}") # rubocop:disable Gitlab/RailsLogger
false
end
# Import wiki repository from external service # Import wiki repository from external service
# #
# @param [Project] project # @param [Project] project
...@@ -238,25 +218,6 @@ module Gitlab ...@@ -238,25 +218,6 @@ module Gitlab
false false
end end
# Return a SSH url for a given project path
#
# @param [String] full_path project path (URL)
# @return [String] SSH URL
def url_to_repo(full_path)
Gitlab.config.gitlab_shell.ssh_path_prefix + "#{full_path}.git"
end
# Return GitLab shell version
#
# @return [String] version
def version
gitlab_shell_version_file = "#{gitlab_shell_path}/VERSION"
if File.readable?(gitlab_shell_version_file)
File.read(gitlab_shell_version_file).chomp
end
end
# Check if repository exists on disk # Check if repository exists on disk
# #
# @example Check if repository exists # @example Check if repository exists
...@@ -271,23 +232,8 @@ module Gitlab ...@@ -271,23 +232,8 @@ module Gitlab
false false
end end
# Return hooks folder path used by projects
#
# @return [String] path
def hooks_path
File.join(gitlab_shell_path, 'hooks')
end
protected protected
def gitlab_shell_path
File.expand_path(Gitlab.config.gitlab_shell.path)
end
def gitlab_shell_user_home
File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
end
def full_path(storage, dir_name) def full_path(storage, dir_name)
raise ArgumentError.new("Directory name can't be blank") if dir_name.blank? raise ArgumentError.new("Directory name can't be blank") if dir_name.blank?
......
...@@ -50,7 +50,7 @@ module SystemCheck ...@@ -50,7 +50,7 @@ module SystemCheck
end end
def gitlab_shell_version def gitlab_shell_version
Gitlab::Shell.new.version Gitlab::Shell.version
end end
end end
end end
...@@ -82,15 +82,10 @@ namespace :gitlab do ...@@ -82,15 +82,10 @@ namespace :gitlab do
puts "Using Omniauth:\t#{Gitlab::Auth.omniauth_enabled? ? "yes".color(:green) : "no"}" puts "Using Omniauth:\t#{Gitlab::Auth.omniauth_enabled? ? "yes".color(:green) : "no"}"
puts "Omniauth Providers: #{omniauth_providers.join(', ')}" if Gitlab::Auth.omniauth_enabled? puts "Omniauth Providers: #{omniauth_providers.join(', ')}" if Gitlab::Auth.omniauth_enabled?
# check Gitolite version # check Gitlab Shell version
gitlab_shell_version_file = "#{Gitlab.config.gitlab_shell.path}/VERSION"
if File.readable?(gitlab_shell_version_file)
gitlab_shell_version = File.read(gitlab_shell_version_file)
end
puts "" puts ""
puts "GitLab Shell".color(:yellow) puts "GitLab Shell".color(:yellow)
puts "Version:\t#{gitlab_shell_version || "unknown".color(:red)}" puts "Version:\t#{Gitlab::Shell.version || "unknown".color(:red)}"
puts "Repository storage paths:" puts "Repository storage paths:"
Gitlab::GitalyClient::StorageSettings.allow_disk_access do Gitlab::GitalyClient::StorageSettings.allow_disk_access do
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
......
...@@ -8383,7 +8383,7 @@ msgstr "" ...@@ -8383,7 +8383,7 @@ msgstr ""
msgid "Failed to create a branch for this issue. Please try again." msgid "Failed to create a branch for this issue. Please try again."
msgstr "" msgstr ""
msgid "Failed to create repository via gitlab-shell" msgid "Failed to create repository"
msgstr "" msgstr ""
msgid "Failed to create resources" msgid "Failed to create resources"
......
...@@ -50,9 +50,9 @@ describe Backup::Repository do ...@@ -50,9 +50,9 @@ describe Backup::Repository do
describe 'command failure' do describe 'command failure' do
before do before do
allow_next_instance_of(Gitlab::Shell) do |instance| # Allow us to set expectations on the project directly
allow(instance).to receive(:create_repository).and_return(false) expect(Project).to receive(:find_each).and_yield(project)
end expect(project.repository).to receive(:create_repository) { raise 'Fail in tests' }
end end
context 'hashed storage' do context 'hashed storage' do
......
...@@ -7,18 +7,17 @@ describe Gitlab::Shell do ...@@ -7,18 +7,17 @@ describe Gitlab::Shell do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let(:repository) { project.repository } let(:repository) { project.repository }
let(:gitlab_shell) { described_class.new } let(:gitlab_shell) { described_class.new }
let(:popen_vars) { { 'GIT_TERMINAL_PROMPT' => ENV['GIT_TERMINAL_PROMPT'] } }
let(:timeout) { Gitlab.config.gitlab_shell.git_timeout }
before do
allow(Project).to receive(:find).and_return(project)
end
it { is_expected.to respond_to :create_repository }
it { is_expected.to respond_to :remove_repository } it { is_expected.to respond_to :remove_repository }
it { is_expected.to respond_to :fork_repository } it { is_expected.to respond_to :fork_repository }
it { expect(gitlab_shell.url_to_repo('diaspora')).to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + "diaspora.git") } describe '.url_to_repo' do
let(:full_path) { 'diaspora/disaspora-rails' }
subject { described_class.url_to_repo(full_path) }
it { is_expected.to eq(Gitlab.config.gitlab_shell.ssh_path_prefix + full_path + '.git') }
end
describe 'memoized secret_token' do describe 'memoized secret_token' do
let(:secret_file) { 'tmp/tests/.secret_shell_test' } let(:secret_file) { 'tmp/tests/.secret_shell_test' }
...@@ -49,37 +48,12 @@ describe Gitlab::Shell do ...@@ -49,37 +48,12 @@ describe Gitlab::Shell do
describe 'projects commands' do describe 'projects commands' do
let(:gitlab_shell_path) { File.expand_path('tmp/tests/gitlab-shell') } let(:gitlab_shell_path) { File.expand_path('tmp/tests/gitlab-shell') }
let(:projects_path) { File.join(gitlab_shell_path, 'bin/gitlab-projects') } let(:projects_path) { File.join(gitlab_shell_path, 'bin/gitlab-projects') }
let(:gitlab_shell_hooks_path) { File.join(gitlab_shell_path, 'hooks') }
before do before do
allow(Gitlab.config.gitlab_shell).to receive(:path).and_return(gitlab_shell_path) allow(Gitlab.config.gitlab_shell).to receive(:path).and_return(gitlab_shell_path)
allow(Gitlab.config.gitlab_shell).to receive(:git_timeout).and_return(800) allow(Gitlab.config.gitlab_shell).to receive(:git_timeout).and_return(800)
end end
describe '#create_repository' do
let(:repository_storage) { 'default' }
let(:repository_storage_path) do
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
Gitlab.config.repositories.storages[repository_storage].legacy_disk_path
end
end
let(:repo_name) { 'project/path' }
let(:created_path) { File.join(repository_storage_path, repo_name + '.git') }
after do
FileUtils.rm_rf(created_path)
end
it 'returns false when the command fails' do
FileUtils.mkdir_p(File.dirname(created_path))
# This file will block the creation of the repo's .git directory. That
# should cause #create_repository to fail.
FileUtils.touch(created_path)
expect(gitlab_shell.create_repository(repository_storage, repo_name, repo_name)).to be_falsy
end
end
describe '#remove_repository' do describe '#remove_repository' do
let!(:project) { create(:project, :repository, :legacy_storage) } let!(:project) { create(:project, :repository, :legacy_storage) }
let(:disk_path) { "#{project.disk_path}.git" } let(:disk_path) { "#{project.disk_path}.git" }
......
...@@ -1921,30 +1921,15 @@ describe Project do ...@@ -1921,30 +1921,15 @@ describe Project do
describe '#create_repository' do describe '#create_repository' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:shell) { Gitlab::Shell.new }
before do
allow(project).to receive(:gitlab_shell).and_return(shell)
end
context 'using a regular repository' do context 'using a regular repository' do
it 'creates the repository' do it 'creates the repository' do
expect(shell).to receive(:create_repository) expect(project.repository).to receive(:create_repository)
.with(project.repository_storage, project.disk_path, project.full_path)
.and_return(true)
expect(project.repository).to receive(:after_create)
expect(project.create_repository).to eq(true) expect(project.create_repository).to eq(true)
end end
it 'adds an error if the repository could not be created' do it 'adds an error if the repository could not be created' do
expect(shell).to receive(:create_repository) expect(project.repository).to receive(:create_repository) { raise 'Fail in test' }
.with(project.repository_storage, project.disk_path, project.full_path)
.and_return(false)
expect(project.repository).not_to receive(:after_create)
expect(project.create_repository).to eq(false) expect(project.create_repository).to eq(false)
expect(project.errors).not_to be_empty expect(project.errors).not_to be_empty
end end
...@@ -1953,7 +1938,7 @@ describe Project do ...@@ -1953,7 +1938,7 @@ describe Project do
context 'using a forked repository' do context 'using a forked repository' do
it 'does nothing' do it 'does nothing' do
expect(project).to receive(:forked?).and_return(true) expect(project).to receive(:forked?).and_return(true)
expect(shell).not_to receive(:create_repository) expect(project.repository).not_to receive(:create_repository)
project.create_repository project.create_repository
end end
...@@ -1962,28 +1947,16 @@ describe Project do ...@@ -1962,28 +1947,16 @@ describe Project do
describe '#ensure_repository' do describe '#ensure_repository' do
let(:project) { create(:project, :repository) } 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 it 'creates the repository if it not exist' do
allow(project).to receive(:repository_exists?) allow(project).to receive(:repository_exists?).and_return(false)
.and_return(false)
allow(shell).to receive(:create_repository)
.with(project.repository_storage, project.disk_path, project.full_path)
.and_return(true)
expect(project).to receive(:create_repository).with(force: true) expect(project).to receive(:create_repository).with(force: true)
project.ensure_repository project.ensure_repository
end end
it 'does not create the repository if it exists' do it 'does not create the repository if it exists' do
allow(project).to receive(:repository_exists?) allow(project).to receive(:repository_exists?).and_return(true)
.and_return(true)
expect(project).not_to receive(:create_repository) expect(project).not_to receive(:create_repository)
...@@ -1992,13 +1965,8 @@ describe Project do ...@@ -1992,13 +1965,8 @@ describe Project do
it 'creates the repository if it is a fork' do it 'creates the repository if it is a fork' do
expect(project).to receive(:forked?).and_return(true) expect(project).to receive(:forked?).and_return(true)
expect(project).to receive(:repository_exists?).and_return(false)
allow(project).to receive(:repository_exists?) expect(project.repository).to receive(:create_repository) { true }
.and_return(false)
expect(shell).to receive(:create_repository)
.with(project.repository_storage, project.disk_path, project.full_path)
.and_return(true)
project.ensure_repository project.ensure_repository
end end
......
...@@ -34,7 +34,7 @@ describe ProjectWiki do ...@@ -34,7 +34,7 @@ describe ProjectWiki do
describe "#url_to_repo" do describe "#url_to_repo" do
it "returns the correct ssh url to the repo" do it "returns the correct ssh url to the repo" do
expect(subject.url_to_repo).to eq(gitlab_shell.url_to_repo(subject.full_path)) expect(subject.url_to_repo).to eq(Gitlab::Shell.url_to_repo(subject.full_path))
end end
end end
...@@ -97,9 +97,7 @@ describe ProjectWiki do ...@@ -97,9 +97,7 @@ describe ProjectWiki do
it "raises CouldNotCreateWikiError if it can't create the wiki repository" do it "raises CouldNotCreateWikiError if it can't create the wiki repository" do
# Create a fresh project which will not have a wiki # Create a fresh project which will not have a wiki
project_wiki = described_class.new(create(:project), user) project_wiki = described_class.new(create(:project), user)
gitlab_shell = double(:gitlab_shell) expect(project_wiki.repository).to receive(:create_if_not_exists) { false }
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) expect { project_wiki.send(:wiki) }.to raise_exception(ProjectWiki::CouldNotCreateWikiError)
end end
...@@ -416,26 +414,12 @@ describe ProjectWiki do ...@@ -416,26 +414,12 @@ describe ProjectWiki do
end end
end end
describe '#create_repo!' do
let(:project) { create(:project) }
it 'creates a repository' do
expect(raw_repository.exists?).to eq(false)
expect(subject.repository).to receive(:after_create)
subject.send(:create_repo!, raw_repository)
expect(raw_repository.exists?).to eq(true)
end
end
describe '#ensure_repository' do describe '#ensure_repository' do
let(:project) { create(:project) } let(:project) { create(:project) }
it 'creates the repository if it not exist' do it 'creates the repository if it not exist' do
expect(raw_repository.exists?).to eq(false) expect(raw_repository.exists?).to eq(false)
expect(subject).to receive(:create_repo!).and_call_original
subject.ensure_repository subject.ensure_repository
expect(raw_repository.exists?).to eq(true) expect(raw_repository.exists?).to eq(true)
......
...@@ -312,6 +312,8 @@ describe Projects::ForkService do ...@@ -312,6 +312,8 @@ describe Projects::ForkService do
# Stub everything required to move a project to a Gitaly shard that does not exist # Stub everything required to move a project to a Gitaly shard that does not exist
stub_storage_settings('test_second_storage' => { 'path' => TestEnv::SECOND_STORAGE_PATH }) stub_storage_settings('test_second_storage' => { 'path' => TestEnv::SECOND_STORAGE_PATH })
allow_any_instance_of(Gitlab::Git::Repository).to receive(:create_repository)
.and_return(true)
allow_any_instance_of(Gitlab::Git::Repository).to receive(:replicate) allow_any_instance_of(Gitlab::Git::Repository).to receive(:replicate)
allow_any_instance_of(Gitlab::Git::Repository).to receive(:checksum) allow_any_instance_of(Gitlab::Git::Repository).to receive(:checksum)
.and_return(::Gitlab::Git::BLANK_SHA) .and_return(::Gitlab::Git::BLANK_SHA)
......
...@@ -32,6 +32,8 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -32,6 +32,8 @@ describe Projects::UpdateRepositoryStorageService do
project.repository.path_to_repo project.repository.path_to_repo
end end
expect(project_repository_double).to receive(:create_repository)
.and_return(true)
expect(project_repository_double).to receive(:replicate) expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw) .with(project.repository.raw)
expect(project_repository_double).to receive(:checksum) expect(project_repository_double).to receive(:checksum)
...@@ -58,6 +60,8 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -58,6 +60,8 @@ describe Projects::UpdateRepositoryStorageService do
context 'when the move fails' do context 'when the move fails' do
it 'unmarks the repository as read-only without updating the repository storage' do it 'unmarks the repository as read-only without updating the repository storage' do
expect(project_repository_double).to receive(:create_repository)
.and_return(true)
expect(project_repository_double).to receive(:replicate) expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw) .with(project.repository.raw)
.and_raise(Gitlab::Git::CommandError) .and_raise(Gitlab::Git::CommandError)
...@@ -73,6 +77,8 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -73,6 +77,8 @@ describe Projects::UpdateRepositoryStorageService do
context 'when the checksum does not match' do context 'when the checksum does not match' do
it 'unmarks the repository as read-only without updating the repository storage' do it 'unmarks the repository as read-only without updating the repository storage' do
expect(project_repository_double).to receive(:create_repository)
.and_return(true)
expect(project_repository_double).to receive(:replicate) expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw) .with(project.repository.raw)
expect(project_repository_double).to receive(:checksum) expect(project_repository_double).to receive(:checksum)
...@@ -91,6 +97,8 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -91,6 +97,8 @@ describe Projects::UpdateRepositoryStorageService do
let!(:pool) { create(:pool_repository, :ready, source_project: project) } let!(:pool) { create(:pool_repository, :ready, source_project: project) }
it 'leaves the pool' do it 'leaves the pool' do
expect(project_repository_double).to receive(:create_repository)
.and_return(true)
expect(project_repository_double).to receive(:replicate) expect(project_repository_double).to receive(:replicate)
.with(project.repository.raw) .with(project.repository.raw)
expect(project_repository_double).to receive(:checksum) expect(project_repository_double).to receive(:checksum)
......
...@@ -22,11 +22,15 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| ...@@ -22,11 +22,15 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
context 'when the move succeeds', :clean_gitlab_redis_shared_state do context 'when the move succeeds', :clean_gitlab_redis_shared_state do
before do before do
allow(project_repository_double).to receive(:create_repository)
.and_return(true)
allow(project_repository_double).to receive(:replicate) allow(project_repository_double).to receive(:replicate)
.with(project.repository.raw) .with(project.repository.raw)
allow(project_repository_double).to receive(:checksum) allow(project_repository_double).to receive(:checksum)
.and_return(project_repository_checksum) .and_return(project_repository_checksum)
allow(repository_double).to receive(:create_repository)
.and_return(true)
allow(repository_double).to receive(:replicate) allow(repository_double).to receive(:replicate)
.with(repository.raw) .with(repository.raw)
allow(repository_double).to receive(:checksum) allow(repository_double).to receive(:checksum)
...@@ -90,11 +94,15 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| ...@@ -90,11 +94,15 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
context "when the move of the #{repository_type} repository fails" do context "when the move of the #{repository_type} repository fails" do
it 'unmarks the repository as read-only without updating the repository storage' do it 'unmarks the repository as read-only without updating the repository storage' do
allow(project_repository_double).to receive(:create_repository)
.and_return(true)
allow(project_repository_double).to receive(:replicate) allow(project_repository_double).to receive(:replicate)
.with(project.repository.raw) .with(project.repository.raw)
allow(project_repository_double).to receive(:checksum) allow(project_repository_double).to receive(:checksum)
.and_return(project_repository_checksum) .and_return(project_repository_checksum)
allow(repository_double).to receive(:create_repository)
.and_return(true)
allow(repository_double).to receive(:replicate) allow(repository_double).to receive(:replicate)
.with(repository.raw) .with(repository.raw)
.and_raise(Gitlab::Git::CommandError) .and_raise(Gitlab::Git::CommandError)
...@@ -111,11 +119,15 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| ...@@ -111,11 +119,15 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
context "when the checksum of the #{repository_type} repository does not match" do context "when the checksum of the #{repository_type} repository does not match" do
it 'unmarks the repository as read-only without updating the repository storage' do it 'unmarks the repository as read-only without updating the repository storage' do
allow(project_repository_double).to receive(:create_repository)
.and_return(true)
allow(project_repository_double).to receive(:replicate) allow(project_repository_double).to receive(:replicate)
.with(project.repository.raw) .with(project.repository.raw)
allow(project_repository_double).to receive(:checksum) allow(project_repository_double).to receive(:checksum)
.and_return(project_repository_checksum) .and_return(project_repository_checksum)
allow(repository_double).to receive(:create_repository)
.and_return(true)
allow(repository_double).to receive(:replicate) allow(repository_double).to receive(:replicate)
.with(repository.raw) .with(repository.raw)
allow(repository_double).to receive(:checksum) allow(repository_double).to receive(:checksum)
......
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