summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-03-24 09:29:00 -0700
committerStan Hu <stanhu@gmail.com>2016-03-25 06:30:51 -0700
commit506878970b2040be7446fc1a341d7abc61f9c6ec (patch)
treec1f1693ce133afa20ebc06c26c18ed1ae26c9900
parent63c8a05bf7f18ac4093ece1f08b4b5fd8dba5fac (diff)
downloadgitlab-ce-506878970b2040be7446fc1a341d7abc61f9c6ec.tar.gz
Don't attempt to look up an avatar in repo if repo directory does not exist
Closes #14580
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/repository.rb2
-rw-r--r--spec/models/project_spec.rb6
-rw-r--r--spec/models/repository_spec.rb6
4 files changed, 15 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5d9f4961ef5..18893feff06 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 13154eb4205..b69d5f239a0 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -877,6 +877,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 7eac70ae948..b30a6e7ae3d 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -725,6 +725,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').