Commit a5e50b0e authored by Sean McGivern's avatar Sean McGivern

Merge branch '330485-geo-failing-to-replicate-empty-projects' into 'master'

Geo - Fix replication for for empty projects

See merge request gitlab-org/gitlab!61419
parents 816b507f de245fca
......@@ -5,4 +5,4 @@ rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/329664
milestone: '13.12'
type: development
group: group::gitaly
default_enabled: true
default_enabled: false
......@@ -710,6 +710,9 @@ module EE
def update_root_ref(remote, remote_url, authorization)
root_ref = repository.find_remote_root_ref(remote, remote_url, authorization)
change_head(root_ref) if root_ref.present?
rescue ::Gitlab::Git::Repository::NoRepository => e
::Gitlab::AppLogger.error("Error updating root ref for project #{full_path} (#{id}): #{e.message}.")
nil
end
override :lfs_http_url_to_repo
......
......@@ -57,8 +57,8 @@ module Geo
project.update_root_ref(GEO_REMOTE_NAME, remote_url, authorization)
else
repository_with_config(jwt_authentication_header) do
project.update_root_ref(GEO_REMOTE_NAME, remote_url)
repository.with_config(jwt_authentication_header) do
project.update_root_ref(GEO_REMOTE_NAME, remote_url, nil)
end
end
end
......
---
title: Geo - Fix replication for for empty projects
merge_request: 61419
author:
type: fixed
......@@ -2178,6 +2178,14 @@ RSpec.describe Project do
.not_to change { project.default_branch }
end
it 'does not raise error when repository does not exist' do
allow(project.repository).to receive(:find_remote_root_ref)
.with('origin', url, auth)
.and_raise(Gitlab::Git::Repository::NoRepository)
expect { project.update_root_ref('origin', url, auth) }.not_to raise_error
end
def stub_find_remote_root_ref(project, ref:)
allow(project.repository)
.to receive(:find_remote_root_ref)
......
......@@ -233,11 +233,16 @@ RSpec.describe Geo::RepositorySyncService, :geo do
context 'with non empty repositories' do
let(:project) { create(:project, :repository) }
context 'when when HEAD change' do
context 'with inmemory feature disabled' do
before do
stub_feature_flags(find_remote_root_refs_inmemory: false)
end
context 'when HEAD change' do
before do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, anything)
.with('geo', url_to_repo, nil)
.and_return('feature')
end
......@@ -251,6 +256,7 @@ RSpec.describe Geo::RepositorySyncService, :geo do
expect(repository).to receive(:with_config)
.with("http.#{url_to_repo}.extraHeader" => anything)
.and_call_original
.twice
expect(project).to receive(:change_head).with('feature').once
......@@ -262,7 +268,7 @@ RSpec.describe Geo::RepositorySyncService, :geo do
before do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, anything)
.with('geo', url_to_repo, nil)
.and_return(project.default_branch)
end
......@@ -276,6 +282,7 @@ RSpec.describe Geo::RepositorySyncService, :geo do
expect(repository).to receive(:with_config)
.with("http.#{url_to_repo}.extraHeader" => anything)
.and_call_original
.twice
expect(project).to receive(:change_head).with('master').once
......@@ -283,6 +290,65 @@ RSpec.describe Geo::RepositorySyncService, :geo do
end
end
end
context 'with inmemory feature enabled' do
before do
stub_feature_flags(find_remote_root_refs_inmemory: true)
end
context 'when HEAD change' do
before do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, anything)
.and_return('feature')
end
it 'syncs gitattributes to info/attributes' do
expect(repository).to receive(:copy_gitattributes)
subject.execute
end
it 'updates the default branch' do
expect(repository).to receive(:with_config)
.with("http.#{url_to_repo}.extraHeader" => anything)
.and_call_original
.once
expect(project).to receive(:change_head).with('feature').once
subject.execute
end
end
context 'when HEAD does not change' do
before do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, anything)
.and_return(project.default_branch)
end
it 'syncs gitattributes to info/attributes' do
expect(repository).to receive(:copy_gitattributes)
subject.execute
end
it 'updates the default branch' do
expect(repository).to receive(:with_config)
.with("http.#{url_to_repo}.extraHeader" => anything)
.and_call_original
.once
expect(project).to receive(:change_head).with('master').once
subject.execute
end
end
end
end
end
context 'when repository sync fail' 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