diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-02-01 19:59:08 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-02-01 19:59:08 +0300 |
commit | c5d431240e09e20c49dd27b9c65a4865f3f79bbd (patch) | |
tree | bf810aeba73430d6b4570186433414587bb2a2f8 | |
parent | 1de1608a28d03f86c131961c046a7afbbf5b6e51 (diff) | |
parent | db35a3ae8aba3587dc5cadc1c44f1950502ff434 (diff) |
Merge branch 'ee-1979-blobs-at' into 'master'
Fix migration when project repository is missing
See merge request gitlab-org/gitlab-ce!24859
-rw-r--r-- | app/models/repository.rb | 2 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index b47238b52f1..e6ab3b484a2 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -525,6 +525,8 @@ class Repository # items is an Array like: [[oid, path], [oid1, path1]] def blobs_at(items) + return [] unless exists? + raw_repository.batch_blobs(items).map { |blob| Blob.decorate(blob, project) } end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index ac5874fd0f7..4978c43c9b5 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1237,6 +1237,27 @@ describe Repository do end end + describe '#blobs_at' do + let(:empty_repository) { create(:project_empty_repo).repository } + + it 'returns empty array for an empty repository' do + # rubocop:disable Style/WordArray + expect(empty_repository.blobs_at(['master', 'foobar'])).to eq([]) + # rubocop:enable Style/WordArray + end + + it 'returns blob array for a non-empty repository' do + repository.create_file(User.last, 'foobar', 'CONTENT', message: 'message', branch_name: 'master') + + # rubocop:disable Style/WordArray + blobs = repository.blobs_at([['master', 'foobar']]) + # rubocop:enable Style/WordArray + + expect(blobs.first.name).to eq('foobar') + expect(blobs.size).to eq(1) + end + end + describe '#root_ref' do it 'returns a branch name' do expect(repository.root_ref).to be_an_instance_of(String) |