Commit 83cda43a authored by Douwe Maan's avatar Douwe Maan Committed by Douwe Maan

Fix Xcode project detection by looking for dirs instead of files

parent 83660e57
...@@ -596,7 +596,7 @@ class Repository ...@@ -596,7 +596,7 @@ class Repository
cache_method :gitlab_ci_yml cache_method :gitlab_ci_yml
def xcode_project? def xcode_project?
file_on_head(:xcode_config).present? file_on_head(:xcode_config, :tree).present?
end end
cache_method :xcode_project? cache_method :xcode_project?
...@@ -920,11 +920,21 @@ class Repository ...@@ -920,11 +920,21 @@ class Repository
end end
end end
def file_on_head(type) def file_on_head(type, object_type = :blob)
if head = tree(:head) return unless head = tree(:head)
head.blobs.find do |blob|
Gitlab::FileDetector.type_of(blob.path) == type objects =
case object_type
when :blob
head.blobs
when :tree
head.trees
else
raise ArgumentError, "Object type #{object_type} is not supported"
end end
objects.find do |object|
Gitlab::FileDetector.type_of(object.path) == type
end end
end end
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
avatar: /\Alogo\.(png|jpg|gif)\z/, avatar: /\Alogo\.(png|jpg|gif)\z/,
issue_template: %r{\A\.gitlab/issue_templates/[^/]+\.md\z}, issue_template: %r{\A\.gitlab/issue_templates/[^/]+\.md\z},
merge_request_template: %r{\A\.gitlab/merge_request_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 # Configuration files
gitignore: '.gitignore', gitignore: '.gitignore',
......
...@@ -2021,27 +2021,27 @@ describe Repository do ...@@ -2021,27 +2021,27 @@ describe Repository do
describe '#xcode_project?' do describe '#xcode_project?' do
before 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 end
context 'when the root contains a *.xcodeproj file' do context 'when the root contains a *.xcodeproj directory' do
let(:blob) { double(:blob, path: 'Foo.xcodeproj') } let(:tree) { double(:tree, path: 'Foo.xcodeproj') }
it 'returns true' do it 'returns true' do
expect(repository.xcode_project?).to be_truthy expect(repository.xcode_project?).to be_truthy
end end
end end
context 'when the root contains a *.xcworkspace file' do context 'when the root contains a *.xcworkspace directory' do
let(:blob) { double(:blob, path: 'Foo.xcworkspace') } let(:tree) { double(:tree, path: 'Foo.xcworkspace') }
it 'returns true' do it 'returns true' do
expect(repository.xcode_project?).to be_truthy expect(repository.xcode_project?).to be_truthy
end end
end end
context 'when the root contains no XCode config file' do context 'when the root contains no Xcode config directory' do
let(:blob) { double(:blob, path: 'subdir/Foo.xcworkspace') } let(:tree) { double(:tree, path: 'Foo') }
it 'returns false' do it 'returns false' do
expect(repository.xcode_project?).to be_falsey expect(repository.xcode_project?).to be_falsey
......
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