Commit de97f66f authored by Douwe Maan's avatar Douwe Maan

Merge branch '1979-blobs-at' into 'master'

Fix migration error when project repository is missing

See merge request gitlab-org/gitlab-ee!9392
parents 1c171b75 2e95d8fe
...@@ -525,6 +525,8 @@ class Repository ...@@ -525,6 +525,8 @@ class Repository
# items is an Array like: [[oid, path], [oid1, path1]] # items is an Array like: [[oid, path], [oid1, path1]]
def blobs_at(items) def blobs_at(items)
return [] unless exists?
raw_repository.batch_blobs(items).map { |blob| Blob.decorate(blob, project) } raw_repository.batch_blobs(items).map { |blob| Blob.decorate(blob, project) }
end end
......
---
title: Fix background migration error when project repository is missing
merge_request: 9392
author:
type: fixed
...@@ -254,5 +254,17 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do ...@@ -254,5 +254,17 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do
end.not_to raise_error end.not_to raise_error
end end
end end
context 'when project has no repository' do
let(:project_without_repository) { create(:project) }
let(:target) { create(:merge_request, target_project: project_without_repository, source_project: project_without_repository) }
let(:target_type) { 'MergeRequest' }
it "does not err" do
expect do
described_class.new.perform(target_type, target.id)
end.not_to raise_error
end
end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs # rubocop:enable RSpec/FactoriesInMigrationSpecs
...@@ -1237,6 +1237,27 @@ describe Repository do ...@@ -1237,6 +1237,27 @@ describe Repository do
end end
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 describe '#root_ref' do
it 'returns a branch name' do it 'returns a branch name' do
expect(repository.root_ref).to be_an_instance_of(String) expect(repository.root_ref).to be_an_instance_of(String)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment