[Bug] Null Exception
Describe the bug Error: The process '/opt/hostedtoolcache/GitVersion.Tool/5.7.0/x64/dotnet-gitversion' failed with exit code 1
Expected Behavior
output JSON
Actual Behavior
Error: The process '/opt/hostedtoolcache/GitVersion.Tool/5.7.0/x64/dotnet-gitversion' failed with exit code 1
Possible Fix
Steps to Reproduce
Context
I can't use gitversion in my CI/CD
Your Environment
- Version Used: 5.x - latest
- Operating System and version (Windows 10, Ubuntu 18.04): Ubuntu 20.04
- Link to your project:
- Link to your CI build (if appropriate):
ERROR [08/27/21 3:34:09:55] An unexpected error occurred:
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 14
at GitVersion.Commit..ctor(Commit innerCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 15
at GitVersion.GitRepository.<>c__DisplayClass27_0.<FindMergeBase>b__0() in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs:line 64
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 37
at GitVersion.GitRepository.FindMergeBase(ICommit commit, ICommit otherCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs:line 62
at GitVersion.RepositoryStore.FindMergeBase(IBranch branch, IBranch otherBranch) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\RepositoryStore.cs:line 48
at GitVersion.RepositoryStore.<>c__DisplayClass29_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 321
at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 81
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 47
at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionContextFactory.cs:line 40
at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\GitVersionCoreModule.cs:line 38
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 17
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 32
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 70
INFO [08/27/21 3:34:09:55] Attempting to show the current git graph (please include in issue):
INFO [08/27/21 3:34:09:55] Showing max of 100 commits
INFO [08/27/21 3:34:09:61] * e94028f 26 minutes ago (HEAD -> build, origin/master, master)
This will be impossible to debug without access to the repository that is failing. Is it public? If not, are you able to reproduce the problem in a public repository?
This is not a public repository. I have not tried it on any public repository. It fails in the gitlab repository where there is a build branch for the builds.
On Tue, Aug 31, 2021 at 2:55 AM Asbjørn Ulsberg @.***> wrote:
This will be impossible to debug without access to the repository that is failing. Is it public? If not, are you able to reproduce the problem in a public repository?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GitTools/GitVersion/issues/2825#issuecomment-909083603, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNJ2MTASMO25I6LHQLXASDT7SRIRANCNFSM5C4VW5DA .
I had a similar bug also on a private repo I debugged gitversion and the source of the problem seemed to be here a merge base wasn't found so when it tries to construct a new Commit using null it crashes.
I fixed it by passing in some config to make the search for a merge base return successfully. I wonder if the wildcard regex search for a merge base is deterministic across clones of the repo though which is maybe why this happens to some people but not others (looking at some of the other issues that mention similar crashes).
That sounds probable, @jscarrott. Thanks for debugging the issue. If you figure out a workaround, I'd love to merge a pull request fixing this.
@asbjornu If you want to provide me a debug build, then I can run on the repository and provide the logs.
@sanjivpurohit, I don't think we have debug builds readily available. Is it possible for you to fork GitVersion and build it locally yourself? Then you can set breakpoints in the code as well.
I have a public repo where I ran into this bug if you want to check it out.
I am not using any config file. I am using the GitFlow branching style and running the GitVersion action on the master branch works fine, but when I create a feature/branchname branch the GitVersion action is throwing the same error.
See https://github.com/DirtySoc/learn-go-with-tests/runs/4132664940?check_suite_focus=true
Sorry all, looks like my issue was just ignorance. I didn't checkout with a depth of 0.
I have a reproducer on a public repository: https://github.com/Cray-HPE/cray-product-catalog/runs/4230181725?check_suite_focus=true
I should note that I attempted this in our Jenkins pipeline as well, and got the same error. Using gitversion on my mac with the repo locally works as expected.
I am still getting the same error in the pre-release version.
ERROR [01/05/22 18:27:08:65] An unexpected error occurred:
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 14
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 47
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) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 80
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 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
I have a reproducer on a public repository: https://github.com/Cray-HPE/cray-product-catalog/runs/4230181725?check_suite_focus=true
Thanks for providing a public repository, @rkleinman-hpe. However, I'm unable to reproduce the problem on HEAD of develop and since neither the commit https://github.com/Cray-HPE/cray-product-catalog/commit/a5ba9946789be347a2b6d6d5c61e0dc9fe1e2257 nor the branch feature/CASMCMS-7619 exists anymore, I'm unable to get hold of it to reproduce the problem locally.
Are you able to provide a commit and branch that consistently fails?
ERROR [03/30/22 17:03:25:01] An unexpected error occurred:
System.NullReferenceException: Object reference not set to an instance of an object.
at GitVersion.RepositoryStore.<>c.<GetMergeCommitsForBranch>b__33_3(BranchCommit b) in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/Core/RepositoryStore.cs:line 521
at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter`1.ComputeMap(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
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 /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/Core/RepositoryStore.cs:line 501
at GitVersion.RepositoryStore.FindCommitBranchWasBranchedFrom(IBranch branch, Config configuration, IBranch[] excludedBranches) in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/Core/RepositoryStore.cs:line 382
at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches)
at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs:line 54
at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs:line 28
at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/Core/GitVersionContextFactory.cs:line 38
at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/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 /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs:line 15
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs:line 30
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 52
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /private/tmp/gitversion-20220310-16026-1mvb8ws/GitVersion-5.9.0/src/GitVersion.App/GitVersionExecutor.cs:line 66
INFO [03/30/22 17:03:25:01] Attempting to show the current git graph (please include in issue):
INFO [03/30/22 17:03:25:01] Showing max of 100 commits
INFO [03/30/22 17:03:25:11] * 2e5ccdc4 2 hours ago (tag: 0.1.1060, origin/master, origin/HEAD, master)
@sanjivpurohit, your latest stack trace is different from the first you and @rkleinman-hpe posted. As far as I can tell, the first stack trace fails here:
https://github.com/GitTools/GitVersion/blob/b7d207f7f107e56ae9a1d738d264a21f4c08b129/src/GitVersion.LibGit2Sharp/Git/GitObject.cs#L13
While the second fails here:
https://github.com/GitTools/GitVersion/blob/b7d207f7f107e56ae9a1d738d264a21f4c08b129/src/GitVersion.Core/Core/RepositoryStore.cs#L521
We should of course try to fix both errors, but I don't think they are related.
I have started exploring possible fixes for this in #3064. Please add your thoughts, ideas and feedback if you have any.
I tried the latest build and there are still more null protection required. Please let me know if you want me to open new issue.
ERROR [04/04/22 21:18:52:16] An unexpected error occurred:
System.NullReferenceException: Object reference not set to an instance of an object.
at GitVersion.RepositoryStore.<>c.2.ComputeKeys(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter1.ComputeMap(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable1.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at GitVersion.RepositoryStore.GetMergeCommitsForBranch(IBranch branch, Config configuration, IEnumerable1 excludedBranches) in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/Core/RepositoryStore.cs:line 483
at GitVersion.RepositoryStore.FindCommitBranchWasBranchedFrom(IBranch branch, Config configuration, IBranch[] excludedBranches) in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/Core/RepositoryStore.cs:line 321
at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList1 excludedInheritBranches)
at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList1 excludedInheritBranches) in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs:line 54
at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList1 excludedInheritBranches) in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/Configuration/BranchConfigurationCalculator.cs:line 28
at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/Core/GitVersionContextFactory.cs:line 38
at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/GitVersionCoreModule.cs:line 37
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue()
at System.Lazy`1.get_Value()
at GitVersion.VersionCalculation.NextVersionCalculator.get_context() in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs:line 15
at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs:line 30
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 52
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /Users/runner/work/GitVersion/GitVersion/src/GitVersion.App/GitVersionExecutor.cs:line 66
INFO [04/04/22 21:18:52:16] Attempting to show the current git graph (please include in issue):
INFO [04/04/22 21:18:52:16] Showing max of 100 commits
INFO [04/04/22 21:18:52:26] * 1aeae519 4 hours ago (origin/ss/ps_enum)
:tada: This issue has been resolved in version 5.10.0 :tada: The release is available on:
Your GitReleaseManager bot :package::rocket: