Skip to content
Snippets Groups Projects
Unverified Commit 83cda43a authored by Douwe Maan's avatar Douwe Maan Committed by Douwe Maan
Browse files

Fix Xcode project detection by looking for dirs instead of files

parent 83660e57
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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?
 
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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',
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment