diff --git a/ee/app/models/ee/repository.rb b/ee/app/models/ee/repository.rb index 131c9f4fd3c99299337b185783e028db34d3cf00..a797ca9a0c00f161cb5a46a4b978ab34256e4ce0 100644 --- a/ee/app/models/ee/repository.rb +++ b/ee/app/models/ee/repository.rb @@ -131,7 +131,7 @@ def update_root_ref(remote_url, authorization) root_ref = find_remote_root_ref(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 repository #{full_path} (#{container.id}): #{e.message}.") + ::Gitlab::AppLogger.info("Error updating root ref for repository #{full_path} (#{container.id}): #{e.message}.") nil end diff --git a/ee/spec/models/repository_spec.rb b/ee/spec/models/repository_spec.rb index 999ad9ec2a2529f3ebba1bd43967425c164a7c35..015631825dec23057ab086c90663f8a6425f8941 100644 --- a/ee/spec/models/repository_spec.rb +++ b/ee/spec/models/repository_spec.rb @@ -370,12 +370,28 @@ def create_remote_branch(remote_name, branch_name, target) .not_to change { project.default_branch } end - it 'does not raise error when repository does not exist' do - allow(repository).to receive(:find_remote_root_ref) - .with(url, auth) - .and_raise(Gitlab::Git::Repository::NoRepository) + context 'when project repo is missing' do + before do + allow(repository).to receive(:find_remote_root_ref) + .with(url, auth) + .and_raise(Gitlab::Git::Repository::NoRepository) + end - expect { repository.update_root_ref(url, auth) }.not_to raise_error + it 'logs a message' do + expect(Gitlab::AppLogger) + .to receive(:info) + .with(/Error updating root ref for repository/) + + repository.update_root_ref(url, auth) + end + + it 'returns nil when NoRepository exception is raised' do + expect(repository.update_root_ref(url, auth)).to be_nil + end + + it 'does not raise error' do + expect { repository.update_root_ref(url, auth) }.not_to raise_error + end end def stub_find_remote_root_ref(repository, ref:)