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

[Bug] Object reference not set to an instance of an object during versioning solving #2967

Closed
rafek1241 opened this issue Jan 18, 2022 · 12 comments · Fixed by #3018
Closed
Labels
Milestone

Comments

@rafek1241
Copy link

Describe the bug
Branch version solving does not works

Expected Behavior

Correct composition of current version

Actual Behavior

System.NullReferenceException: Object reference not set to an instance of an object.
   at GitVersion.GitObject..ctor(GitObject innerGitObject) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\GitObject.cs:line 12
   at GitVersion.Commit..ctor(Commit innerCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 12
   at GitVersion.GitRepository.<>c__DisplayClass27_0.<FindMergeBase>b__0() in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs:line 61
   at Polly.Policy`1.<>c__DisplayClass11_0.<Execute>b__0(Context ctx, CancellationToken ct)
   at Polly.Retry.RetryEngine.Implementation[TResult](Func`3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates`1 shouldRetryResultPredicates, Action`4 onRetry, Int32 permittedRetryCount, IEnumerable`1 sleepDurationsEnumerable, Func`4 sleepDurationProvider)
   at Polly.Retry.RetryPolicy`1.Implementation(Func`3 action, Context context, CancellationToken cancellationToken)
   at Polly.Policy`1.Execute(Func`3 action, Context context, CancellationToken cancellationToken)
   at Polly.Policy`1.Execute(Func`1 action)
   at GitVersion.Helpers.RetryAction`2.Execute(Func`1 operation) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Helpers\RetryAction.cs:line 35
   at GitVersion.GitRepository.FindMergeBase(ICommit commit, ICommit otherCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs:line 59
   at GitVersion.RepositoryStore.FindMergeBase(IBranch branch, IBranch otherBranch) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\RepositoryStore.cs:line 49
   at GitVersion.RepositoryStore.<>c__DisplayClass30_0.<GetMergeCommitsForBranch>b__2(IBranch otherBranch) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\RepositoryStore.cs:line 454
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.OrderedEnumerable`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at GitVersion.RepositoryStore.GetMergeCommitsForBranch(IBranch branch, Config configuration, IEnumerable`1 excludedBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\RepositoryStore.cs:line 438
   at GitVersion.RepositoryStore.FindCommitBranchWasBranchedFrom(IBranch branch, Config configuration, IBranch[] excludedBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\RepositoryStore.cs:line 320
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches)
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 44
   at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 39
   at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 37
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 51
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
  INFO [01/18/22 15:50:05:06] Attempting to show the current git graph (please include in issue):
  INFO [01/18/22 15:50:05:06] Showing max of 100 commits
  INFO [01/18/22 15:50:05:13] * 0e9c7d4 49 minutes ago  (HEAD -> feature/XXX, tag: 1.0.0, origin/feature/XXX)

Steps to Reproduce

I used command line execution in my project directory:

dotnet.exe C:\Users\Admin\.nuget\packages\gitversion.tool\5.8.1\tools\net6.0\any\gitversion.dll /nocache

I tried as well with:

dotnet.exe C:\Users\Admin\.nuget\packages\gitversion.tool\5.8.1\tools\netcoreapp3.1\any\gitversion.dll /nocache
dotnet.exe C:\Users\Admin\.nuget\packages\gitversion.tool\5.8.1\tools\net5.0\any\gitversion.dll /nocache
dotnet.exe C:\Users\Admin\.nuget\packages\gitversion.tool\5.6.7\tools\net5.0\any\gitversion.dll /nocache

Your Environment

project that runs .net core 3.1

  • Version Used:
  • Operating System and version (Windows 10, Ubuntu 18.04): windows 10
  • Link to your project: -
  • Link to your CI build (if appropriate): -

Branch structure in my repository:

Rider:
image

@rafek1241 rafek1241 added the bug label Jan 18, 2022
@rafek1241 rafek1241 changed the title [Bug] [Bug] Object reference not set to an instance of an object during versioning solving Jan 18, 2022
@rafek1241
Copy link
Author

Okay, rebase to master fixed the issue but it could be great to have such custom exception here to be more described.

@asbjornu
Copy link
Member

If you are able to provide a public repository that reproduces this problem, it should be easy to fix. We don't want NullReferenceException to be thrown anywhere, as I completely agree they are obscure and unhelpful.

@rafek1241
Copy link
Author

@asbjornu
It was my work repository. I will try to prepare some reproduction repository soon.

@rafek1241
Copy link
Author

@asbjornu
Repository that reproduces the issue: https://github.com/rafek1241/gitversion-issue-2967-reproduction

@rafek1241 rafek1241 reopened this Jan 19, 2022
@davidkeaveny
Copy link
Contributor

I'm getting this issue with a private repo, so can help validate a fix if needed.

@asbjornu
Copy link
Member

asbjornu commented Feb 4, 2022

@davidkeaveny, can you please clone or fork GitVersion locally and run it against your repository to get a line numbered stack trace? If you're adventurous, it would be awesome if you found the source of the NRE and fixed it too.

@asbjornu
Copy link
Member

I think I've managed to find the source of the issue you're experiencing, @rafek1241. As I'm not using Mainline myself, I'm not sure why this code is exactly as it is, but this line in RepositoryStore.GetMainlineBranches() is excluding all branches that don't have a MergeBase:

.Where(a => a.MergeBase != null)

And for the reproduction repository you've provided, no branches have a MergeBase, causing the returned list to become empty. What's worrying is that while commenting that line out still fails on your repository, it fails no tests. So our test coverage on Mainline is obviously not great. 😬

What I think could work here is for Mainline to defer to BaseVersionCalculator if it's unable to find a suitable Mainline branch.

asbjornu added a commit to asbjornu/GitVersion that referenced this issue Feb 26, 2022
@asbjornu
Copy link
Member

I think I've solved this in #3018. I still need to add a test and it should be good to go. I'm not yet confident that I'm able to reproduce the problem in a test, though.

asbjornu added a commit to asbjornu/GitVersion that referenced this issue Feb 26, 2022
asbjornu added a commit to asbjornu/GitVersion that referenced this issue Feb 26, 2022
Add test for GitToolsGH-2967. Unfortunately, it does not reproduce the
`NullReferenceException`, but it may be useful as a regression test in
the future. ¯\_(ツ)_/¯
arturcic added a commit that referenced this issue Feb 26, 2022
@asbjornu asbjornu added this to the 5.x milestone Feb 28, 2022
@arturcic arturcic modified the milestones: 5.x, 5.8.3 Mar 5, 2022
@github-actions
Copy link

github-actions bot commented Mar 5, 2022

🎉 This issue has been resolved in version 5.8.3 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

@0000day
Copy link

0000day commented Jul 17, 2024

This just happend to me again.
A rebase had no impact.
I'm on a feature-branch that has been squashed down to 1 commit.

System.NullReferenceException: Object reference not set to an instance of an object.
   at LibGit2Sharp.Core.Handles.ObjectHandle.op_Implicit(ObjectHandle handle) in /_/LibGit2Sharp/Core/Handles/Objects.cs:line 509
   at LibGit2Sharp.Core.Proxy.git_commit_author(ObjectHandle obj) in /_/LibGit2Sharp/Core/Proxy.cs:line 289
   at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.LibGit2Sharp.Core.LazyGroup<T>.IEvaluator<TInput>.Evaluate(TInput input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 88
   at LibGit2Sharp.Core.LazyGroup`1.<Evaluate>b__6_0(T input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 36
   at LibGit2Sharp.Core.GitObjectLazyGroup.EvaluateInternal(Action`1 evaluator) in /_/LibGit2Sharp/Core/GitObjectLazyGroup.cs:line 20
   at LibGit2Sharp.Core.LazyGroup`1.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 34
   at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 80
   at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.get_Value() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 73
   at LibGit2Sharp.Commit.get_Committer() in /_/LibGit2Sharp/Commit.cs:line 87
   at GitVersion.Commit..ctor(Commit innerCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 17
   at GitVersion.Commit.<>c.<.ctor>b__3_0(Commit parent) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 16
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 77
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 28
   at GitVersion.VersionCalculation.BaseVersionCalculator.GetBaseVersion()
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 56
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line [52](_gitlab_url_masked_/-/jobs/4983096#L52)
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
  INFO [07/17/24 9:05:56:63] Attempting to show the current git graph (please include in issue): 
  INFO [07/17/24 9:05:56:63] Showing max of 100 commits
  ....

It has been executed on a gitlab-runner.
Will get another machine to test just to be sure the issue is not local.

I'm on 5.12.0

@arturcic
Copy link
Member

@0000day try the latest beta

@0000day
Copy link

0000day commented Jul 18, 2024

Latest beta had too many changes for me. Investigated it on v5.12.0.
The issue was that we moved over to Gitlab. Looks like gitlab is doing a shallow-copy of the repository.

before_script:
  - git fetch --unshallow --all

This fixed it for me, maybe it's a help for others.

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

Successfully merging a pull request may close this issue.

5 participants