diff options
author | Stan Hu <stanhu@gmail.com> | 2016-11-11 14:58:29 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-11-11 15:28:29 -0800 |
commit | cfc555f1951ba95376bd020ed1f1ef743f18ee52 (patch) | |
tree | 2f0c5a82ad55609f949a975fe9c03bcaa30db2a6 | |
parent | 67041e63c283fe4586251fdc56eaa02cc9a22241 (diff) | |
download | gitlab-ce-cfc555f1951ba95376bd020ed1f1ef743f18ee52.tar.gz |
Don't attempt to build the cache if the project repo is emptysh-handle-empty-import
Attempting to import an empty repo causes `Repository#build_cache`
to fail with a `nil Exception.
-rw-r--r-- | app/models/repository.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/sh-handle-empty-import.yml | 4 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 7 |
3 files changed, 13 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 063dc74021d..c01895b75e4 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -333,6 +333,8 @@ class Repository end def build_cache + return if empty? + (cache_keys + cache_keys_for_branches_and_tags).each do |key| unless cache.exist?(key) send(key) diff --git a/changelogs/unreleased/sh-handle-empty-import.yml b/changelogs/unreleased/sh-handle-empty-import.yml new file mode 100644 index 00000000000..500c573d587 --- /dev/null +++ b/changelogs/unreleased/sh-handle-empty-import.yml @@ -0,0 +1,4 @@ +--- +title: Don't attempt to build the cache if the project repo is empty +merge_request: +author: diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index fe26b4ac18c..b1dcb17f2d8 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1491,6 +1491,13 @@ describe Repository, models: true do repository.build_cache end + + it 'does not build cache for an empty repo' do + empty_project = create(:project_empty_repo) + expect(empty_project.repository.send(:cache)).not_to receive(:exist?) + + empty_project.repository.build_cache + end end describe "#keep_around" do |