Commit dcc684c4 authored by Patrick Steinhardt's avatar Patrick Steinhardt

repository: Convert #fetch_upstream to use in-memory remotes

Convert `Repository#fetch_upstream()` to use `fetch_remote()` with an
in-memory remote. This allows us to skip the call to `add_remote()`: its
backing RPC call is deprecated and will eventually be removed by Gitaly.

The change reuses the `fetch_remote_params` feature flag which is also
used by the GitHub importer and by `fetch_as_mirror()`. This is fine
given that the feature flag hasn't yet been rolled out to production and
is thus still disabled.
parent f90a8af4
......@@ -34,6 +34,17 @@ module EE
end
def fetch_upstream(url, forced: false, check_tags_changed: false)
if ::Feature.enabled?(:fetch_remote_params, project, default_enabled: :yaml)
return fetch_remote(
MIRROR_REMOTE,
url: url,
refmap: ["+refs/heads/*:refs/remotes/#{MIRROR_REMOTE}/*"],
ssh_auth: project&.import_data,
forced: forced,
check_tags_changed: check_tags_changed
)
end
add_remote(MIRROR_REMOTE, url)
fetch_remote(MIRROR_REMOTE, ssh_auth: project&.import_data, forced: forced, check_tags_changed: check_tags_changed)
......
......@@ -49,6 +49,41 @@ RSpec.describe Repository do
end
end
describe '#fetch_upstream' do
let(:url) { "http://example.com" }
context 'when :fetch_remote_params is enabled' do
it 'fetches the URL without creating a remote' do
expect(repository).not_to receive(:add_remote)
expect(repository)
.to receive(:fetch_remote)
.with(described_class::MIRROR_REMOTE, url: url, refmap: ['+refs/heads/*:refs/remotes/upstream/*'], ssh_auth: nil, forced: true, check_tags_changed: true)
.and_return(nil)
repository.fetch_upstream(url, forced: true, check_tags_changed: true)
end
end
context 'when :fetch_remote_params is disabled' do
before do
stub_feature_flags(fetch_remote_params: false)
end
it 'creates a remote and fetches it' do
expect(repository)
.to receive(:add_remote)
.with(described_class::MIRROR_REMOTE, url)
.and_return(nil)
expect(repository)
.to receive(:fetch_remote)
.with(described_class::MIRROR_REMOTE, ssh_auth: nil, forced: true, check_tags_changed: true)
.and_return(nil)
repository.fetch_upstream(url, forced: true, check_tags_changed: true)
end
end
end
describe '#with_config' do
let(:rugged) { rugged_repo(repository) }
let(:entries) 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