Commit 85b59a17 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'sh-fix-issue-50562' into 'master'

Fix remote mirrors failing if Git remotes have not been added

Closes #50562

See merge request gitlab-org/gitlab-ce!21351
parents 842377ab 578137f6
......@@ -150,6 +150,15 @@ class RemoteMirror < ActiveRecord::Base
result.to_s
end
def ensure_remote!
return unless project
return unless remote_name && url
# If this fails or the remote already exists, we won't know due to
# https://gitlab.com/gitlab-org/gitaly/issues/1317
project.repository.add_remote(remote_name, url)
end
private
def raw
......
......@@ -10,6 +10,7 @@ module Projects
return success unless remote_mirror.enabled?
begin
remote_mirror.ensure_remote!
repository.fetch_remote(remote_mirror.remote_name, no_tags: true)
opts = {}
......
---
title: Fix remote mirrors failing if Git remotes have not been added
merge_request: 21351
author:
type: fixed
......@@ -220,6 +220,18 @@ describe RemoteMirror do
end
end
context '#ensure_remote!' do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
it 'adds a remote multiple times with no errors' do
expect(remote_mirror.project.repository).to receive(:add_remote).with(remote_mirror.remote_name, remote_mirror.url).twice.and_call_original
2.times do
remote_mirror.ensure_remote!
end
end
end
context '#updated_since?' do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
let(:timestamp) { Time.now - 5.minutes }
......
......@@ -18,6 +18,7 @@ describe Projects::UpdateRemoteMirrorService do
end
it "fetches the remote repository" do
expect(remote_mirror).to receive(:ensure_remote!).and_call_original
expect(repository).to receive(:fetch_remote).with(remote_mirror.remote_name, no_tags: true) do
sync_remote(repository, remote_mirror.remote_name, local_branch_names)
end
......
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