Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE]: NotImplementedException in TrunkBased-Workflow #4056

Open
2 tasks done
steven-r opened this issue Jun 7, 2024 · 11 comments
Open
2 tasks done

[ISSUE]: NotImplementedException in TrunkBased-Workflow #4056

steven-r opened this issue Jun 7, 2024 · 11 comments

Comments

@steven-r
Copy link

steven-r commented Jun 7, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

GitVersion.Tool

GitVersion version

6.0.0-rc1

Operating system

Linux, Windows

What are you seeing?

When running gitversion on my git repos, I receive a NotImplementedException.

I was using Mainline for the past and I'm trying out the 6.0-RC1 release now.

What is expected?

A valid version description.

Steps to Reproduce

use my repos (it's private, sorry), with the following configuration:

workflow: TrunkBased/v1
patch-version-bump-message: "^(text|fix|perf|refactor|revert|style|test)(\\([\\w\\s-]*\\))?:"

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

INFO [24-06-07 22:24:08:77] Applicable build agent found: 'LocalBuild'.
INFO [24-06-07 22:24:08:83] Working directory: /home/sreindl/src/mybook
INFO [24-06-07 22:24:08:83] Project root is: /home/sreindl/src/mybook/
INFO [24-06-07 22:24:08:83] DotGit directory is: /home/sreindl/src/mybook/.git
INFO [24-06-07 22:24:08:83] Branch from build environment:
INFO [24-06-07 22:24:08:84] Found configuration file at '/home/sreindl/src/mybook/GitVersion.yml'
INFO [24-06-07 22:24:08:86] -< Begin: Loading version variables from disk cache file /home/sreindl/src/mybook/.git/gitversion_cache/2E0243312D3E3098EEE3D1F4458494769E1ACE06 >-
  INFO [24-06-07 22:24:08:86] Cache file /home/sreindl/src/mybook/.git/gitversion_cache/2E0243312D3E3098EEE3D1F4458494769E1ACE06 not found.
INFO [24-06-07 22:24:08:86] -< End: Loading version variables from disk cache file /home/sreindl/src/mybook/.git/gitversion_cache/2E0243312D3E3098EEE3D1F4458494769E1ACE06 (Took: 0.51ms) >-
INFO [24-06-07 22:24:08:86] Found configuration file at '/home/sreindl/src/mybook/GitVersion.yml'
INFO [24-06-07 22:24:09:01] Using latest commit on specified branch
INFO [24-06-07 22:24:09:03] Getting tagged semantic versions. TagPrefix: [vV]? and Format: Strict
INFO [24-06-07 22:24:09:09] Running against branch: main ('16af603' - Merge pull request #250 from steven-r/dependabot/npm_and_yarn/prettier-3.3.0)
INFO [24-06-07 22:24:09:09] -< Begin: Fetching the base versions for version calculation... >-
  INFO [24-06-07 22:24:09:09] Calculating base versions for 'main'
  INFO [24-06-07 22:24:09:09] -< Begin: [Using 'ConfiguredNextVersionVersionStrategy' strategy] >-
  INFO [24-06-07 22:24:09:09] -< End: [Using 'ConfiguredNextVersionVersionStrategy' strategy] (Took: 0.51ms) >-
  INFO [24-06-07 22:24:09:09] -< Begin: [Using 'MainlineVersionStrategy' strategy] >-
    INFO [24-06-07 22:24:09:10] -< Begin: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]? and Format: Strict >-
    INFO [24-06-07 22:24:09:12] -< End: Getting tagged semantic versions on branch 'refs/heads/main'. TagPrefix: [vV]? and Format: Strict (Took: 15.81ms) >-
INFO [24-06-07 22:24:09:14] -< Begin: Finding branches source of 'main' >-
    INFO [24-06-07 22:24:09:14] -< End: Finding branches source of 'main' (Took: 5.23ms) >-
  INFO [24-06-07 22:24:09:77] -< End: [Using 'MainlineVersionStrategy' strategy] (Took: 673.15ms) >-
INFO [24-06-07 22:24:09:77] -< End: Fetching the base versions for version calculation... (Took: 676.90ms) >-
ERROR [24-06-07 22:24:09:78] An unexpected error occurred:
System.NotImplementedException: The method or operation is not implemented.
   at GitVersion.VersionCalculation.MainlineVersionStrategy.IterateOverCommitsRecursive(IEnumerable`1 commitsInReverseOrder, MainlineIteration iteration, IBranch targetBranch, String targetLabel, ILookup`2 taggedSemanticVersions, HashSet`1 traversedCommits) in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 242
 at GitVersion.VersionCalculation.MainlineVersionStrategy.GetBaseVersions(EffectiveBranchConfiguration configuration)+MoveNext() in /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs:line 105
   at GitVersion.VersionCalculation.NextVersionCalculator.<>c__DisplayClass14_0.<<GetNextVersions>g__GetNextVersionsInternal|0>d.MoveNext() in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 264
   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 239
   at GitVersion.VersionCalculation.NextVersionCalculator.CalculateNextVersion(IBranch branch, IGitVersionConfiguration configuration) in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 158
   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 62
INFO [24-06-07 22:24:09:78] Attempting to show the current git graph (please include in issue):
INFO [24-06-07 22:24:09:78] Showing max of 100 commits
INFO [24-06-07 22:24:09:81] *   16af603 4 days ago  (HEAD -> main, origin/main, origin/HEAD)
|\
| * c78e95a 4 days ago
* |   b059dc8 4 days ago
|\ \
| |/
|/|
| * d647992 4 days ago  (origin/dependabot/pip/tools/watchdog-4.0.1)
* |   138cd6e 4 days ago
|\ \
| * | b5fd3e3 4 days ago
* | |   f2133e2 4 days ago
|\ \ \
| * | | c85b925 4 days ago
| |/ /
* | |   d941621 4 days ago
|\ \ \
| |/ /
|/| |
| * | a806d1a 4 days ago  (origin/dependabot/pip/tools/python-dateutil-2.9.0.post0)
| |/
* |   a7eb2de 4 days ago
|\ \
| * | cab75cb 4 days ago
|/ /
* |   f7ab2bc 4 days ago
|\ \
| * | fe6dd26 4 days ago  (origin/dependabot/npm_and_yarn/semantic-release-24.0.0)
| |/
* |   379206f 4 days ago
|\ \
| * | 32ef5c1 4 days ago  (origin/dependabot/pip/tools/textual-0.64.0)
| |/
* | 4cbde78 4 days ago
* | 313c6a6 4 days ago
* | 8eedad5 4 days ago
* | 2b788e3 4 days ago
* | 1d16749 4 days ago
* | f8c9588 4 days ago
* | b675960 4 days ago
* | ad68f4c 5 days ago
|/
| * e924596 4 days ago  (origin/dependabot/pip/tools/sphinx-design-0.6.0)
|/
| * 11ea42c 4 days ago  (origin/dependabot/npm_and_yarn/typescript-5.4.5)
|/
| * 11785ed 4 days ago  (origin/dependabot/npm_and_yarn/prettier-3.3.0)
|/
| * c523a3e 4 days ago  (origin/dependabot/npm_and_yarn/conventional-changelog-conventionalcommits-8.0.0)
|/
* 095d235 5 days ago
* 1822eee 5 days ago
* 159b2de 5 days ago
* c467070 5 days ago
* 1c4511a 6 days ago
* b7d5a6e 6 days ago
* 54b0852 6 days ago
* 23db9fe 6 days ago
* e2127f2 6 days ago
* 3eafa11 6 days ago
* 1ad7fff 6 days ago
* 0413fe7 6 days ago
* be3e0b1 8 days ago
*   cc15698 8 days ago
*   cc15698 8 days ago
|\
| * d45724f 8 days ago
|/
*   c4ed833 8 days ago
|\
| * caba933 8 days ago
|/
*   bc10604 8 days ago
|\
| * d354534 4 months ago  (origin/dependabot/npm_and_yarn/prettier-3.2.5)
* |   33783ca 8 days ago
|\ \
| * | d192163 4 months ago  (origin/dependabot/npm_and_yarn/ip-2.0.1)
| |/
* |   b1d0618 8 days ago
|\ \
| * | 25098ac 8 days ago
* | |   a73a888 8 days ago
|\ \ \
| |/ /
|/| |
| * | 76d3474 8 days ago
* | |   33f72ce 8 days ago
|\ \ \
| |/ /
|/| |
| * | fb3290c 8 days ago
|/ /
* | dc2eb0b 12 days ago
* | dc229a8 12 days ago
* | 6bcd747 12 days ago
* | 882c286 12 days ago
* | 2a12144 12 days ago
* | 530eb9d 2 weeks ago
* | 2f8b873 2 weeks ago
* | 425c70b 2 weeks ago
|/
| * c6601dc 10 weeks ago  (origin/dependabot/pip/tools/textual-0.55.0)
|/
| * 481f0fb 2 months ago  (origin/dependabot/npm_and_yarn/semantic-release-23.0.6)
|/
| * bee859f 2 months ago  (origin/dependabot/pip/tools/urwid-2.6.10)
|/
| * 783d5f4 3 months ago  (origin/dependabot/pip/tools/setuptools-69.2.0)
|/
| * a868f1e 3 months ago  (origin/dependabot/pip/tools/pandas-2.2.1)
|/
| * 407aec3 3 months ago  (origin/dependabot/npm_and_yarn/eslint-8.57.0)
|/
| * 6a92988 4 months ago  (origin/dependabot/npm_and_yarn/markdownlint-cli-0.39.0)
|/
| * 9fdb4b2 5 months ago  (origin/dependabot/pip/tools/jinja2-3.1.3)
|/
| * a333d63 5 months ago  (origin/dependabot/pip/tools/humanize-4.9.0)
|/
*   d90c696 5 months ago
|\
| * 3a5505d 5 months ago
|/
*   0540c52 5 months ago
|\
| * 440e8f6 5 months ago
* |   1f401cb 5 months ago
|\ \
| |/
|/|
| * 83779f0 5 months ago
|/
*   5271152 5 months ago
|\
| * 97a7f28 5 months ago
|/
*   6be3236 5 months ago
|\
| * 907fe08 6 months ago
* |   be2f03c 5 months ago
|\ \
| * | e1f6ab0 6 months ago
| |/
* |   860a2b5 5 months ago
|\ \
| * | 205ad0d 6 months ago
| |/
* |   4a5116c 5 months ago
|\ \
| * | 57760c5 7 months ago
| |/
* |   9484cc8 5 months ago
|\ \
| * | 7e3cf6d 7 months ago
| |/
* |   ed7e81a 5 months ago
|\ \
| * | dcfd8e3 6 months ago
| |/
* |   22e49e4 5 months ago
|\ \
| |/
|/|
| * 6234f1d 5 months ago
|/
*   b2d7db0 7 months ago
|\
| *   e35f3a7 7 months ago
| |\
| | * 3d790ff 7 months ago
| * |   b65376f 7 months ago
| |\ \
| | * | fb30953 8 months ago
| | |/
| * |   dde8119 7 months ago
| |\ \
@HHobeck
Copy link
Contributor

HHobeck commented Jun 8, 2024

Please analyze this issue in more detail and simplify your scenario. In advance provide:

  • git commands and/or
  • an integration test

to reproduce this issue.

Please notice: The NotImplementedException indecates that multiple is-main-branch: true branches have been used with the Mainline version strategy. In version 6.x this is not supported and will be probably implemented in version 7.x:

@brendankowitz
Copy link

When upgrading to 6 I've noticed the same stacktrace from the build server on merge commits, just trying to understand what the right config should be here...
It looks like the solution is to either turn off "is-main-branch" (which seems to give the wrong version) or turn off "track-merge-message" to prevent that codepath in the merge build.

if (item.IsMergeCommit())
{
Lazy<IReadOnlyCollection<ICommit>> mergedCommitsInReverseOrderLazy = new(
() => incrementStrategyFinder.GetMergedCommits(item, 1, Context.Configuration.Ignore).Reverse().ToList()
);
if ((configuration.TrackMergeMessage ?? Context.Configuration.TrackMergeMessage) == true
&& MergeMessage.TryParse(item, Context.Configuration, out var mergeMessage))
{
if (mergeMessage.MergedBranch is not null)
{
var childConfiguration = Context.Configuration.GetBranchConfiguration(mergeMessage.MergedBranch);
var childBranchName = mergeMessage.MergedBranch;
if (childConfiguration.IsMainBranch == true)
{
if (configuration.IsMainBranch == true) throw new NotImplementedException();

@peterbomers
Copy link
Contributor

I think this occurs when there is a merge message on te main branch.
The childConfiguration is the same as the current configuration and the exception is thrown.

@daghsentinel
Copy link

Tip: I removed regex: main from the main branch definition in GitVersion.yml and this error went away.

@steven-r
Copy link
Author

After some digging, cloing the sources and add debug information I can confirm that these are merge requests towards Main coming from PRs. What fixed he problem was to add the malicious merges to the ignore list.

Anyhow, this git "tree" was a result out of working git operations.
Instead of throwing an error/exception, gitversion should ignore those merges to behave like 5.x

@asbjornu
Copy link
Member

asbjornu commented Sep 3, 2024

@steven-r, sure. If you can figure out a way to ignore such commits without breaking any existing tests, we would be happy to accept a pull request.

@HHobeck
Copy link
Contributor

HHobeck commented Sep 3, 2024

@steven-r Can you please create a minimal example or somehow a visual representation to have a basis for the discussion? Would be very good.

Actually I'm not sure if a merge commit from main is generally a good idea in the TrunkBased workflow. Anyway ignoring the commit is not what I would expect. I would expect at least that it will be handled like a normal commit. What do you think?

@thomhurst
Copy link

I've just managed to replicate it.

  • I pull main
  • Someone else commits and pushes to main
  • I commit and push to main, but don't have the latest now
  • Git merges latest for me and makes a commit with a message "[Merge remote-tracking branch 'origin/main']
  • GitVersion now fails with exception

Git Log output:

*   b4587d0 2 minutes ago  (HEAD -> main, origin/main, origin/HEAD)
|\
| * d8d918b 3 minutes ago
* | b69156a 2 minutes ago
|/
* c6c2e05 5 minutes ago
* 47c20f6 2 days ago
* df3ed2f 2 days ago
* 794b50f 2 days ago

Repository you can test with:
https://github.com/thomhurst/GitVersionExceptionRepro

@steven-r
Copy link
Author

steven-r commented Sep 5, 2024

My real use case is a list of dependabot updates on main where there's no rebase in between (as it is not needed in all cases).

I've just managed to replicate it.

  • I pull main
  • Someone else commits and pushes to main
  • I commit and push to main, but don't have the latest now
  • Git merges latest for me and makes a commit with a message "[Merge remote-tracking branch 'origin/main']
  • GitVersion now fails with exception

@thomhurst
Copy link

thomhurst commented Sep 6, 2024

My real use case is a list of dependabot updates on main where there's no rebase in between (as it is not needed in all cases).

Yep this exact scenario has just broken my repository. Arghhhhhh

@thomhurst
Copy link

I've tried ignoring those commits and now I'm getting a brand new error:

INFO [24-09-06 16:46:10:80] -< End: Fetching the base versions for version 
  calculation... (Took: 7,416.53ms) >-
  ERROR [24-09-06 16:46:10:81] An unexpected error occurred:
  System.ArgumentOutOfRangeException: Exception of type 
  'System.ArgumentOutOfRangeException' was thrown. (Parameter 'strategy')
  Actual value was Inherit.
     at 
  GitVersion.Extensions.IncrementStrategyExtensions.ToVersionField(IncrementStrate
  gy 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(MainlineIter
  ation iteration, String targetLabel, IIncrementStrategyFinder 
  incrementStrategyFinder, IGitVersionConfiguration configuration)+MoveNext() in 
  /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersio
  nStrategy.cs:line 367
     at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 
  items)
     at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 
  source)
     at 
  GitVersion.VersionCalculation.MainlineVersionStrategy.DetermineBaseVersionRecurs
  ive(MainlineIteration iteration, String targetLabel, IIncrementStrategyFinder 
  incrementStrategyFinder, IGitVersionConfiguration configuration) in 
  /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersio
  nStrategy.cs:line 335
     at 
  GitVersion.VersionCalculation.MainlineVersionStrategy.DetermineBaseVersion(Mainl
  ineIteration iteration, String targetLabel, IIncrementStrategyFinder 
  incrementStrategyFinder, IGitVersionConfiguration configuration) in 
  /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersio
  nStrategy.cs:line 328
     at 
  GitVersion.VersionCalculation.MainlineVersionStrategy.GetBaseVersions(EffectiveB
  ranchConfiguration configuration)+MoveNext() in 
  /_/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersio
  nStrategy.cs:line 113
     at 
  GitVersion.VersionCalculation.NextVersionCalculator.<>c__DisplayClass14_0.<<GetN
  extVersions>g__GetNextVersionsInternal|0>d.MoveNext() in 
  /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculat
  or.cs:line 264
     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/NextVersionCalculat
  or.cs:line 239
     at 
  GitVersion.VersionCalculation.NextVersionCalculator.CalculateNextVersion(IBranch
  branch, IGitVersionConfiguration configuration) in 
  /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculat
  or.cs:line 158
     at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in 
  /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculat
  or.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 66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants