diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-02 18:06:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-02 18:06:12 +0300 |
commit | 4f4dcd3c5d7a15b7eab5fa28e27482fa68c750a3 (patch) | |
tree | 75e1d73289b774a909461007406eb22b33989265 | |
parent | 2cf5eb1498d6613523b39a829eb00f76df17e781 (diff) |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/shell.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 29 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/repository_service_spec.rb | 22 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 |
8 files changed, 93 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bb3e468170..6eab7f944e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 4ea618f063b..b2c22898079 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -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 diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index c4eb3ad770a..befcc004ee4 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -365,7 +365,7 @@ module Gitlab if Sidekiq.server? 6.hours else - 55.seconds + default_timeout end end diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index ee5cb519a72..d0e5e0db830 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -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) diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb index 7dbed591b84..ec9b2a2022e 100644 --- a/lib/gitlab/shell.rb +++ b/lib/gitlab/shell.rb @@ -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 diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index dcb7401b695..354260f23f6 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -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 diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index a3808adb376..f4b73931f21 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ebfdc1bab44..d6c326764d1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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| |