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,53 +233,119 @@ 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
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, anything)
.and_return('feature')
stub_feature_flags(find_remote_root_refs_inmemory: false)
end
it 'syncs gitattributes to info/attributes' do
expect(repository).to receive(:copy_gitattributes)
context 'when HEAD change' do
before do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, nil)
.and_return('feature')
end
subject.execute
it 'syncs gitattributes to info/attributes' do
expect(repository).to receive(:copy_gitattributes)
subject.execute
end
it 'updates the default branch with JWT credentials' 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
subject.execute
end
end
it 'updates the default branch with JWT credentials' do
expect(repository).to receive(:with_config)
.with("http.#{url_to_repo}.extraHeader" => anything)
.and_call_original
context 'when HEAD does not change' do
before do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, nil)
.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 with JWT credentials' 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
expect(project).to receive(:change_head).with('master').once
subject.execute
subject.execute
end
end
end
context 'when HEAD does not change' do
context 'with inmemory feature enabled' do
before do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo', url_to_repo, anything)
.and_return(project.default_branch)
stub_feature_flags(find_remote_root_refs_inmemory: true)
end
it 'syncs gitattributes to info/attributes' do
expect(repository).to receive(:copy_gitattributes)
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
subject.execute
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
it 'updates the default branch with JWT credentials' do
expect(repository).to receive(:with_config)
.with("http.#{url_to_repo}.extraHeader" => anything)
.and_call_original
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
expect(project).to receive(:change_head).with('master').once
subject.execute
subject.execute
end
end
end
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