GitVersion: System.InvalidOperationException - ignore commits-before in GitVersion.yml
There are multiple folders in our repository with separate release cadence and different versions.
Adding a new folder, we would like it versioned starting from 0.0.0 hence we want it not to count the commits before the date it got added. The GitVersion.yml looks as below:
assembly-versioning-scheme: None
mode: Mainline
next-version: 0.0.0
branches: {}
ignore:
commits-before: '2020-02-17T13:57:12'
increment: Inherit
commit-message-incrementing: MergeMessageOnly
Running gitversion.exe or dotnet-gitversion.exe in the folder throws an exception:
An unexpected error occurred:
System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.Aggregate[TSource](IEnumerable`1 source, Func`3 func)
at GitVersion.VersionCalculation.BaseVersionCalculator.GetBaseVersion(GitVersionContext context)
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context)
at GitVersion.GitVersionFinder.FindVersion(GitVersionContext context)
at GitVersion.GitVersionCalculator.<>c__DisplayClass14_0.<ExecuteInternal>b__0(IRepository repo)
at GitVersion.Extensions.LibGitExtensions.WithRepository[TResult](String dotGitDirectory, Func`2 action)
at GitVersion.GitVersionCalculator.ExecuteInternal(String targetBranch, String commitId, Config overrideConfig)
at GitVersion.GitVersionCalculator.GetCachedGitVersionInfo(String targetBranch, String commitId, Config overrideConfig, Boolean noCache)
at GitVersion.GitVersionCalculator.CalculateVersionVariables()
at GitVersion.ExecCommand.Execute()
at GitVersion.GitVersionExecutor.VerifyArgumentsAndRun(Arguments arguments)
It seems to works without the section below to get a version.
ignore:
commits-before: '2020-02-17T13:57:12'
But it gets 2.0.235 or so which is not how we want the contents of that folder versioned.
Versions tried with: gitversion /version 5.1.3+Branch.master.Sha.bef8ebc0b62b3ddd0cdafe09b66d68bbfcaf90d5 dotnet-gitversion.exe /version 5.1.3+Branch.master.Sha.bef8ebc0b62b3ddd0cdafe09b66d68bbfcaf90d5
Also tried with: dotnet-gitversion.exe /version 5.1.4-beta.1+172.Branch.master.Sha.c602fbb304b8f39aecb39656f921c5898414283d
Are we doing something wrong? Can anyone guide us please.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (16 by maintainers)
Commits related to this issue
- Clarify ignore config to resolve #2122 — committed to asbjornu/GitVersion by asbjornu 3 years ago
Well played @asbjornu 😆
Will see what I can do. Bit busy so cannot promise anytime soon. If nobody picks this up will look to revisit. Thanks
Definitely better documentation would help better understanding how this feature works.
I think this can be argued one way or another. I don’t know the intention behind the original design, but I think it’s reasonable that only version sources are ignored and not all commits for counting.
In other words;
IgnoreConfig.Before
ignores themajor.minor.patch
part that any commits before the given date may affect, but not whatever information those same commits may contribute to the build metadata. I think that’s fine, but it should probably be documented (better).@DamianKedzior, #2300 is now merged.
@asbjornu I am aware of #2300 and I am happy to see it coming. I will keep my modifications to minimum in Configuration classes, so far I think I have only 2 lines addition. If #2300 will be merged than I will just back-merge and refactor the code. I think I will get back to work on this issue on the weekend.
This flexibility stems more from the ability to have
GitVersion.yml
placed anywhere in the repository (or even somewhere else) than to support Monorepo. When you configureignore: commits-before: '2020-02-17T13:57:12'
, you will exclude a lot of commits that may be important for GitVersion to find a proper version source for a given commit. GitVersion failing withSequence contains no elements
tells you just that: It couldn’t find any elements (commits) in a code path required to calculate a version number.Now, I think it should be possible for GitVersion to ignore this exact exception and continue with a fallback strategy and only fail if no strategies yields a version number. So if you are able to figure out how to untie that knot in the codebase, we would warmly welcome a PR. 😃 🙏