Does not raise errors for empty repositories

https://gitlab.com/gitlab-org/gitaly/-/merge_requests/3412
changes the behavior of `Gitaly::FindRemoteRootRefRequest`
for  empty repositories raising an error "no remote HEAD found"
instead of returning a nil value breaking the Geo replication
for empty repositories. This commit handle the error keeping
the old behavior.
parent d59510b4
......@@ -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
......
......@@ -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)
......
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