Tuesday, November 12, 2019

LibGit2Sharp.NotFoundException: Object not found - no matching loose object

Hi Everyone.
In this article we will talk about very old bug in GIT:

LibGit2Sharp.NotFoundException: Object not found - no matching loose object (0000000000000000000000000000000000000000)
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
at LibGit2Sharp.Core.Proxy.git_checkout_tree(RepositorySafeHandle repo, ObjectId treeId, GitCheckoutOpts& opts)
at LibGit2Sharp.Repository.CheckoutTree(Tree tree, IList`1 paths, IConvertableToGitCheckoutOpts opts)
at LibGit2Sharp.Repository.Checkout(Tree tree, CheckoutOptions checkoutOptions, String refLogHeadSpec)
at LibGit2Sharp.Repository.Checkout(String committishOrBranchSpec, CheckoutOptions options)
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncAndCheckout(ITaskEndpoint endpoint, String rootPath, Boolean cleanRepository, String sourceBranch, String sourceVersion, String& commit, CancellationToken cancellationToken, Boolean checkoutSubmodules)
at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.TfsGitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()



Background.

   Our client still using TFS 2015. And after one discussion dev team decided move from git repo binaries to another git repo. When they moved binaries we enabled in VNext build definition Checkout submodules and receive following error:

System.OperationCanceledException: Git operation canceled ---> LibGit2Sharp.UserCancelledException: No error message has been provided by the native library
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts)
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.CloneRepository(String repositoryPath, Uri repositoryUrl, Boolean checkoutSubmodules, String username, String password)
--- End of inner exception stack trace ---
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.CloneRepository(String repositoryPath, Uri repositoryUrl, Boolean checkoutSubmodules, String username, String password)
at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(Uri repositoryUrl, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion, String username, String password)

   I tried quickly find any information about this error and found that this happens because tfs is using an old version of git.  The problem was aggravated by the fact that TFS does not directly use git, but calls the API through libraries. Finally, I disable option checkout submodules.

Customization downloading git submodules


   When TFS in VNext build definition start zero-step with downloading the repo, it is download full git repo, and then make checkout to branch which needs to build. As for pull request, TFS creates temporary git branch with guid name.
If some branch has submodule (for example master), and other doesn't have (for example release), in that case, if build definition cleans every time build folder, you will receive an error which is placed at the top of this posting.
   Because Microsoft doesn't support in the current moment TFS 2015, 2017, we should resolve this issue by our self. 
  We have two options. 
  1. The first option connect with an old version of git. I saw similar errors, but in other cases, people don't use TFS. They use standalone git.exe. Because we can't update version of git in tfs, this option is relevant only who use separate git. Just update the version of git!
  2. The second life hack is for people who can't update git. It is also relevant for the separate git process. 
        Do the following steps:
        1. Disable cleaning build folder.
        2. Start to build with a branch which could pass zero-step to download artifacts
        3. In the end, remove everything except .git folder
        4.Switch branch in release definition which broke build with error on the top.
 After this old git pickup, previous cash from .git folder and could checkout between branches which has/hasn't submodules.

 


No comments:

Post a Comment