diff --git a/ee/app/models/ee/repository.rb b/ee/app/models/ee/repository.rb index 35e069a5a5cb7625b9e66cbc4a9caf26b7991f95..bbfd304d50f818dd3d9343e9a8a5c965c6f6c7b4 100644 --- a/ee/app/models/ee/repository.rb +++ b/ee/app/models/ee/repository.rb @@ -134,7 +134,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 9e5bc7687b5ed6fe09cd9e4088bc6f7248c27d13..4c124ad269372c6399bf02260cfd879bfe56d1f0 100644 --- a/ee/spec/models/repository_spec.rb +++ b/ee/spec/models/repository_spec.rb @@ -372,12 +372,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:)