Commit ccf52282 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Mark Chao

Support wildcard with double asterisks for CI file includes

parent c92f0085
......@@ -995,7 +995,13 @@ class Repository
def search_files_by_wildcard_path(path, ref = 'HEAD')
# We need to use RE2 to match Gitaly's regexp engine
regexp_string = RE2::Regexp.escape(path).gsub('\*', '.*?')
regexp_string = RE2::Regexp.escape(path)
anything = '.*?'
anything_but_not_slash = '([^\/])*?'
regexp_string.gsub!('\*\*', anything)
regexp_string.gsub!('\*', anything_but_not_slash)
raw_repository.search_files_by_regexp("^#{regexp_string}$", ref)
end
......
......@@ -487,7 +487,7 @@ Use local includes instead of symbolic links.
> - It's not recommended for production use.
> - To use it in GitLab self-managed instances, ask a GitLab administrator to enable it. **(CORE ONLY)**
You can use wildcard paths (`*`) with `include:local`.
You can use wildcard paths (`*` and `**`) with `include:local`.
Example:
......@@ -495,7 +495,19 @@ Example:
include: 'configs/*.yml'
```
When the pipeline runs, it adds all `.yml` files in the `configs` folder into the pipeline configuration.
When the pipeline runs, GitLab:
- Adds all `.yml` files in the `configs` directory into the pipeline configuration.
- Does not add `.yml` files in subfolders of the `configs` directory. To allow this,
add the following configuration:
```yaml
# This matches all `.yml` files in `configs` and any subfolder in it.
include: 'configs/**.yml'
# This matches all `.yml` files only in subfolders of `configs`.
include: 'configs/**/*.yml'
```
The wildcard file paths feature is under development and not ready for production use. It is
deployed behind a feature flag that is **disabled by default**.
......
......@@ -1006,19 +1006,58 @@ RSpec.describe Repository do
end
end
context 'when specifying a path with wildcard' do
let(:path) { 'files/*/*.png' }
context 'when specifying a wildcard path' do
let(:path) { '*.md' }
it 'returns files matching the path in the root folder' do
expect(result).to contain_exactly('CONTRIBUTING.md',
'MAINTENANCE.md',
'PROCESS.md',
'README.md')
end
end
context 'when specifying a wildcard path for all' do
let(:path) { '**.md' }
it 'returns all matching files in all folders' do
expect(result).to contain_exactly('CONTRIBUTING.md',
'MAINTENANCE.md',
'PROCESS.md',
'README.md',
'files/markdown/ruby-style-guide.md',
'with space/README.md')
end
end
context 'when specifying a path to subfolders using two asterisks and a slash' do
let(:path) { 'files/**/*.md' }
it 'returns all files matching the path' do
expect(result).to contain_exactly('files/images/logo-black.png',
'files/images/logo-white.png')
expect(result).to contain_exactly('files/markdown/ruby-style-guide.md')
end
end
context 'when specifying a wildcard path to subfolder with just two asterisks' do
let(:path) { 'files/**.md' }
it 'returns all files in the matching path' do
expect(result).to contain_exactly('files/markdown/ruby-style-guide.md')
end
end
context 'when specifying a wildcard path to subfolder with one asterisk' do
let(:path) { 'files/*/*.md' }
it 'returns all files in the matching path' do
expect(result).to contain_exactly('files/markdown/ruby-style-guide.md')
end
end
context 'when specifying an extension with wildcard' do
let(:path) { '*.rb' }
context 'when specifying a wildcard path for an unknown number of subfolder levels' do
let(:path) { '**/*.rb' }
it 'returns all files matching the extension' do
it 'returns all matched files in all subfolders' do
expect(result).to contain_exactly('encoding/russian.rb',
'files/ruby/popen.rb',
'files/ruby/regex.rb',
......@@ -1026,6 +1065,14 @@ RSpec.describe Repository do
end
end
context 'when specifying a wildcard path to one level of subfolders' do
let(:path) { '*/*.rb' }
it 'returns all matched files in one subfolder' do
expect(result).to contain_exactly('encoding/russian.rb')
end
end
context 'when sending regexp' do
let(:path) { '.*\.rb' }
......
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