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

GIT alternates not supported with version 3.4x #595

Closed
Sam13 opened this issue Apr 26, 2021 · 20 comments
Closed

GIT alternates not supported with version 3.4x #595

Sam13 opened this issue Apr 26, 2021 · 20 comments

Comments

@Sam13
Copy link

Sam13 commented Apr 26, 2021

When repository is checked out with GIT alternates (e.g. as TeamCity does) NBGV get-version fails:
Nerdbank.GitVersioning.GitException: An commit object with SHA 163380e3fa79d36c0e51efc251132aa7e7f86b9d could not be found.

To reproduce:
git clone --mirror https://github.com/dotnet/Nerdbank.GitVersioning.git
git clone --shared --reference .\Nerdbank.GitVersioning.git https://github.com/dotnet/Nerdbank.GitVersioning.git test
cd test
nbgv Get-Version

I'm using NBGV v3.4.194 on Windows.
Setting NBGV_GitEngine=LibGit2 works but unfortunately not in Docker image mcr.microsoft.com/dotnet/sdk:5.0 because of dependency load problems for LibGit2.

@Sam13 Sam13 changed the title GIT alternates not supported withversion 3.4x GIT alternates not supported with version 3.4x Apr 26, 2021
@AArnott
Copy link
Collaborator

AArnott commented Apr 26, 2021

It looks like yet another storage variance with git that our new managed implementation may not yet support?
@qmfrederik what do you think?

@AArnott AArnott added this to the v3.4 milestone Apr 26, 2021
@AArnott AArnott added the bug label Apr 26, 2021
@qmfrederik
Copy link
Contributor

There was some work done to support alternates, e.g. https://github.com/dotnet/Nerdbank.GitVersioning/blob/master/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs#L537-L568 (and in the constructor), but obviously it fails here.

I'll try to free up some time to have a look at the open managed-git issues (this one seems easy to reproduce). (Unfortunately, freeing up time is not so easy lately).

@AArnott
Copy link
Collaborator

AArnott commented Apr 26, 2021

Unfortunately, freeing up time is not so easy lately

Understandable. I really appreciate how responsive you've been and how well you're supporting your new feature. We don't hear a lot about folks unblocked in 3.4 on various linux distros as a result of your work, but I assume that's because people mostly give feedback when something's broken rather than when it works. And I used to get a stream of complaints about various distros, and I haven't heard a peep since your work, so that's great!
@Sam13 even mentioned the libgit2 workaround doesn't work for him because he is in a linux environment where it doesn't work, so clearly your new feature is having a positive impact.

@qmfrederik
Copy link
Contributor

Thanks, @AArnott . I had a look at two issues which seemed straightforward (including this one). Issues like #584 and #587 will probably need more time. Do you think you could label issues related to the managed git implementation with a managed-git label or something similar? That would help me identify those.

@qmfrederik
Copy link
Contributor

@AArnott By the way, from a conversation on another project:

As long as there is no native dependency (that's bugged me a lot), and that it's fast.. One issue I had with one of the gitversion tools was that it recalculated the version for each project in a solution (hence my tendency to calculate versioning once and apply it by includes).. Minver has yet to show the same slowness.

Performance and portability seem to be a common concern for users of git-based versioning tools in the ecosystem. Glad to see nbgv making progress on both fronts!

@AArnott
Copy link
Collaborator

AArnott commented Apr 30, 2021

@Sam13 would you be willing to test @qmfrederik's fix to see if it resolves your issue?

Use version 3.4.201 from here: https://dev.azure.com/andrewarnott/OSS/_packaging?_a=package&feed=PublicCI&package=Nerdbank.GitVersioning&protocolType=NuGet&version=3.4.201&view=overview

Thanks.

@Sam13
Copy link
Author

Sam13 commented May 3, 2021

Still fails on Teamcity (which is using alternates):

/root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
  /root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018: Nerdbank.GitVersioning.GitException: An commit object with SHA b34230dc4f18514928ead73604be154c9a1d57d4 could not be found.
  /root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:    at Nerdbank.GitVersioning.ManagedGit.GitRepository.GetObjectBySha(GitObjectId sha, String objectType)
  /root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:    at Nerdbank.GitVersioning.ManagedGit.GitRepository.GetCommit(GitObjectId sha, Boolean readAuthor)
  /root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:    at Nerdbank.GitVersioning.ManagedGit.GitRepository.GetHeadCommit(Boolean readAuthor)
  /root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:    at Nerdbank.GitVersioning.Managed.ManagedGitContext..ctor(String workingDirectory, String dotGitPath, String committish)
  /root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:    at Nerdbank.GitVersioning.GitContext.Create(String path, String committish, Boolean writable)
  /root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018:    at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner()

Sidenote: When running on local machine without alternates #587 happens

@qmfrederik
Copy link
Contributor

@Sam13 Thanks for testing! Could you share the contents of the alternates file on the Teamcity server?

@Sam13
Copy link
Author

Sam13 commented May 3, 2021

The content looks like that:

C:\TeamCity\BuildAgent\system\git\git-0E4C94A5.git\objects

@qmfrederik
Copy link
Contributor

@Sam13 Hmm, now you got me confused - the TeamCity build log shows:

/root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.

which made me think that was a Linux server, but C:\TeamCity\BuildAgent\system\git\git-0E4C94A5.git\objects is a Windows path.

Is this running WSL or something similar?

@Sam13
Copy link
Author

Sam13 commented May 3, 2021

Sorry for the confusion.
This happens if your Build Agent is on Windows and you're running Linux containers.
If the build agent is Linux the content of the alternate files looks like that:
/teamcity/system/git/git-84BA29EB.git/objects

@qmfrederik
Copy link
Contributor

@Sam13 I have to admit don't know much about WSL2 (assuming that's how you run your containers).

