Commit 50687897 authored by Stan Hu's avatar Stan Hu

Don't attempt to look up an avatar in repo if repo directory does not exist

Closes #14580
parent 63c8a05b
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.7.0 (unreleased) v 8.7.0 (unreleased)
- Don't attempt to look up an avatar in repo if repo directory does not exist (Stan hu)
- Preserve time notes/comments have been updated at when moving issue - Preserve time notes/comments have been updated at when moving issue
- Make HTTP(s) label consistent on clone bar (Stan Hu) - Make HTTP(s) label consistent on clone bar (Stan Hu)
- Fix avatar stretching by providing a cropping feature - Fix avatar stretching by providing a cropping feature
......
...@@ -877,6 +877,8 @@ class Repository ...@@ -877,6 +877,8 @@ class Repository
end end
def avatar def avatar
return nil unless exists?
@avatar ||= cache.fetch(:avatar) do @avatar ||= cache.fetch(:avatar) do
AVATAR_FILES.find do |file| AVATAR_FILES.find do |file|
blob_at_branch('master', file) blob_at_branch('master', file)
......
...@@ -422,6 +422,12 @@ describe Project, models: true do ...@@ -422,6 +422,12 @@ describe Project, models: true do
it { should eq "http://localhost#{avatar_path}" } it { should eq "http://localhost#{avatar_path}" }
end end
context 'when git repo is empty' do
let(:project) { create(:empty_project) }
it { should eq nil }
end
end end
describe :ci_commit do describe :ci_commit do
......
...@@ -725,6 +725,12 @@ describe Repository, models: true do ...@@ -725,6 +725,12 @@ describe Repository, models: true do
end end
describe '#avatar' do describe '#avatar' do
it 'returns nil if repo does not exist' do
expect(repository).to receive(:exists?).and_return(false)
expect(repository.avatar).to eq(nil)
end
it 'returns the first avatar file found in the repository' do it 'returns the first avatar file found in the repository' do
expect(repository).to receive(:blob_at_branch). expect(repository).to receive(:blob_at_branch).
with('master', 'logo.png'). with('master', 'logo.png').
......
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