Synchronize the default branch in secondary nodes

parent 1f93e85a
......@@ -10,7 +10,7 @@ module EE
MIRROR_REMOTE = "upstream".freeze
included do
delegate :checksum, to: :raw_repository
delegate :checksum, :find_remote_root_ref, to: :raw_repository
end
# Transiently sets a configuration variable
......
......@@ -6,9 +6,7 @@ module Geo
def sync_repository
fetch_repository
update_gitattributes
update_default_branch
mark_sync_as_successful
rescue Gitlab::Shell::Error => e
# In some cases repository does not exist, the only way to know about this is to parse the error text.
......@@ -47,11 +45,10 @@ module Geo
project.ensure_repository
end
# Update info/attributes file using the contents of .gitattributes file from the default branch
def update_gitattributes
return if project.default_branch.nil?
repository.copy_gitattributes(project.default_branch)
# Update the default branch querying the remote to determine its HEAD
def update_default_branch
root_ref = repository.find_remote_root_ref(GEO_REMOTE_NAME)
project.change_head(root_ref) if root_ref.present?
end
def schedule_repack
......
......@@ -31,6 +31,11 @@ describe Geo::RepositorySyncService do
allow_any_instance_of(Repository).to receive(:fetch_as_mirror)
.and_return(true)
allow_any_instance_of(Repository)
.to receive(:find_remote_root_ref)
.with('geo')
.and_return('master')
end
it 'fetches project repository with JWT credentials' do
......@@ -215,6 +220,17 @@ describe Geo::RepositorySyncService do
subject.execute
end
it 'updates the default branch' do
allow(project.repository)
.to receive(:find_remote_root_ref)
.with('geo')
.and_return('development')
expect(project).to receive(:change_head).with('development').once
subject.execute
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