5
5
6
6
namespace GitVersion . VersionCalculation ;
7
7
8
- internal class PathFilter ( IReadOnlyList < string > paths ) : IVersionFilter
8
+ internal enum PathFilterMode
9
+ {
10
+ Inclusive , // All commit paths must match for commit to be excluded
11
+ //Exclusive // Any commit path must match for commit to be excluded
12
+ }
13
+
14
+ internal class PathFilter ( IReadOnlyList < string > paths , PathFilterMode mode = PathFilterMode . Inclusive ) : IVersionFilter
9
15
{
10
16
private readonly IReadOnlyList < Regex > pathsRegexes = [ .. paths . Select ( path => new Regex ( path , RegexOptions . Compiled ) ) ] ;
11
17
private readonly ConcurrentDictionary < string , bool > pathMatchCache = [ ] ;
@@ -16,25 +22,33 @@ public bool Exclude(IBaseVersion baseVersion, [NotNullWhen(true)] out string? re
16
22
return Exclude ( baseVersion . BaseVersionSource , out reason ) ;
17
23
}
18
24
25
+ private bool IsMatch ( string path )
26
+ {
27
+ if ( ! pathMatchCache . TryGetValue ( path , out var isMatch ) )
28
+ {
29
+ isMatch = this . pathsRegexes . Any ( regex => regex . IsMatch ( path ) ) ;
30
+ pathMatchCache [ path ] = isMatch ;
31
+ }
32
+ return isMatch ;
33
+ }
34
+
19
35
public bool Exclude ( ICommit ? commit , [ NotNullWhen ( true ) ] out string ? reason )
20
36
{
21
37
reason = null ;
22
38
23
39
if ( commit != null )
24
40
{
25
- foreach ( var path in commit . DiffPaths )
41
+ switch ( mode )
26
42
{
27
- if ( ! pathMatchCache . TryGetValue ( path , out var isMatch ) )
28
- {
29
- isMatch = this . pathsRegexes . Any ( regex => regex . IsMatch ( path ) ) ;
30
- pathMatchCache [ path ] = isMatch ;
31
- }
32
-
33
- if ( isMatch )
34
- {
35
- reason = "Source was ignored due to commit path matching ignore regex" ;
36
- return true ;
37
- }
43
+ case PathFilterMode . Inclusive :
44
+ {
45
+ if ( commit . DiffPaths . All ( this . IsMatch ) )
46
+ {
47
+ reason = "Source was ignored due to all commit paths matching ignore regex" ;
48
+ return true ;
49
+ }
50
+ break ;
51
+ }
38
52
}
39
53
}
40
54
0 commit comments