Handle forks in Gitlab::Checks::LfsIntegrity
This commit is contained in:
parent
78ea074f42
commit
ebd5174472
6 changed files with 57 additions and 19 deletions
|
@ -91,15 +91,7 @@ module LfsRequest
|
|||
end
|
||||
|
||||
def storage_project
|
||||
@storage_project ||= begin
|
||||
result = project
|
||||
|
||||
# TODO: Make this go to the fork_network root immeadiatly
|
||||
# dependant on the discussion in: https://gitlab.com/gitlab-org/gitlab-ce/issues/39769
|
||||
result = result.fork_source while result.forked?
|
||||
|
||||
result
|
||||
end
|
||||
@storage_project ||= project.lfs_storage_project
|
||||
end
|
||||
|
||||
def objects
|
||||
|
|
|
@ -6,16 +6,8 @@ class LfsObject < ActiveRecord::Base
|
|||
|
||||
mount_uploader :file, LfsObjectUploader
|
||||
|
||||
def storage_project(project)
|
||||
if project && project.forked?
|
||||
storage_project(project.forked_from_project)
|
||||
else
|
||||
project
|
||||
end
|
||||
end
|
||||
|
||||
def project_allowed_access?(project)
|
||||
projects.exists?(storage_project(project).id)
|
||||
projects.exists?(project.lfs_storage_project.id)
|
||||
end
|
||||
|
||||
def self.destroy_unreferenced
|
||||
|
|
|
@ -1042,6 +1042,18 @@ class Project < ActiveRecord::Base
|
|||
forked_from_project || fork_network&.root_project
|
||||
end
|
||||
|
||||
def lfs_storage_project
|
||||
@lfs_storage_project ||= begin
|
||||
result = self
|
||||
|
||||
# TODO: Make this go to the fork_network root immeadiatly
|
||||
# dependant on the discussion in: https://gitlab.com/gitlab-org/gitlab-ce/issues/39769
|
||||
result = result.fork_source while result&.forked?
|
||||
|
||||
result || self
|
||||
end
|
||||
end
|
||||
|
||||
def personal?
|
||||
!group
|
||||
end
|
||||
|
|
|
@ -15,7 +15,10 @@ module Gitlab
|
|||
|
||||
return false unless new_lfs_pointers.present?
|
||||
|
||||
existing_count = @project.lfs_objects.where(oid: new_lfs_pointers.map(&:lfs_oid)).count
|
||||
existing_count = @project.lfs_storage_project
|
||||
.lfs_objects
|
||||
.where(oid: new_lfs_pointers.map(&:lfs_oid))
|
||||
.count
|
||||
|
||||
existing_count != new_lfs_pointers.count
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Checks::LfsIntegrity do
|
||||
include ProjectForksHelper
|
||||
let(:project) { create(:project, :repository) }
|
||||
let(:newrev) { '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51' }
|
||||
|
||||
|
@ -49,5 +50,25 @@ describe Gitlab::Checks::LfsIntegrity do
|
|||
expect(subject.objects_missing?).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context 'for forked project' do
|
||||
let(:parent_project) { create(:project, :repository) }
|
||||
let(:project) { fork_project(parent_project, nil, repository: true) }
|
||||
|
||||
before do
|
||||
allow(project).to receive(:lfs_enabled?).and_return(true)
|
||||
end
|
||||
|
||||
it 'is true parent project is missing LFS objects' do
|
||||
expect(subject.objects_missing?).to be_truthy
|
||||
end
|
||||
|
||||
it 'is false parent project already conatins LFS objects for the fork' do
|
||||
lfs_object = create(:lfs_object, oid: blob_object.lfs_oid)
|
||||
create(:lfs_objects_project, project: parent_project, lfs_object: lfs_object)
|
||||
|
||||
expect(subject.objects_missing?).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1943,6 +1943,24 @@ describe Project do
|
|||
expect(second_fork.fork_source).to eq(project)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#lfs_storage_project' do
|
||||
it 'returns self for non-forks' do
|
||||
expect(project.lfs_storage_project).to eq project
|
||||
end
|
||||
|
||||
it 'returns the fork network root for forks' do
|
||||
second_fork = fork_project(forked_project)
|
||||
|
||||
expect(second_fork.lfs_storage_project).to eq project
|
||||
end
|
||||
|
||||
it 'returns self when fork_source is nil' do
|
||||
expect(forked_project).to receive(:fork_source).and_return(nil)
|
||||
|
||||
expect(forked_project.lfs_storage_project).to eq forked_project
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#pushes_since_gc' do
|
||||
|
|
Loading…
Reference in a new issue