Fix Xcode project detection by looking for dirs instead of files

This commit is contained in:
Douwe Maan 2018-05-18 11:01:27 +00:00 committed by Douwe Maan
parent 83660e5712
commit 83cda43a00
No known key found for this signature in database
GPG Key ID: 5976703F65143D36
3 changed files with 23 additions and 13 deletions

View File

@ -596,7 +596,7 @@ class Repository
cache_method :gitlab_ci_yml
def xcode_project?
file_on_head(:xcode_config).present?
file_on_head(:xcode_config, :tree).present?
end
cache_method :xcode_project?
@ -920,11 +920,21 @@ class Repository
end
end
def file_on_head(type)
if head = tree(:head)
head.blobs.find do |blob|
Gitlab::FileDetector.type_of(blob.path) == type
def file_on_head(type, object_type = :blob)
return unless head = tree(:head)
objects =
case object_type
when :blob
head.blobs
when :tree
head.trees
else
raise ArgumentError, "Object type #{object_type} is not supported"
end
objects.find do |object|
Gitlab::FileDetector.type_of(object.path) == type
end
end

View File

@ -14,7 +14,7 @@ module Gitlab
avatar: /\Alogo\.(png|jpg|gif)\z/,
issue_template: %r{\A\.gitlab/issue_templates/[^/]+\.md\z},
merge_request_template: %r{\A\.gitlab/merge_request_templates/[^/]+\.md\z},
xcode_config: %r{\A[^/]*\.(xcodeproj|xcworkspace)\z},
xcode_config: %r{\A[^/]*\.(xcodeproj|xcworkspace)(/.+)?\z},
# Configuration files
gitignore: '.gitignore',

View File

@ -2021,27 +2021,27 @@ describe Repository do
describe '#xcode_project?' do
before do
allow(repository).to receive(:tree).with(:head).and_return(double(:tree, blobs: [blob]))
allow(repository).to receive(:tree).with(:head).and_return(double(:tree, trees: [tree]))
end
context 'when the root contains a *.xcodeproj file' do
let(:blob) { double(:blob, path: 'Foo.xcodeproj') }
context 'when the root contains a *.xcodeproj directory' do
let(:tree) { double(:tree, path: 'Foo.xcodeproj') }
it 'returns true' do
expect(repository.xcode_project?).to be_truthy
end
end
context 'when the root contains a *.xcworkspace file' do
let(:blob) { double(:blob, path: 'Foo.xcworkspace') }
context 'when the root contains a *.xcworkspace directory' do
let(:tree) { double(:tree, path: 'Foo.xcworkspace') }
it 'returns true' do
expect(repository.xcode_project?).to be_truthy
end
end
context 'when the root contains no XCode config file' do
let(:blob) { double(:blob, path: 'subdir/Foo.xcworkspace') }
context 'when the root contains no Xcode config directory' do
let(:tree) { double(:tree, path: 'Foo') }
it 'returns false' do
expect(repository.xcode_project?).to be_falsey