Skip to content

Commit 2b207a6

Browse files
authored
Merge pull request #4420 from Roei-Levi/feature/paths-filter
Feature: Support ignoring (filtering) paths in git tree
2 parents f37d7df + 212fe9f commit 2b207a6

38 files changed

+420
-36
lines changed

docs/input/docs/reference/configuration.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ branches:
191191
is-main-branch: false
192192
ignore:
193193
sha: []
194+
paths: []
194195
mode: ContinuousDelivery
195196
label: '{BranchName}'
196197
increment: Inherit
@@ -208,7 +209,7 @@ tracks-release-branches: false
208209
is-release-branch: false
209210
is-main-branch: false
210211
```
211-
<sup><a href='/docs/workflows/GitFlow/v1.yml#L1-L166' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
212+
<sup><a href='/docs/workflows/GitFlow/v1.yml#L1-L167' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
212213
<!-- endSnippet -->
213214

214215
The supported built-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like:
@@ -315,6 +316,7 @@ branches:
315316
is-main-branch: false
316317
ignore:
317318
sha: []
319+
paths: []
318320
mode: ContinuousDelivery
319321
label: '{BranchName}'
320322
increment: Inherit
@@ -332,7 +334,7 @@ tracks-release-branches: false
332334
is-release-branch: false
333335
is-main-branch: false
334336
```
335-
<sup><a href='/docs/workflows/GitHubFlow/v1.yml#L1-L115' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitHubFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
337+
<sup><a href='/docs/workflows/GitHubFlow/v1.yml#L1-L116' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitHubFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
336338
<!-- endSnippet -->
337339

338340
The preview built-in configuration (experimental usage only) for the `TrunkBased` workflow (`workflow: TrunkBased/preview1`) looks like:
@@ -424,6 +426,7 @@ branches:
424426
pre-release-weight: 30000
425427
ignore:
426428
sha: []
429+
paths: []
427430
mode: ContinuousDelivery
428431
label: '{BranchName}'
429432
increment: Inherit
@@ -441,7 +444,7 @@ tracks-release-branches: false
441444
is-release-branch: false
442445
is-main-branch: false
443446
```
444-
<sup><a href='/docs/workflows/TrunkBased/preview1.yml#L1-L100' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/TrunkBased/preview1.yml' title='Start of snippet'>anchor</a></sup>
447+
<sup><a href='/docs/workflows/TrunkBased/preview1.yml#L1-L101' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/TrunkBased/preview1.yml' title='Start of snippet'>anchor</a></sup>
445448
<!-- endSnippet -->
446449

447450
The details of the available options are as follows:
@@ -621,6 +624,44 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
621624
2015-10-23T12:23:15`) to setup an exclusion range. Effectively any commit before
622625
`commits-before` will be ignored.
623626

627+
#### paths
628+
A sequence of regular expressions that represent paths in the repository. Commits that modify these paths will be excluded from version calculations. For example, to filter out commits that belong to `docs`:
629+
```yaml
630+
ignore:
631+
paths:
632+
- ^docs\/
633+
```
634+
##### *Monorepo*
635+
This ignore config can be used to filter only those commits that belong to a specific project in a monorepo.
636+
As an example, consider a monorepo consisting of subdirectories for `ProjectA`, `ProjectB` and a shared `LibraryC`. For GitVersion to consider only commits that are part of `projectA` and shared library `LibraryC`, a regex that matches all paths except those starting with `ProjectA` or `LibraryC` can be used. Either one of the following configs would filter out `ProjectB`.
637+
* Specific match on `/ProjectB/*`:
638+
```yaml
639+
ignore:
640+
paths:
641+
- `^\/ProductB\/.*`
642+
```
643+
* Negative lookahead on anything other than `/ProjectA/*` and `/LibraryC/*`:
644+
```yaml
645+
ignore:
646+
paths:
647+
- `^(?!\/ProductA\/|\/LibraryC\/).*`
648+
```
649+
A commit having changes only in `/ProjectB/*` path would be ignored. A commit having changes in the following paths wouldn't be ignored:
650+
* `/ProductA/*`
651+
* `/LibraryC/*`
652+
* `/ProductA/*` and `/LibraryC/*`
653+
* `/ProductA/*` and `/ProductB/*`
654+
* `/LibraryC/*` and `/ProductB/*`
655+
* `/ProductA/*` and `/ProductB/*` and `/LibraryC/*`
656+
657+
:::
658+
Note: The `ignore.paths` configuration is case-sensitive. This can lead to unexpected behavior on case-insensitive file systems, such as Windows. To ensure consistent matching regardless of case, you can prefix your regular expressions with the case-insensitive flag `(?i)`. For example, `(?i)^docs\/` will match both `docs/` and `Docs/`.
659+
:::
660+
661+
::: {.alert .alert-warning}
662+
A commit is ignored by the `ignore.paths` configuration only if **all paths** changed in that commit match one or more of the specified regular expressions. If a path in a commit does not match any one of the ignore patterns, that commit will be included in version calculations.
663+
:::
664+
624665
### merge-message-formats
625666

