diff options
author | James Fargher <proglottis@gmail.com> | 2020-05-22 04:55:39 +0300 |
---|---|---|
committer | James Fargher <proglottis@gmail.com> | 2020-05-22 04:55:39 +0300 |
commit | 8122214a1052416fdd94cb547752cf4090c5d68d (patch) | |
tree | 0ccdddb758eb27bdb3561c490531f45ab1c6b56a | |
parent | 5b24bc1e54c5d4baf855dd819f8ece839adabed5 (diff) | |
parent | c56f3fc999e0672a885ce90b38856696baf0817f (diff) |
Merge branch 'pass-ssh-env-through-to-ls-remote-remote-branches' into 'master'
Pass SSH environment through to git ls-remote command for remote branches
See merge request gitlab-org/gitaly!2191
-rw-r--r-- | ruby/lib/gitlab/git/remote_mirror.rb | 8 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository_mirroring.rb | 4 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/remote_mirror_spec.rb | 4 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/repository_mirroring_spec.rb | 25 |
4 files changed, 32 insertions, 9 deletions
diff --git a/ruby/lib/gitlab/git/remote_mirror.rb b/ruby/lib/gitlab/git/remote_mirror.rb index 8b5d5d4d3..45a1936a1 100644 --- a/ruby/lib/gitlab/git/remote_mirror.rb +++ b/ruby/lib/gitlab/git/remote_mirror.rb @@ -20,9 +20,9 @@ module Gitlab def update ssh_auth.setup do |env| - updated_branches = changed_refs(local_branches, remote_branches) + updated_branches = changed_refs(local_branches, remote_branches(env: env)) push_refs(default_branch_first(updated_branches.keys), env: env) - delete_refs(local_branches, remote_branches, env: env) + delete_refs(local_branches, remote_branches(env: env), env: env) local_tags = refs_obj(repository.tags) remote_tags = refs_obj(repository.remote_tags(remote_name, env: env)) @@ -48,9 +48,9 @@ module Gitlab ) end - def remote_branches + def remote_branches(env:) @remote_branches ||= refs_obj( - repository.remote_branches(remote_name), + repository.remote_branches(remote_name, env: env), match_refs: true ) end diff --git a/ruby/lib/gitlab/git/repository_mirroring.rb b/ruby/lib/gitlab/git/repository_mirroring.rb index 129bab9c1..0e7f9f15b 100644 --- a/ruby/lib/gitlab/git/repository_mirroring.rb +++ b/ruby/lib/gitlab/git/repository_mirroring.rb @@ -12,7 +12,7 @@ module Gitlab tags: '+refs/tags/*:refs/tags/*' }.freeze - def remote_branches(remote_name) + def remote_branches(remote_name, env:) branches = [] rugged.references.each("refs/remotes/#{remote_name}/*").map do |ref| @@ -30,7 +30,7 @@ module Gitlab # # See https://gitlab.com/gitlab-org/gitaly/-/issues/2670 if feature_enabled?(:remote_branches_ls_remote) - ls_remote_branches = experimental_remote_branches(remote_name) + ls_remote_branches = experimental_remote_branches(remote_name, env: env) control_refs = branches.collect(&:name) experiment_refs = ls_remote_branches.collect(&:name) diff --git a/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb b/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb index e4611bce0..1821a7aa9 100644 --- a/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb +++ b/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb @@ -49,7 +49,7 @@ describe Gitlab::Git::RemoteMirror do expect(repository).to receive(:local_branches).and_return([ref('master'), ref('11-5-stable'), ref('unprotected')]) expect(repository).to receive(:remote_branches) - .with(ref_name) + .with(ref_name, env: env) .and_return([ref('master'), ref('obsolete-branch')]) expect(repository).to receive(:tags).and_return([tag('v1.0.0'), tag('new-tag')]) @@ -87,7 +87,7 @@ describe Gitlab::Git::RemoteMirror do expect(repository).to receive(:local_branches).and_return([ref('master'), ref('new-branch')]) expect(repository).to receive(:remote_branches) - .with(ref_name) + .with(ref_name, env: env) .and_return([ref('master'), ref('obsolete-branch')]) expect(repository).to receive(:tags).and_return([tag('v1.0.0'), tag('new-tag')]) diff --git a/ruby/spec/lib/gitlab/git/repository_mirroring_spec.rb b/ruby/spec/lib/gitlab/git/repository_mirroring_spec.rb index a0efc83f8..dca981717 100644 --- a/ruby/spec/lib/gitlab/git/repository_mirroring_spec.rb +++ b/ruby/spec/lib/gitlab/git/repository_mirroring_spec.rb @@ -6,8 +6,11 @@ describe Gitlab::Git::RepositoryMirroring do class FakeRepository include Gitlab::Git::RepositoryMirroring - def initialize(projects_stub) + attr_reader :rugged + + def initialize(projects_stub, rugged_instance = nil) @gitlab_projects = projects_stub + @rugged = rugged_instance end def gitlab_projects_error @@ -15,6 +18,26 @@ describe Gitlab::Git::RepositoryMirroring do end end + describe '#remote_branches' do + let(:projects_stub) { double.as_null_object } + let(:rugged_stub) { double.as_null_object } + + subject(:repository) { FakeRepository.new(projects_stub, rugged_stub) } + + it 'passes environment to `ls-remote`' do + env = { option_a: true, option_b: false } + + allow(repository).to receive(:feature_enabled?) + .with(:remote_branches_ls_remote) + .and_return(true) + expect(repository).to receive(:list_remote_refs) + .with('remote_a', env: env) + .and_return([]) + + repository.remote_branches('remote_a', env: env) + end + end + describe '#push_remote_branches' do let(:projects_stub) { double.as_null_object } |