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

"An tree object with SHA *** could not be found" with fetchDepth: 0 #1152

Open
oruchreis opened this issue Jan 13, 2025 · 3 comments
Open

"An tree object with SHA *** could not be found" with fetchDepth: 0 #1152

oruchreis opened this issue Jan 13, 2025 · 3 comments

Comments

@oruchreis
Copy link

oruchreis commented Jan 13, 2025

Hi,
As stated in the document, I made fetchDepth:0 to use this package on Azure Devops, but I still get the following error during the build phase:

error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly. [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018: Nerdbank.GitVersioning.GitException: An tree object with SHA 30b07c3f71f16fee9b6073fbf8831458ae0ebf11 could not be found. [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.ManagedGit.GitRepository.GetObjectBySha(GitObjectId sha, String objectType) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.ManagedGit.GitRepository.GetTreeEntry(GitObjectId treeId, ReadOnlySpan`1 nodeName) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.Managed.ManagedVersionFile.GetVersion(GitCommit commit, String repoRelativeProjectDirectory, Dictionary`2 blobVersionCache, String& actualDirectory) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.Managed.ManagedVersionFile.GetVersionCore(String& actualDirectory) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.VersionFile.GetVersion(String& actualDirectory) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.VersionFile.GetVersion() [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.VersionOracle..ctor(GitContext context, ICloudBuild cloudBuild, Nullable`1 overrideVersionHeightOffset) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner() in D:\a\1\s\src\Nerdbank.GitVersioning.Tasks\GetBuildVersion.cs:line 247 [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]
error MSB4018:    at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) [/home/ubuntu/.nuget/packages/nerdbank.gitversioning/3.7.112/build/PrivateP2PCaching.proj]

The head of the pipeline file looks like this:

steps:
- checkout: self
  persistCredentials: true
  fetchDepth: 0
  fetchTags: true
  clean: true
  displayName: 'Checkout Repository'
  
- script: |
    dotnet restore Project.sln /nowarn:NU1900
  displayName: 'Restore'

- script: |
    dotnet build Project.sln --configuration $(buildConfiguration) --no-restore /nowarn:NU1900
  displayName: 'Build'

And Directory.Packages.props file looks like this:

<Project>
  <Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3" />
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
  </PropertyGroup>
  ...
  ...
  <ItemGroup>
    <!-- GLOBAL PACKAGES -->
    <GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.7.112" />
    <GlobalPackageReference Include="Microsoft.SourceLink.AzureRepos.Git" Version="8.0.0" />
  </ItemGroup>
</Project>

By the way the target framework is .net 9.0, I'm building with .net sdk 9.0.100 and I can build in my development machine without any issues. Also I can use nbgv get-version without any error in azure devops or local machine.

Edit: The commit with 30b07c3f71f16fee9b6073fbf8831458ae0ebf11 is corresponding with symbolic link of a folder. When I delete symbolic link and move the actual folder, it can build. But I need to use symbolic link.

@AArnott
Copy link
Collaborator

AArnott commented Jan 13, 2025

The commit with 30b07c3f71f16fee9b6073fbf8831458ae0ebf11 is corresponding with symbolic link of a folder. When I delete symbolic link and move the actual folder, it can build. But I need to use symbolic link.

Are you saying that that commit added a symbolic link to the tree? Can you describe what you did to add it?
Does it only fail when you try to build something within that symbol folder?

@oruchreis
Copy link
Author

I did only this:

mklink /D SymLinkFolder ../RealFolder

then commited it. After this error occured, I've deleted SymLinkFolder, moved RealFolder to symlinked location, then pushed force(amend) on git, and it worked.
In short:
Error with git commit has:

    -> RealFolder
    -> OtherFolder
         ->SymLinkedFolder ---> ../RealFolder

For fixing this build error I've deleted SymLinkedFolder, and moved RealFolder, and overrided above commit with this by push force:

    -> OtherFolder
        ->RealFolder 

By the way in my local dev machine it works with symlinked commit, but it didn't work in azure devops pipeline.

@AArnott
Copy link
Collaborator

AArnott commented Jan 14, 2025

Thanks. I suspect this is a case we missed handling in our managed git engine. Can you please refer to https://github.com/dotnet/Nerdbank.GitVersioning/releases/tag/v3.4.142-alpha for the workaround that activates the libgit2 engine and report on whether that works?

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

2 participants