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

Regression: Nerdbank.GitVersioning.GitException: The commit 0000000000000000000000000000000000000000 was not found in this repository. #602

Closed
vchirikov opened this issue May 15, 2021 · 10 comments

Comments

@vchirikov
Copy link

vchirikov commented May 15, 2021

Hello, I ran into a problem with the managed git implementation in nbgv (3.4.194).
The 3.3.37 version works fine.

> cat .git/HEAD
ref: refs/heads/my/build_system_setup

> dotnet nbgv get-version
 Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Nerdbank.GitVersioning.GitException: The commit 0000000000000000000000000000000000000000 was not found in this repository.
     at Nerdbank.GitVersioning.ManagedGit.GitRepository.GetCommit(GitObjectId sha, Boolean readAuthor)
     at Nerdbank.GitVersioning.Managed.ManagedGitContext.TrySelectCommit(String committish)
     at Nerdbank.GitVersioning.Tool.Program.OnGetVersionCommand(String project, IReadOnlyList`1 metadata, String format, String variable, String commitIsh) in D:\a\1\s\src\nbgv\Program.cs:line 371
     --- End of inner exception stack trace ---
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at System.Delegate.DynamicInvokeImpl(Object[] args)
     at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
     at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseMiddleware>b__0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

The repo was cloned through git alternates and then repacked.

git repack -a -d && rm -rf .git/objects/info/alternates
@vchirikov vchirikov changed the title Nerdbank.GitVersioning.GitException: The commit 0000000000000000000000000000000000000000 was not found in this repository. Regression: Nerdbank.GitVersioning.GitException: The commit 0000000000000000000000000000000000000000 was not found in this repository. May 15, 2021
@AArnott AArnott added this to the v3.4 milestone May 16, 2021
@AArnott
Copy link
Collaborator

AArnott commented May 16, 2021

I think this may be fixed in the latest CI build. Can you confirm by trying out v3.4.203?

More instructions here: https://github.com/dotnet/Nerdbank.GitVersioning#how-do-i-consume-the-latest-changes-prior-to-their-release-on-nugetorg

@AArnott AArnott added the bug label May 16, 2021
@vchirikov
Copy link
Author

I tried 3.4.203, nbgv call ended with the same result :(

@AArnott
Copy link
Collaborator

AArnott commented May 16, 2021

@qmfrederik What do you think? Can we fix this?

@epvanhouten
Copy link

epvanhouten commented May 18, 2021

I was trying to build a reproduction for this and am having trouble getting it to break.

I wrote the following script based on my, limited, understanding of git alternates.

$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'

New-Item -ItemType Directory 602Test | Push-Location
dotnet new tool-manifest
dotnet tool install --version 3.4.194 nbgv

New-Item -ItemType Directory source | Push-Location
git init
dotnet nbgv install
git commit -a -m "Add nbgv to source repo"
$sourceRepo = (Get-Item .).FullName

Pop-Location
New-Item -ItemType Directory target | Push-Location
git clone --local --shared $sourceRepo .
Write-Information "Content of .git/info/objects/alternates pre-repack:"
Get-Content .git\objects\info\alternates
git repack -a -d

if(Test-Path .git\info\objects\alternates)
{
    Write-Information "Content of .git/info/alternates post-repack:"
    Get-Content .git\info\objects\alternates
    Get-ChildItem .git\objects\info\alternates | Remove-Item -Force
}else{
    Write-Information "Alternate configuration is gone"
}
dotnet nbgv get-version

Pop-Location
git --version
dotnet nbgv --version

Pop-Location

Which results in the following output:

The template "Dotnet local tool manifest file" was created successfully.
You can invoke the tool from this directory using the following commands: 'dotnet tool run nbgv' or 'dotnet nbgv'.
Tool 'nbgv' (version '3.4.194') was successfully installed. Entry is added to the manifest file C:\code\nbgv602\602Test\.config\dotnet-tools.json.
Initialized empty Git repository in C:/code/nbgv602/602Test/source/.git/
[master (root-commit) 293cb72] Add nbgv to source repo
 2 files changed, 22 insertions(+)
 create mode 100644 Directory.Build.props
 create mode 100644 version.json
Cloning into '.'...
done.
Content of .git/info/objects/alternates pre-repack:
C:\code\nbgv602\602Test\source/.git/objects
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Alternate configuration is gone
Version:                      1.0.1.15401
AssemblyVersion:              1.0.0.0
AssemblyInformationalVersion: 1.0.1-beta+293cb728f2
NuGetPackageVersion:          1.0.1-beta
NpmPackageVersion:            1.0.1-beta
git version 2.30.1.windows.1
3.4.194+8126d95e2c

I feel like I am missing something in the setup.

Edit: Revised to something probably closer to being right... but still not getting a reproduction.

@qmfrederik
Copy link
Contributor

I think this is caused by ResolveReference being unable to open the reference, after which it returns GitObjectId.Empty.

  1. We should find out why ;-).
  2. ResolveReference should probably throw instead.

@vchirikov What does cat .git/refs/heads/my/build_system_setup yield?

@qmfrederik
Copy link
Contributor

@vchirikov If you're up to it, you should be able to fairly easily debug this yourself - something like this:

var repository = GitRepository.Create("path_to_your_repo");
var head = repository.GetHeadCommitSha();

// head is likely to be GitObjectId.Empty; we should find out why ;-)

should get you to the relevant part of the code.

@vchirikov
Copy link
Author

It happened on a build server (TeamCity), I will try to reproduce it soon on my local repo.

@filipnavara
Copy link
Member

Likely to be fixed by #613

@filipnavara
Copy link
Member

git-packed-head.zip

Test repository. Created by git init, git commit --allow-empty -m "Empty commit", git pack-refs --all.

AArnott added a commit to filipnavara/Nerdbank.GitVersioning that referenced this issue Jun 12, 2021
@AArnott AArnott closed this as completed Jun 12, 2021
@vchirikov
Copy link
Author

Sorry I was on vacation. I can confirm, the issue is resolved on 3.4.216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants