Skip to content

LibGit2Sharp.NotFoundException: Object not found - no match for id #1043

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

Closed
ryudice opened this issue Sep 21, 2016 · 13 comments
Closed

LibGit2Sharp.NotFoundException: Object not found - no match for id #1043

ryudice opened this issue Sep 21, 2016 · 13 comments

Comments

@ryudice
Copy link

ryudice commented Sep 21, 2016

Any idea why I would get this error and is there anyway to ignore the error? The error is LibGit2Sharp.NotFoundException: Object not found - no match for id

@asbjornu
Copy link
Member

@ryudice: Does this happen in a public repository? If not, can you reproduce it in a public repository we can inspect? Which version of GitVersion are you using? Are you using the MSBuild Task or .exe?

Usually, this exception occurs if you have a shallow repository or have only cloned a branch and not the whole repository. Does this happen locally or on a build server?

@ryudice
Copy link
Author

ryudice commented Oct 12, 2016

@asbjornu It seems it was a shallow clone causing the issue, after doing the full clone seems to be ok, maybe a more descriptive error would be good?

Thanks for you help.

@ryudice ryudice closed this as completed Oct 12, 2016
@asbjornu
Copy link
Member

@ryudice: I completely agree that a more descriptive error would be good. If you can figure out where we can catch the LibGit2Sharp.NotFoundException in GitVersion and wrap it in a custom exception, it would be a simple thing to fix. Want to take on that task in a pull request or just write down your findings in here?

@asbjornu asbjornu reopened this Oct 12, 2016
@tomap
Copy link
Contributor

tomap commented Oct 25, 2016

Hi,
Not sure it's the same cause, but I got the same exception.
Here is the full stacktrace:

ERROR [10/21/16 15:44:39:77] An unexpected error occurred:
 LibGit2Sharp.NotFoundException: Object not found - no match for id (5a8f976b3c528351cef3d7f632721bfdc785e9c)
    at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
    at LibGit2Sharp.Core.Proxy.git_revwalk_next(RevWalkerHandle walker)
    at LibGit2Sharp.CommitLog.CommitEnumerator.MoveNext()
    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
    at GitVersion.VersionCalculation.FallbackBaseVersionStrategy.<GetVersions>d__0.MoveNext()
    at System.Linq.Enumerable.<SelectManyIterator>d__16`2.MoveNext()
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
    at GitVersion.VersionCalculation.BaseVersionCalculator.GetBaseVersion(GitVersionContext context)
    at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context)
    at GitVersion.GitVersionFinder.FindVersion(GitVersionContext context)
    at GitVersion.ExecuteCore.<>c__DisplayClass6_0.<ExecuteInternal>b__0(IRepository repo)
    at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
    at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
    at GitVersion.Program.VerifyArgumentsAndRun()

I git this error while testing the new Shallow clone in VSTS:
https://www.visualstudio.com/en-us/docs/build/define/repository#git

And then at the end of the script, I got:

##[error]System.Exception: Unexpected exit code 1 returned from tool GitVersion.exe
    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeToolCmdlet.ProcessRecord()
    at System.Management.Automation.CommandProcessor.ProcessRecord()
 ##[error]PowerShell script completed with 1 errors.

I think in case of shallow clone (with an option?) you should ignore this errors

@CharliePoole
Copy link

This seems to be an instance of the same issue: https://travis-ci.org/NUnitSoftware/nunit-gui/jobs/271064871#L2026

I'm in the process of adding GitVersion to the NUnit GUI build. Haven't been able to get it to work on Travis under Linux although the problem doesn't occur on Windows with AppVeyor or locally. Haven't had a chance to try it locally on Linux yet. The failure occurs in the initial call to retrieve a GitVersion instance in my Cake script.

@asbjornu
Copy link
Member

asbjornu commented Sep 4, 2017

@CharliePoole: Is Travis doing a shallow clone? If so, does git fetch --unshallow before running GitVersion fix the problem?

@CharliePoole
Copy link

@asbjornu Thanks... I found that option and implemented it... works great!

It would be better, I think, if GitVersion did something better with that exception. LibGit2Sharp has to throw here, since it doesn't know the purpose of the call. But GitVersion knows what it's doing and could either try to deal with the shallow clone or at least give a better message where that turns out to be the case.

@asbjornu
Copy link
Member

asbjornu commented Sep 5, 2017

@CharliePoole: I completely agree, which is why I suggested that solution in #1043 (comment). I've submitted #1287 which should improve the thrown exception. 😃

BeeWarloc added a commit to Pomona/Pomona that referenced this issue Sep 26, 2017
Maybe this fixes the failing builds.
ref GitTools/GitVersion#1043 (comment)
BeeWarloc added a commit to Pomona/Pomona that referenced this issue Sep 26, 2017
Maybe this fixes the failing builds.
ref GitTools/GitVersion#1043 (comment)
forki added a commit to fsprojects/Mechanic that referenced this issue Jan 9, 2018
forki added a commit to fsprojects/Mechanic that referenced this issue Jan 9, 2018
forki added a commit to fsprojects/Mechanic that referenced this issue Jan 9, 2018
@solidclouddev
Copy link

I'm seeing this is my repo here: https://travis-ci.com/solidclouddev/plivo-dotnet/jobs/162238939

Not sure how to fix this?

@asbjornu
Copy link
Member

asbjornu commented Dec 3, 2018

@solidclouddev: It seems like you're using Nerdbank.GitVersioning and not GitTools.GitVersion, so I'm not sure this is the right repository to ask?

@TheFabbiusCorp
Copy link

TheFabbiusCorp commented Oct 9, 2022

Since I couldn't really find the solution to this issue in the documentation, I wanted to mention that, if you are running your project on GitLab CI, you need to set these variables to the job that executes gitversion:

Export GitVersion:
  variables:
    # Force a deep/non-shallow fetch
    GIT_STRATEGY: fetch
    GIT_FETCH_EXTRA_FLAGS: --unshallow
    GIT_DEPTH: 0

@tlsrcracer7
Copy link

I also ran into this issue, and found https://stackoverflow.com/questions/73827375/gitversion-fails-to-get-the-json-data was useful. It did have to do with the shallow fetch, but mine was part of a DevOps pipeline instead of GitLab.

@markwragg
Copy link

For Azure DevOps YAML pipelines, this can be fixed by adding fetchDepth: 0 to your checkout task, as documented here: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines#shallow-fetch

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

9 participants