Exclusion patterns work only if processed after the inclusion ones.
See original GitHub issueIt took me quite a bit of time to figure out this one: if you have an exclusion pattern before an inclusion one, it won’t work. The reason is that match_files()
processes the patterns in whatever orders they are specified:
for pattern in patterns:
if pattern.include is not None:
result_files = pattern.match(all_files)
if pattern.include:
return_files.update(result_files)
else:
return_files.difference_update(result_files)
return return_files
If the exclusion pattern is processed first, the difference_update won’t have any effect since the return_files
will be empty. To fix that I separated the patterns in two lists and process the inclusion ones first:
include_patterns, exclude_patterns = partition(patterns, lambda p: p.include)
for pattern in include_patterns:
result_files = pattern.match(all_files)
return_files.update(result_files)
for pattern in exclude_patterns:
result_files = pattern.match(all_files)
return_files.difference_update(result_files)
return return_files
where partition
is defined as:
def partition(data, pred):
"""Partitions the data according to the predicate. Returns a tuple of lists (yes, no) with the partitioned elements."""
yes, no = [], []
for d in data:
(yes if pred(d) else no).append(d)
return [yes, no]
Of course you may fix this differently (for example you may “sort” the patterns
such that the exclusion ones come after the include ones.
HTH
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Working with Inclusion/Exclusion Patterns
Inclusion and exclusion patterns allow you include or exclude all resources which match a defined pattern when transferring data to/from a remote server....
Read more >How to use Include/Exclude patterns? - JFrog
Include patterns are a list of patterns to include when processing artifact requests. Only artifacts matching one of the “include patterns” ...
Read more >The Inclusion-Exclusion Principle - CP-Algorithms
The inclusion-exclusion principle is an important combinatorial way to compute the size of a set or the probability of complex events.
Read more >Filters/Include exclude patterns - How-to - Duplicacy Forum
If a match is not found, the path will be excluded if all patterns are include patterns, but included otherwise.
Read more >IntelliJ equivalent of "Inclusion and Exclusion Patterns"?
No, I think it works on IDEA 10 as well; however, I'd really prefer to use inclusion rather than exclusion patterns; also, I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ftrofin @ofek
I’ve now tested this and git handles the patterns as they appear in the “.gitignore” file. It does not run inclusion patterns before exclusion patterns. I’d recommend to sort the patterns after they’re compiled. I.e.,
Test 1 - git
Files:
.gitignore:
Files matched by git:
Test 1 - pathspec
Test 2 - git
Files:
.gitignore:
Files matched by git:
Test 2 - pathspec
@cpburnz Any update on this?