Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2019-10-02 15:06:12 +00:00
parent 2cf5eb1498
commit 4f4dcd3c5d
8 changed files with 93 additions and 8 deletions

View File

@ -2,10 +2,6 @@
documentation](doc/development/changelog.md) for instructions on adding your own
entry.
## 12.3.4
- No changes.
## 12.3.2
### Security (12 changes)

View File

@ -131,6 +131,18 @@ module Gitlab
end
end
def rename(new_relative_path)
wrapped_gitaly_errors do
gitaly_repository_client.rename(new_relative_path)
end
end
def remove
wrapped_gitaly_errors do
gitaly_repository_client.remove
end
end
def expire_has_local_branches_cache
clear_memoization(:has_local_branches)
end

View File

@ -365,7 +365,7 @@ module Gitlab
if Sidekiq.server?
6.hours
else
55.seconds
default_timeout
end
end

View File

@ -347,6 +347,18 @@ module Gitlab
GitalyClient.call(@storage, :object_pool_service, :disconnect_git_alternates, request, timeout: GitalyClient.long_timeout)
end
def rename(relative_path)
request = Gitaly::RenameRepositoryRequest.new(repository: @gitaly_repo, relative_path: relative_path)
GitalyClient.call(@storage, :repository_service, :rename_repository, request, timeout: GitalyClient.fast_timeout)
end
def remove
request = Gitaly::RemoveRepositoryRequest.new(repository: @gitaly_repo)
GitalyClient.call(@storage, :repository_service, :remove_repository, request, timeout: GitalyClient.long_timeout)
end
private
def search_results_from_response(gitaly_response)

View File

@ -126,7 +126,13 @@ module Gitlab
def mv_repository(storage, path, new_path)
return false if path.empty? || new_path.empty?
!!mv_directory(storage, "#{path}.git", "#{new_path}.git")
Gitlab::Git::Repository.new(storage, "#{path}.git", nil, nil).rename("#{new_path}.git")
true
rescue => e
Gitlab::Sentry.track_acceptable_exception(e, extra: { path: path, new_path: new_path, storage: storage })
false
end
# Fork repository to new path
@ -151,9 +157,13 @@ module Gitlab
def remove_repository(storage, name)
return false if name.empty?
!!rm_directory(storage, "#{name}.git")
rescue ArgumentError => e
Gitlab::Git::Repository.new(storage, "#{name}.git", nil, nil).remove
true
rescue => e
Rails.logger.warn("Repository does not exist: #{e} at: #{name}.git") # rubocop:disable Gitlab/RailsLogger
Gitlab::Sentry.track_acceptable_exception(e, extra: { path: name, storage: storage })
false
end

View File

@ -2236,4 +2236,33 @@ describe Gitlab::Git::Repository, :seed_helper do
expect(repository.commit(new_commit.oid).id).to eq(new_commit.oid)
end
end
describe '#rename' do
let(:project) { create(:project, :repository)}
let(:repository) { project.repository }
it 'moves the repository' do
checksum = repository.checksum
new_relative_path = "rename_test/relative/path"
renamed_repository = Gitlab::Git::Repository.new(repository.storage, new_relative_path, nil, nil)
repository.rename(new_relative_path)
expect(renamed_repository.checksum).to eq(checksum)
expect(repository.exists?).to be false
end
end
describe '#remove' do
let(:project) { create(:project, :repository)}
let(:repository) { project.repository }
it 'removes the repository' do
expect(repository.exists?).to be true
repository.remove
expect(repository.raw_repository.exists?).to be false
end
end
end

View File

@ -272,4 +272,26 @@ describe Gitlab::GitalyClient::RepositoryService do
end
end
end
describe 'remove' do
it 'sends a remove_repository message' do
expect_any_instance_of(Gitaly::RepositoryService::Stub)
.to receive(:remove_repository)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return(double(value: true))
client.remove
end
end
describe 'rename' do
it 'sends a rename_repository message' do
expect_any_instance_of(Gitaly::RepositoryService::Stub)
.to receive(:rename_repository)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return(double(value: true))
client.rename('some/new/path')
end
end
end

View File

@ -350,6 +350,10 @@ FactoryBot::SyntaxRunner.class_eval do
include RSpec::Mocks::ExampleMethods
end
# Use FactoryBot 4.x behavior:
# https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#associations
FactoryBot.use_parent_strategy = false
ActiveRecord::Migration.maintain_test_schema!
Shoulda::Matchers.configure do |config|