GitVersion
GitVersion copied to clipboard
[ISSUE]: System.ArgumentOutOfRangeException when IncrementStrategy is Inherit
Prerequisites
- [x] I have written a descriptive issue title
- [x] I have searched issues to ensure it has not already been reported
GitVersion package
GitVersion.Tool
GitVersion version
6.3.0
Operating system
N/A
What are you seeing?
Sometimes, pull request builds fail for GitVersion with the following exception:
System.ArgumentOutOfRangeException: Exception of type 'System.ArgumentOutOfRangeException' was thrown. (Parameter 'strategy')
Actual value was Inherit.
What is expected?
GetEffectiveConfiguration should keep looking for a parent branch configuration as long as the IncrementStrategy of the branch is Inherit.
https://github.com/GitTools/GitVersion/blob/main/src/GitVersion.Core/Extensions/ConfigurationExtensions.cs#L19-L29 #
Steps to Reproduce
I think it happens when we merge one feature branch into another feature branch.
RepositoryFixture Test
No response
Output log or link to your CI build (if appropriate).
INFO [25-05-23 6:16:20:45] -< Begin: Finding branches source of 'master' >-
INFO [25-05-23 6:16:20:45] -< End: Finding branches source of 'master' (Took: 0.96ms) >-
INFO [25-05-23 6:16:20:45] -< End: [Using 'MainlineVersionStrategy' strategy] (Took: 3,545.25ms) >-
INFO [25-05-23 6:16:20:45] -< End: Calculating base versions for 'master' (Took: 3,546.38ms) >-
INFO [25-05-23 6:16:20:45] -< End: Fetching the base versions for version calculation... (Took: 12,454.67ms) >-
ERROR [25-05-23 6:16:20:61] An unexpected error occurred:
System.ArgumentOutOfRangeException: Exception of type 'System.ArgumentOutOfRangeException' was thrown. (Parameter 'strategy')
Actual value was Inherit.
at GitVersion.Extensions.IncrementStrategyExtensions.ToVersionField(IncrementStrategy strategy) in /_/src/GitVersion.Core/Extensions/IncrementStrategyExtensions.cs:line 11
at GitVersion.VersionCalculation.Mainline.EnrichIncrement.Enrich(MainlineIteration iteration, MainlineCommit commit, MainlineContext context) in /_/src/GitVersion.Core/VersionCalculation/Mainline/EnrichIncrement.cs:line 13
at GitVersion.VersionCalculation.MainlineVersionStrategy.GetIncrements(MainlineIteration iteration, String targetLabel, IIncrementStrategyFinder incrementStrategyFinder, IGitVersionConfiguration configuration)+MoveNext() in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 360
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at GitVersion.VersionCalculation.MainlineVersionStrategy.DetermineBaseVersionRecursive(MainlineIteration iteration, String targetLabel, IIncrementStrategyFinder incrementStrategyFinder, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 328
at GitVersion.VersionCalculation.MainlineVersionStrategy.DetermineBaseVersion(MainlineIteration iteration, String targetLabel, IIncrementStrategyFinder incrementStrategyFinder, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 321
at GitVersion.VersionCalculation.MainlineVersionStrategy.GetBaseVersions(EffectiveBranchConfiguration configuration)+MoveNext() in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 113
at GitVersion.VersionCalculation.NextVersionCalculator.<>c__DisplayClass14_0.<<GetNextVersions>g__GetNextVersionsInternal|0>d.MoveNext() in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 262
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at GitVersion.VersionCalculation.NextVersionCalculator.GetNextVersions(IBranch branch, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 237
at GitVersion.VersionCalculation.NextVersionCalculator.CalculateNextVersion(IBranch branch, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 156
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 53
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /_/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 45
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /_/src/GitVersion.App/GitVersionExecutor.cs:line 69
INFO [25-05-23 6:16:20:61] Please run `git log --graph --format="%h %cr %d" --decorate --date=relative --all --remotes=*` to see the git graph. This can help you troubleshoot any issues.
Can you write an integration test like:
https://github.com/GitTools/GitVersion/blob/80c8b6c85cd0980c1469849bec6b658bd2b5a3dd/src/GitVersion.Core.Tests/VersionCalculation/NextVersionCalculatorTests.cs#L183-L190
Generally, in some situation it is not possible to determine the parent branch (for the Mainline version strategy). From the algorithm point of view it is not solvable. Are you using the TrunkBased/preview1 workflow? If yes this error should not happen. If no your configuration might be wrong.
Reproduced with v6.3.0 and workflow=TrunkBased/preview1. Same symptom on v6.2, v6.1 and v6.0.
Only happens in (ADO) PR merge branch, not source branch.
Azure pipeline task reports ##[error]GitVersion output is not valid JSON and fails. I had to checkout PR branch locally and run GitVersion in terminal to see error.
Our (temporary) solution was to downgrade to v5 and switch to mode=Mainline.
Reproduced with v6.3.0 and
workflow=TrunkBased/preview1. Same symptom on v6.2, v6.1 and v6.0.Only happens in (ADO) PR merge branch, not source branch.
Azure pipeline task reports
##[error]GitVersion output is not valid JSONand fails. I had to checkout PR branch locally and run GitVersion in terminal to see error.Our (temporary) solution was to downgrade to v5 and switch to
mode=Mainline.
How it might be possible to analyze your issue and find a solution if you don’t even provide a sample repository or steps to reproduce?
I believe we are seeing something similar. Originally happened in remote gitlab pipeline (we assume, all we see there is the error code), but it is reproduce-able locally on the same branch.
Previous to this, we noticed that version was no longer being calculated (with no other changes to gitversion or its config, it just suddenly stopped working, with version being pinned to the last tag instead), but we hadn't had time to research that yet. I suspect this might be same issue.
~We were able to resolve by applying a newer version tag to recent commit. It's as if gitversion is only able to go back so far in history for calculating version before the crash below happens. If it finds an explicit version tag before that point, it is okay.~ UPDATE: This actually did not work, or at least not reliably. I understand a reproduceable example is being requested and rightfully so. However, we do not know what is suddenly causing this issue. The stacktrace for gitversion is not overly helpful here. We are currently at a loss for how to debug or try creating a reproducible example.
We are currently using gitversion via docker (gittools/gitversion:6.2.0-alpine.3.20-9.0) and locally, cli version 6.3.0. Let us know if there's any other info we can provide, however, the repo is proprietary.
GitVersion.yml
workflow: TrunkBased/preview1
strategies:
- Mainline
# Branch-specific configuration
branches:
main:
increment: Patch
label: null
regex: ^main$
is-main-branch: true
is-release-branch: true
pre-release-weight: 0
feature:
regex: ^(?!main$)(?<BranchName>.+)$
increment: Inherit
label: "{BranchName}"
Error
ERROR [25-06-04 14:10:53:91] An unexpected error occurred:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'strategy')
Actual value was Inherit.
at GitVersion.Extensions.IncrementStrategyExtensions.ToVersionField(IncrementStrategy strategy) in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/Extensions/IncrementStrategyExtensions.cs:line 11
at GitVersion.VersionCalculation.Mainline.EnrichIncrement.Enrich(MainlineIteration iteration, MainlineCommit commit, MainlineContext context) in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/Mainline/EnrichIncrement.cs:line 13
at GitVersion.VersionCalculation.MainlineVersionStrategy.GetIncrements(MainlineIteration iteration, String targetLabel, IIncrementStrategyFinder incrementStrategyFinder, IGitVersionConfiguration configuration)+MoveNext() in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 360
at System.Linq.Enumerable.<ToArray>g__EnumerableToArray|314_0[TSource](IEnumerable`1 source)
at GitVersion.VersionCalculation.MainlineVersionStrategy.DetermineBaseVersionRecursive(MainlineIteration iteration, String targetLabel, IIncrementStrategyFinder incrementStrategyFinder, IGitVersionConfiguration configuration) in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 328
at GitVersion.VersionCalculation.MainlineVersionStrategy.DetermineBaseVersion(MainlineIteration iteration, String targetLabel, IIncrementStrategyFinder incrementStrategyFinder, IGitVersionConfiguration configuration) in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 321
at GitVersion.VersionCalculation.MainlineVersionStrategy.GetBaseVersions(EffectiveBranchConfiguration configuration)+MoveNext() in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 113
at GitVersion.VersionCalculation.NextVersionCalculator.<>c__DisplayClass14_0.<<GetNextVersions>g__GetNextVersionsInternal|0>d.MoveNext() in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 262
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at GitVersion.VersionCalculation.NextVersionCalculator.GetNextVersions(IBranch branch, IGitVersionConfiguration configuration) in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 237
at GitVersion.VersionCalculation.NextVersionCalculator.CalculateNextVersion(IBranch branch, IGitVersionConfiguration configuration) in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 156
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 53
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 45
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /private/tmp/gitversion-20250425-6160-zvt4c2/GitVersion-6.3.0/src/GitVersion.App/GitVersionExecutor.cs:line 69
INFO [25-06-04 14:10:53:91] Please run `git log --graph --format="%h %cr %d" --decorate --date=relative --all --remotes=*` to see the git graph. This can help you troubleshoot any issues.
We are currently using gitversion via docker (gittools/gitversion:6.2.0-alpine.3.20-9.0) and locally, cli version 6.3.0. Let us know if there's any other info we can provide, however, the repo is proprietary.
The information about how to reproduce this error is still not provided. If you cannot provide the repository then please create a hello world repository or create an integration test or provide simple git commands (I don't care). If you or other community members are not able to do so, I'm going to close this issue.
Thank you for your understanding.
@HHobeck I'm currently on holiday. So keep the bug open for a while to give me some time to create an integration test.
Even if it's a config issue on my side, I can still learn from it.
I closed the issue because I can no longer reproduce it on GitVersion 6.4.0