626667
Custom merge message formats to enable identification of merge messages that do not

docs/input/docs/reference/mdsource/configuration.source.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,44 @@ Date and time in the format `yyyy-MM-ddTHH:mm:ss` (eg `commits-before:
225225
2015-10-23T12:23:15`) to setup an exclusion range. Effectively any commit before
226226
`commits-before` will be ignored.
227227

228+
#### paths
229+
A sequence of regular expressions that represent paths in the repository. Commits that modify these paths will be excluded from version calculations. For example, to filter out commits that belong to `docs`:
230+
```yaml
231+
ignore:
232+
paths:
233+
- ^docs\/
234+
```
235+
##### *Monorepo*
236+
This ignore config can be used to filter only those commits that belong to a specific project in a monorepo.
237+
As an example, consider a monorepo consisting of subdirectories for `ProjectA`, `ProjectB` and a shared `LibraryC`. For GitVersion to consider only commits that are part of `projectA` and shared library `LibraryC`, a regex that matches all paths except those starting with `ProjectA` or `LibraryC` can be used. Either one of the following configs would filter out `ProjectB`.
238+
* Specific match on `/ProjectB/*`:
239+
```yaml
240+
ignore:
241+
paths:
242+
- `^\/ProductB\/.*`
243+
```
244+
* Negative lookahead on anything other than `/ProjectA/*` and `/LibraryC/*`:
245+
```yaml
246+
ignore:
247+
paths:
248+
- `^(?!\/ProductA\/|\/LibraryC\/).*`
249+
```
250+
A commit having changes only in `/ProjectB/*` path would be ignored. A commit having changes in the following paths wouldn't be ignored:
251+
* `/ProductA/*`
252+
* `/LibraryC/*`
253+
* `/ProductA/*` and `/LibraryC/*`
254+
* `/ProductA/*` and `/ProductB/*`
255+
* `/LibraryC/*` and `/ProductB/*`
256+
* `/ProductA/*` and `/ProductB/*` and `/LibraryC/*`
257+
258+
:::
259+
Note: The `ignore.paths` configuration is case-sensitive. This can lead to unexpected behavior on case-insensitive file systems, such as Windows. To ensure consistent matching regardless of case, you can prefix your regular expressions with the case-insensitive flag `(?i)`. For example, `(?i)^docs\/` will match both `docs/` and `Docs/`.
260+
:::
261+
262+
::: {.alert .alert-warning}
263+
A commit is ignored by the `ignore.paths` configuration only if **all paths** changed in that commit match one or more of the specified regular expressions. If a path in a commit does not match any one of the ignore patterns, that commit will be included in version calculations.
264+
:::
265+
228266
### merge-message-formats
229267

230268
Custom merge message formats to enable identification of merge messages that do not

docs/input/docs/workflows/GitFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ branches:
148148
is-main-branch: false
149149
ignore:
150150
sha: []
151+
paths: []
151152
mode: ContinuousDelivery
152153
label: '{BranchName}'
153154
increment: Inherit

docs/input/docs/workflows/GitHubFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ branches:
9797
is-main-branch: false
9898
ignore:
9999
sha: []
100+
paths: []
100101
mode: ContinuousDelivery
101102
label: '{BranchName}'
102103
increment: Inherit

docs/input/docs/workflows/TrunkBased/preview1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ branches:
8282
pre-release-weight: 30000
8383
ignore:
8484
sha: []
85+
paths: []
8586
mode: ContinuousDelivery
8687
label: '{BranchName}'
8788
increment: Inherit

new-cli/GitVersion.Core.Libgit2Sharp/GitVersion.Core.Libgit2Sharp.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
</Compile>
5757
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TagCollection.cs">
5858
<Link>Git\TagCollection.cs</Link>
59+
</Compile>
60+
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TreeChanges.cs">
61+
<Link>Git\TreeChanges.cs</Link>
5962
</Compile>
6063
</ItemGroup>
6164

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ branches:
148148
is-main-branch: false
149149
ignore:
150150
sha: []
151+
paths: []
151152
mode: ContinuousDelivery
152153
label: '{BranchName}'
153154
increment: Inherit

src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ branches:
148148
is-main-branch: false
149149
ignore:
150150
sha: []
151+
paths: []
151152
mode: ContinuousDelivery
152153
label: '{BranchName}'
153154
increment: Inherit

src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ branches:
9797
is-main-branch: false
9898
ignore:
9999
sha: []
100+
paths: []
100101
mode: ContinuousDelivery
101102
label: '{BranchName}'
102103
increment: Inherit

src/GitVersion.Configuration.Tests/Workflows/approved/TrunkBased/preview1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ branches:
8282
pre-release-weight: 30000
8383
ignore:
8484
sha: []
85+
paths: []
8586
mode: ContinuousDelivery
8687
label: '{BranchName}'
8788
increment: Inherit

0 commit comments

Comments
 (0)