diff --git a/app/models/project.rb b/app/models/project.rb index 5d0e61ecaa7..e569f325068 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1032,6 +1032,8 @@ class Project < ActiveRecord::Base end def fork_source + return nil unless forked? + forked_from_project || fork_network&.root_project end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 987be8e8b46..4d10df410ab 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1951,6 +1951,10 @@ describe Project do expect(second_fork.fork_source).to eq(project) end + + it 'returns nil if it is the root of the fork network' do + expect(project.fork_source).to be_nil + end end describe '#lfs_storage_project' do