summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/repository.rb2
-rw-r--r--changelogs/unreleased/sh-handle-empty-import.yml4
-rw-r--r--spec/models/repository_spec.rb7
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