Read refs and objects from linked worktrees#196
Merged
Conversation
|
Tested, worked great! 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a linked worktree
.gitis a file pointing at<main>/.git/worktrees/<name>, and that directory has acommondirfile pointing back to the main.gitwhere refs and objects actually live. go-git'sPlainOpenroots its storer at the per-worktree dir, which has noobjects/and norefs/heads/, so even resolvingHEADfails withreference not found.go-git has
PlainOpenOptions.EnableDotGitCommonDirfor this, but in v5 it openscommondirwithout closing it, which on Windows blockst.TempDir()cleanup and would leak an fd per open in any long-running caller. The fix is on go-git's main but not in any v5 tag including v5.19.0.We already shell out to
git rev-parse --git-common-dirforDatabasePath(), and #194 already rebuilds the storage to setAlternatesFS, so this wraps the dotgit fs indotgit.NewRepositoryFilesystemwith the common dir during that same rebuild. go-git never openscommondiritself.This is separate from #194. That one is about
objects/info/alternates(git clone --shared/--reference), which is a different mechanism with the same error message. The two compose: a worktree of a--sharedclone needs both, and theRepositoryFilesystemwrapper routesobjects/info/alternatesto the common dir where it lives.Extended the existing worktree test to actually read refs and objects rather than just checking path resolution.
Fixes #195