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

LibGit2Sharp.Core.Proxy.git_commit_tree_id throws NullReferenceException in shallow clones #1775

Open
AArnott opened this issue Mar 13, 2020 · 2 comments

Comments

@AArnott
Copy link
Contributor

AArnott commented Mar 13, 2020

Reproduction steps

dotnet tool install -g nbgv
git clone https://github.com/aarnott/nerdbank.streams  --depth 10
cd .\nerdbank.streams\
nbgv get-version

Expected behavior

An exception thrown explaining that data is missing because of a shallow clone.

Actual behavior

A NullReferenceException that does not suggest the underlying problem.

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at LibGit2Sharp.Core.Proxy.git_commit_tree_id(ObjectHandle obj)
   at LibGit2Sharp.Commit.<>c__DisplayClass11_0.<.ctor>b__0(ObjectHandle obj)
   at LibGit2Sharp.Core.GitObjectLazyGroup.<>c__DisplayClass3_0`1.<Singleton>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Nerdbank.GitVersioning.VersionFile.GetVersion(Commit commit, String repoRelativeProjectDirectory) in D:\a\1\s\src\NerdBank.GitVersioning\VersionFile.cs:line 52
   at Nerdbank.GitVersioning.GitExtensions.CommitMatchesVersion(Commit commit, SemanticVersion expectedVersion, Position comparisonPrecision, String repoRelativeProjectDirectory) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 450
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 676
   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping)   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
 in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
 in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at Nerdbank.GitVersioning.GitExtensions.GetCommitHeight(Commit commit, Dictionary`2 heights, Func`2 continueStepping) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 681
   at Nerdbank.GitVersioning.GitExtensions.GetVersionHeight(Commit commit, String repoRelativeProjectDirectory, Version baseVersion) in D:\a\1\s\src\NerdBank.GitVersioning\GitExtensions.cs:line 65
   at Nerdbank.GitVersioning.VersionOracle..ctor(String projectDirectory, Repository repo, Commit head, ICloudBuild cloudBuild, Nullable`1 overrideVersionHeightOffset, String projectPathRelativeToGitRepoRoot) in D:\a\1\s\src\NerdBank.GitVersioning\VersionOracle.cs:line 86
   at Nerdbank.GitVersioning.Tool.Program.OnGetVersionCommand(String projectPath, String format, String singleVariable, String versionOrRef) in D:\a\1\s\src\nbgv\Program.cs:line 305
   at Nerdbank.GitVersioning.Tool.Program.MainInner(String[] args) in D:\a\1\s\src\nbgv\Program.cs:line 149
   --- End of inner exception stack trace ---
lean wrapExceptions)
, CultureInfo culture)

Version of LibGit2Sharp (release number or SHA1)

0.27.0-preview.7+gd47cfd9144.libgit2-572e4d8

Operating system(s) tested; .NET runtime tested

Windows 10. .NET Core

danielcirket added a commit to danielcirket/OpenEventSourcing that referenced this issue Jul 6, 2020
* Create build.yml
* Update Nerdbank.GitVersioning for GitHub actions support
* Attempt to work around shallow clone issues with LibGit2Sharp

    See: dotnet/Nerdbank.GitVersioning#423
    See: libgit2/libgit2sharp#1775

* Skip RabbitMQ integration tests when no connection string configured
* Remove dummy service bus connection string to skip Service Bus integration tests
* Skip additional service bus tests when no connection string available
* Skip additional RabbitMQ tests when no connection string is available
* Attempt to get rabbitmq service container working
* Attempt to connect to rabbitmq service container for tests
* Skip rabbitmq management tests if neither connectionstring or management uri configured
* Add service bus connection string secret
* Attempted OS matrix builds for linux and windows builds
* Revert "Attempted OS matrix builds for linux and windows builds"
* Add coverlet flags to dotnet test
* Attempt to store test coverage artifact
* Remove flaky rabbitmq connection finalizer tests
@olivier-spinelli
Copy link

olivier-spinelli commented Nov 19, 2020

In addition to the better exception you suggest, I'd love to benefit of a simple bool IsShallowed {get; } or IsInvalid or IsOutOfClone that would avoid an awful try/catch.

@vincentcastagna
Copy link

vincentcastagna commented Jan 26, 2023

We are still experiencing this issue with git version 5.10.1 on azure devops pipeline.

The fix is to specify a max depth of 0 with a checkout task before gitversion :

steps:
- checkout: self 
  fetchDepth: 0  
  clean: true
  
- task: gitversion/setup@0
  inputs:
    versionSpec: '5.10.1'
  displayName: 'Install GitVersion'

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

3 participants