diff options
author | Stan Hu <stanhu@gmail.com> | 2018-09-06 19:38:41 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-09-06 19:38:41 +0000 |
commit | bd0971bde03f69c910b45afadeb95e83fcdd6264 (patch) | |
tree | aaa06ceab84a9da339c665599067815cff5f1885 | |
parent | 44d251edf7bb6d8f33c8f9a8cc6c702e9a2e15e4 (diff) | |
parent | 460badd8cca3a515bbcae5235c14c09cc907abaf (diff) | |
download | gitlab-ce-bd0971bde03f69c910b45afadeb95e83fcdd6264.tar.gz |
Merge branch '7211-geo-synchronization-does-not-seem-to-replicate-default-branch-all-the-time' into 'master'
Backport Gitlab::Git::Repository#find_remote_root_ref to CE
See merge request gitlab-org/gitlab-ce!21507
-rw-r--r-- | GITALY_SERVER_VERSION | 2 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | Gemfile.rails5.lock | 4 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/remote_service.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 27 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/remote_service_spec.rb | 11 |
8 files changed, 64 insertions, 6 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index 377d8aca07e..f34340fc21c 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -0.117.2 +0.119.0 @@ -425,7 +425,7 @@ group :ed25519 do end # Gitaly GRPC client -gem 'gitaly-proto', '~> 0.113.0', require: 'gitaly' +gem 'gitaly-proto', '~> 0.117.0', require: 'gitaly' gem 'grpc', '~> 1.11.0' # Locked until https://github.com/google/protobuf/issues/4210 is closed diff --git a/Gemfile.lock b/Gemfile.lock index e7ab97fb299..02f30b9d686 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -276,7 +276,7 @@ GEM gettext_i18n_rails (>= 0.7.1) po_to_json (>= 1.0.0) rails (>= 3.2.0) - gitaly-proto (0.113.0) + gitaly-proto (0.117.0) google-protobuf (~> 3.1) grpc (~> 1.10) github-linguist (5.3.3) @@ -1038,7 +1038,7 @@ DEPENDENCIES gettext (~> 3.2.2) gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails_js (~> 1.3) - gitaly-proto (~> 0.113.0) + gitaly-proto (~> 0.117.0) github-linguist (~> 5.3.3) gitlab-flowdock-git-hook (~> 1.0.1) gitlab-gollum-lib (~> 4.2) diff --git a/Gemfile.rails5.lock b/Gemfile.rails5.lock index 1a1aac9f439..2bdb1e035d8 100644 --- a/Gemfile.rails5.lock +++ b/Gemfile.rails5.lock @@ -279,7 +279,7 @@ GEM gettext_i18n_rails (>= 0.7.1) po_to_json (>= 1.0.0) rails (>= 3.2.0) - gitaly-proto (0.113.0) + gitaly-proto (0.117.0) google-protobuf (~> 3.1) grpc (~> 1.10) github-linguist (5.3.3) @@ -1047,7 +1047,7 @@ DEPENDENCIES gettext (~> 3.2.2) gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails_js (~> 1.3) - gitaly-proto (~> 0.113.0) + gitaly-proto (~> 0.117.0) github-linguist (~> 5.3.3) gitlab-flowdock-git-hook (~> 1.0.1) gitlab-gollum-lib (~> 4.2) diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 9521a2d63a0..74a1bfb273a 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -666,6 +666,14 @@ module Gitlab end end + def find_remote_root_ref(remote_name) + return unless remote_name.present? + + wrapped_gitaly_errors do + gitaly_remote_client.find_remote_root_ref(remote_name) + end + end + AUTOCRLF_VALUES = { "true" => true, "false" => false, diff --git a/lib/gitlab/gitaly_client/remote_service.rb b/lib/gitlab/gitaly_client/remote_service.rb index 1381e033d4b..6415c64b4e2 100644 --- a/lib/gitlab/gitaly_client/remote_service.rb +++ b/lib/gitlab/gitaly_client/remote_service.rb @@ -52,6 +52,18 @@ module Gitlab response.result end + def find_remote_root_ref(remote_name) + request = Gitaly::FindRemoteRootRefRequest.new( + repository: @gitaly_repo, + remote: remote_name + ) + + response = GitalyClient.call(@storage, :remote_service, + :find_remote_root_ref, request) + + response.ref.presence + end + def update_remote_mirror(ref_name, only_branches_matching) req_enum = Enumerator.new do |y| y.yield Gitaly::UpdateRemoteMirrorRequest.new( diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 17348b01006..1098a266140 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -583,6 +583,33 @@ describe Gitlab::Git::Repository, :seed_helper do end end + describe '#find_remote_root_ref' do + it 'gets the remote root ref from GitalyClient' do + expect_any_instance_of(Gitlab::GitalyClient::RemoteService) + .to receive(:find_remote_root_ref).and_call_original + + expect(repository.find_remote_root_ref('origin')).to eq 'master' + end + + it 'returns nil when remote name is nil' do + expect_any_instance_of(Gitlab::GitalyClient::RemoteService) + .not_to receive(:find_remote_root_ref) + + expect(repository.find_remote_root_ref(nil)).to be_nil + end + + it 'returns nil when remote name is empty' do + expect_any_instance_of(Gitlab::GitalyClient::RemoteService) + .not_to receive(:find_remote_root_ref) + + expect(repository.find_remote_root_ref('')).to be_nil + end + + it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RemoteService, :find_remote_root_ref do + subject { repository.find_remote_root_ref('origin') } + end + end + describe "#log" do shared_examples 'repository log' do let(:commit_with_old_name) do diff --git a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb index f03c7e3f04b..b8831c54aba 100644 --- a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb @@ -45,6 +45,17 @@ describe Gitlab::GitalyClient::RemoteService do end end + describe '#find_remote_root_ref' do + it 'sends an find_remote_root_ref message and returns the root ref' do + expect_any_instance_of(Gitaly::RemoteService::Stub) + .to receive(:find_remote_root_ref) + .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) + .and_return(double(ref: 'master')) + + expect(client.find_remote_root_ref('origin')).to eq 'master' + end + end + describe '#update_remote_mirror' do let(:ref_name) { 'remote_mirror_1' } let(:only_branches_matching) { ['my-branch', 'master'] } |