diff options
author | Stan Hu <stanhu@gmail.com> | 2016-03-27 00:21:57 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-03-27 00:21:57 +0000 |
commit | c1834664a7a29a32551291102265ece978c55ffe (patch) | |
tree | a884cce1fb71d495debc0c0371604be6df88bc69 | |
parent | 8034e1a154aa355b8a212cc48acddf0401d414ce (diff) | |
parent | 506878970b2040be7446fc1a341d7abc61f9c6ec (diff) | |
download | gitlab-ce-c1834664a7a29a32551291102265ece978c55ffe.tar.gz |
Merge branch 'handle-avatar-in-empty-repo' into 'master'
Don't attempt to look up an avatar in repo if repo directory does not exist
Relates to https://sentry.gitlap.com/gitlab/gitlabcom/issues/3507/
Closes #14580
See merge request !3390
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/repository.rb | 2 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 6 |
4 files changed, 15 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG index c9527e6627e..7e9a447a8f6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. 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 - Make HTTP(s) label consistent on clone bar (Stan Hu) - Fix avatar stretching by providing a cropping feature diff --git a/app/models/repository.rb b/app/models/repository.rb index 908d765fb47..c07e8072043 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -889,6 +889,8 @@ class Repository end def avatar + return nil unless exists? + @avatar ||= cache.fetch(:avatar) do AVATAR_FILES.find do |file| blob_at_branch('master', file) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 20f06f4b7e1..55f1c665b86 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -422,6 +422,12 @@ describe Project, models: true do it { should eq "http://localhost#{avatar_path}" } end + + context 'when git repo is empty' do + let(:project) { create(:empty_project) } + + it { should eq nil } + end end describe :ci_commit do diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 417f11acca4..f10d671104c 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -744,6 +744,12 @@ describe Repository, models: true do end 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 expect(repository).to receive(:blob_at_branch). with('master', 'logo.png'). |