-
Notifications
You must be signed in to change notification settings - Fork 662
Fix git system hash for worktrees #1759
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add tests to make sure this change works as expected?
|
I give up trying to make LibGit2Sharp create a cross-platform worktree to test this 🤦♂ |
|
@chuseman, is that why AppVeyor is failing the build? |
|
No, I was just trying to add a test for completeness. The AppVeyor thing looks like it was a transient network error:
Do you have a way to kick off another AppVeyor build to see if it works now? |
I see. Yes, I expected to find a test in this PR somewhere. If you have a proposal for a test, perhaps we can discuss in this PR how to make it work cross-platform? Please add it to the PR.
Yes, done. |
|
@chuseman, when LibGit2Sharp throws |
|
I don't see a way to get the reference that it is complaining about. The exception doesn't have any interesting properties that aren't logged already. I think this is actually some kind of LibGit2Sharp on Mono failure -- it only fails when running the net472 test on Mono. LibGit2Sharp's test to add a worktree does almost exactly what mine does so I don't think I'm calling the API incorrectly. I don't think they run tests on Mono though - just .NET Core for Linux/Mac. This probably isn't worth fighting for this case though because the part that is failing is just the arranging of the environment (creating a dummy worktree) to test my new logic. When actually exercising the new logic, it works fine on Mono. So, for now I've just added a skip for this worktree test on mono. |
|
@chuseman, have you inspected the |
Yes - the only data added are |
| var versionAndBranchFinder = new ExecuteCore(fileSystem); | ||
|
|
||
| if (Type.GetType("Mono.Runtime") != null) | ||
| Assert.Ignore("LibGit2Sharp fails here when running under Mono"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there might be tests that already ignore Mono through the use of [Category] or something similar. Can you please investigate that option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did see the NoMono category, but it looks like the logic is to skip the whole test when running on Unix. This test can run with .NET Core, so I didn't want to skip it altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, that logic is wrong, then. There are surely a lot of tests decorated with NoMono that break on Unix, but then they should be marked with a NoUnix category. To not continue digging in this erroneous hole and make it any bigger, let's fix the NoMono vs. NoUnix issue first and then decorate this test with NoUnix. Ok? If you want to tackle it in this PR that would be very much appreciated, otherwise I can take a look in another PR if I can find a few minutes of spare time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started adding the changes for a NoUnix category, but there were some required category changes so I think its better in a separate PR. I'll open another one once I work through the failing tests.
For now, I've just switched my new test over to NoMono so it should pass.
Codecov Report
@@ Coverage Diff @@
## master #1759 +/- ##
======================================
Coverage 66.9% 66.9%
======================================
Files 130 130
Lines 4829 4829
======================================
Hits 3231 3231
Misses 1598 1598Continue to review full report at Codecov.
|
When calculating the system hash, all refs need to be included so we need to look outside the worktree's gitdir.
|
@chuseman, can you please have a look at what @ermshiperete has done in #1793 and consider whether it solves your problem or not? |
Running GitVersion from a git worktree nearly works for me -- I just get an exception when
GitVersionCacheKeyFactory.GetGitSystemHash()is called.To come up with the
gitSystemHashportion of the composite hash,.git/refs/*are enumerated and all file names are included. This falls down for worktrees because the .git directory returned is actually.git/worktrees/<worktree name>and there isn't arefsfolder here.So, this PR just does some string matching to see if the path looks like a worktree and if so, return the parent .git dir path instead. I didn't see an easy way using LibGit2Sharp to jump from a worktree to its parent repo path and I figured string matching on the path is probably safe enough for this case.
Also, I added a more meaningful message when throwing an ArgumentException() when the refs folder couldn't be found.