-
Notifications
You must be signed in to change notification settings - Fork 539
storage/worktree: filesystem, support common directory/linked repositories #1098
base: master
Are you sure you want to change the base?
Conversation
27a9f5b
to
3932973
Compare
…ories. Signed-off-by: Arran Walker <arran.walker@fiveturns.org>
At the moment I have An alternative would be Any preference/thoughts on what I'm starting to think it's more likely developers would expect |
From what I understand most of the files reside in the common A PR to fixtures with a repository in this fashion would be great for testing. Thanks! |
This supports worktrees; none of this code is my own.
Hi @saracen, thanks for the PR. Could you share your fixtures? |
thank you @saracen I am available to test any change if you need. So far, what I did:
Output:
|
@saracen I sent you a PR fixing the gitdir of worktrees (saracen/go-git-fixtures#1). Now the tests are passing:
|
@sbourlon Thanks for testing and fixing that. I've merged your MR and renamed the filename of the fixture (sha-1 hash of the uncompressed tar). Are you able to test with the updated fixtures? |
thanks @saracen, doing now. |
@saracen the tests pass, however it is not working in my case because I am using the |
My use case is to run the same command as: What about updating |
Are you not able to just use Using that, and committing to the worktree returned from it looks like it might be enough. Sorry if I'm misunderstanding something, I wasn't super knowledgeable about the worktree workflow even when I wrote this almost a year ago :( |
I need to pass both the work tree dir and the gitdir because they are located in different directories. Here is an interesting article explaining that: https://www.logicbig.com/tutorials/misc/git/custom-git-dir.html In the git cli, that would be: |
I'm not sure why you'd ever have to provide the gitdir and worktree directory paths up front, as the .git file already links them with that |
thanks @saracen, I was able to reset my linked worktree to the main worktree, however I think in my test:
I think your solution works with |
it's finally working! I will sent you a small PR to load a separate worktree tomorrow morning (PST time) Thanks again @saracen for your help. |
@saracen here is the branch with your branch rebased on master and my commit that let PlainOpenWithOptions() open a repository with a worktree in a separate directory. I have used this mode to call Status() and Log() successfully. https://github.com/sbourlon/go-git/commits/common-linked-repo-rebased Maybe you could:
|
Hi @sbourlon - I'm not entirely sure what you're doing isn't already supported still. But, it occurs to me that you're wanting the working tree main directory, rather than the dotgit directory. This PR is mostly about dealing with the dotgit side of things and dealing with references in both the common and local repository. It might be best that I try and work with @jfontan to get this merged soon, and then you create another PR to address your requirements. I know it's a longer process, but probably cleaner than have me be a middleman into what it is you want to achieve. I hope that makes sense. @jfontan Can you take a look at the fixtures I've submitted and see if they're acceptable? As suggested, I'll modify the method names to |
@saracen that works for me 👍 |
This PR implements main/common directory support for linked working tree repositories created by
git worktree add
(akaGIT_COMMON_DIR
as noted in https://git-scm.com/docs/gitrepository-layout).To summarize:
PlainOpenWithOptions
now checks to see whether a file calledcommondir
is in the .git directory. If so, it knows this is a linked/local worktree. Ifcommondir
is valid, this main worktree it references is opened and set infilesystem.Options
asCommonDir
. This setting is passed through toDotGit
.DotGit
has very few changes, as theCommonDir
filesystem takes the place of the regular filesystem (fs
), and the regular filesystem is set tolocalfs
. In the instances whereCommonDir
isn't set, bothfs
andlocalfs
reference the same filesystem, so normal repositories are unaffected.MainFilesystem()
complementsFilesystem()
. They'll return the same underlying filesystem for a normal/non-linked repository.The largest change is the way that pseudo references are handled, mainly "HEAD". All references are read from
localfs
unless they start withrefs/
, thenfs
the common directory is used. This filesystem selection is handled withfsFromRefPath
.Is this the correct approach to this? Any thoughts on additional tests that should be added (I can send a PR to the fixtures repository for what I have so far).