Commit 70f230b0 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rs-keep-divergent-refs-backend' into 'master'

Add backend "keep divergent refs" option

See merge request gitlab-org/gitlab!26406
parents 999ba82d 3c0e3b8a
...@@ -117,6 +117,8 @@ class RemoteMirror < ApplicationRecord ...@@ -117,6 +117,8 @@ class RemoteMirror < ApplicationRecord
end end
end end
options[:keep_divergent_refs] = keep_divergent_refs?
Gitlab::Git::RemoteMirror.new( Gitlab::Git::RemoteMirror.new(
project.repository.raw, project.repository.raw,
remote_name, remote_name,
......
...@@ -5,14 +5,15 @@ module Gitlab ...@@ -5,14 +5,15 @@ module Gitlab
class RemoteMirror class RemoteMirror
include Gitlab::Git::WrapsGitalyErrors include Gitlab::Git::WrapsGitalyErrors
attr_reader :repository, :ref_name, :only_branches_matching, :ssh_key, :known_hosts attr_reader :repository, :ref_name, :only_branches_matching, :ssh_key, :known_hosts, :keep_divergent_refs
def initialize(repository, ref_name, only_branches_matching: [], ssh_key: nil, known_hosts: nil) def initialize(repository, ref_name, only_branches_matching: [], ssh_key: nil, known_hosts: nil, keep_divergent_refs: false)
@repository = repository @repository = repository
@ref_name = ref_name @ref_name = ref_name
@only_branches_matching = only_branches_matching @only_branches_matching = only_branches_matching
@ssh_key = ssh_key @ssh_key = ssh_key
@known_hosts = known_hosts @known_hosts = known_hosts
@keep_divergent_refs = keep_divergent_refs
end end
def update def update
...@@ -21,7 +22,8 @@ module Gitlab ...@@ -21,7 +22,8 @@ module Gitlab
ref_name, ref_name,
only_branches_matching, only_branches_matching,
ssh_key: ssh_key, ssh_key: ssh_key,
known_hosts: known_hosts known_hosts: known_hosts,
keep_divergent_refs: keep_divergent_refs
) )
end end
end end
......
...@@ -53,7 +53,7 @@ module Gitlab ...@@ -53,7 +53,7 @@ module Gitlab
encode_utf8(response.ref) encode_utf8(response.ref)
end end
def update_remote_mirror(ref_name, only_branches_matching, ssh_key: nil, known_hosts: nil) def update_remote_mirror(ref_name, only_branches_matching, ssh_key: nil, known_hosts: nil, keep_divergent_refs: false)
req_enum = Enumerator.new do |y| req_enum = Enumerator.new do |y|
first_request = Gitaly::UpdateRemoteMirrorRequest.new( first_request = Gitaly::UpdateRemoteMirrorRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
...@@ -62,6 +62,7 @@ module Gitlab ...@@ -62,6 +62,7 @@ module Gitlab
first_request.ssh_key = ssh_key if ssh_key.present? first_request.ssh_key = ssh_key if ssh_key.present?
first_request.known_hosts = known_hosts if known_hosts.present? first_request.known_hosts = known_hosts if known_hosts.present?
first_request.keep_divergent_refs = keep_divergent_refs
y.yield(first_request) y.yield(first_request)
......
...@@ -7,14 +7,14 @@ describe Gitlab::Git::RemoteMirror do ...@@ -7,14 +7,14 @@ describe Gitlab::Git::RemoteMirror do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:repository) { project.repository } let(:repository) { project.repository }
let(:ref_name) { 'foo' } let(:ref_name) { 'foo' }
let(:options) { { only_branches_matching: ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS' } } let(:options) { { only_branches_matching: ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS', keep_divergent_refs: true } }
subject(:remote_mirror) { described_class.new(repository, ref_name, **options) } subject(:remote_mirror) { described_class.new(repository, ref_name, **options) }
it 'delegates to the Gitaly client' do it 'delegates to the Gitaly client' do
expect(repository.gitaly_remote_client) expect(repository.gitaly_remote_client)
.to receive(:update_remote_mirror) .to receive(:update_remote_mirror)
.with(ref_name, ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS') .with(ref_name, ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS', keep_divergent_refs: true)
remote_mirror.update remote_mirror.update
end end
......
...@@ -66,7 +66,7 @@ describe Gitlab::GitalyClient::RemoteService do ...@@ -66,7 +66,7 @@ describe Gitlab::GitalyClient::RemoteService do
.with(kind_of(Enumerator), kind_of(Hash)) .with(kind_of(Enumerator), kind_of(Hash))
.and_return(double(:update_remote_mirror_response)) .and_return(double(:update_remote_mirror_response))
client.update_remote_mirror(ref_name, only_branches_matching, ssh_key: ssh_key, known_hosts: known_hosts) client.update_remote_mirror(ref_name, only_branches_matching, ssh_key: ssh_key, known_hosts: known_hosts, keep_divergent_refs: true)
end end
end end
......
...@@ -142,6 +142,26 @@ describe RemoteMirror, :mailer do ...@@ -142,6 +142,26 @@ describe RemoteMirror, :mailer do
end end
end end
describe '#update_repository' do
let(:git_remote_mirror) { spy }
before do
stub_const('Gitlab::Git::RemoteMirror', git_remote_mirror)
end
it 'includes the `keep_divergent_refs` setting' do
mirror = build_stubbed(:remote_mirror, keep_divergent_refs: true)
mirror.update_repository({})
expect(git_remote_mirror).to have_received(:new).with(
anything,
mirror.remote_name,
hash_including(keep_divergent_refs: true)
)
end
end
describe '#safe_url' do describe '#safe_url' do
context 'when URL contains credentials' do context 'when URL contains credentials' do
it 'masks the credentials' do it 'masks the credentials' do
......
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