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
end
end
options[:keep_divergent_refs] = keep_divergent_refs?
Gitlab::Git::RemoteMirror.new(
project.repository.raw,
remote_name,
......
......@@ -5,14 +5,15 @@ module Gitlab
class RemoteMirror
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
@ref_name = ref_name
@only_branches_matching = only_branches_matching
@ssh_key = ssh_key
@known_hosts = known_hosts
@keep_divergent_refs = keep_divergent_refs
end
def update
......@@ -21,7 +22,8 @@ module Gitlab
ref_name,
only_branches_matching,
ssh_key: ssh_key,
known_hosts: known_hosts
known_hosts: known_hosts,
keep_divergent_refs: keep_divergent_refs
)
end
end
......
......@@ -53,7 +53,7 @@ module Gitlab
encode_utf8(response.ref)
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|
first_request = Gitaly::UpdateRemoteMirrorRequest.new(
repository: @gitaly_repo,
......@@ -62,6 +62,7 @@ module Gitlab
first_request.ssh_key = ssh_key if ssh_key.present?
first_request.known_hosts = known_hosts if known_hosts.present?
first_request.keep_divergent_refs = keep_divergent_refs
y.yield(first_request)
......
......@@ -7,14 +7,14 @@ describe Gitlab::Git::RemoteMirror do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
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) }
it 'delegates to the Gitaly client' do
expect(repository.gitaly_remote_client)
.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
end
......
......@@ -66,7 +66,7 @@ describe Gitlab::GitalyClient::RemoteService do
.with(kind_of(Enumerator), kind_of(Hash))
.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
......
......@@ -142,6 +142,26 @@ describe RemoteMirror, :mailer do
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
context 'when URL contains 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