I didn't expect a Windows-style path inside a Linux environment. Does git show b34230dc4f18514928ead73604be154c9a1d57d4 work if you run that command inside a container?

@Sam13
Copy link
Author

Sam13 commented May 4, 2021

@qmfrederik I did some more investigation by executing the following commands in my containers (docker-compose):

GIT_ALTERNATES_PATH=$$(cat .git/objects/info/alternates) &&
echo $$GIT_ALTERNATES_PATH &&
ls $$GIT_ALTERNATES_PATH &&
git log -n 1

When I run this on a Linux host, Linux container GIT log shows commit information but NBGV fails:

/root/.nuget/packages/nerdbank.gitversioning/3.4.201/build/Nerdbank.GitVersioning.Inner.targets(17,5): error MSB4018: Nerdbank.GitVersioning.GitException: An commit object with SHA 4a25bea23766ed23f5763b03fdaa1cded6734e3f could not be found.

When I run this on a Windows host, Linux container NBGV 3.4.201 works. (Altough GIT log fails)

So for me it seems that NBGV 3.4.201 seems to fail only on Linux?

@qmfrederik
Copy link
Contributor

When I run this on a Linux host

Can you copy the output of echo $$GIT_ALTERNATES_PATH?

@Sam13
Copy link
Author

Sam13 commented May 4, 2021

Can you copy the output of echo $$GIT_ALTERNATES_PATH?

/teamcity/system/git/git-84BA29EB.git/objects

@qmfrederik
Copy link
Contributor

@Sam13 Thanks, do you know whether there's a trailing \n character at the end?

@Sam13
Copy link
Author

Sam13 commented May 5, 2021

@qmfrederik Prerelease v3.4.203 works on Linux host with Linux container!

Altough GIT height is always zero (#587)

@3x0dv5
Copy link

3x0dv5 commented Apr 27, 2023

Hi guys,
using github actions I see this problem happening, here is a job that fails with this error:
https://github.com/ruilimacom/amiliur.annotations/actions/runs/4823851800/jobs/8592878009

the commit exists:

amiliur.annotations\src\amiliur.annotations [develop ≡]> git rev-list --all | Select-String "7de9ba10425f0b2dc4138e5a598a94f933cbc545"

7de9ba10425f0b2dc4138e5a598a94f933cbc545

@AArnott
Copy link
Collaborator

AArnott commented Apr 28, 2023

@3x0dv5 Your fetch-depth is 1: https://github.com/ruilimacom/amiliur.annotations/actions/runs/4823851800/jobs/8592878009#step:2:8

You need to set fetch-depth to 0 so that history is downloaded.

@3x0dv5
Copy link

3x0dv5 commented Apr 28, 2023

whoops... I feel like an idiot 😄
Thanks @AArnott , that was the problem indeed.

changing the step to:

- name: Checkout repository
      uses: actions/checkout@v3
      with:
        fetch-depth: 0

did it

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

4 participants