-
Notifications
You must be signed in to change notification settings - Fork 654
Fix several issues related to worktree #1793
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.
Thanks for this! I think it mostly looks good.
src/GitVersionCore/GitPreparer.cs
Outdated
@@ -150,6 +150,21 @@ public string GetDotGitDirectory() | |||
return dotGitDirectory; | |||
} | |||
|
|||
public string GetDotGitDirectoryOfMain() | |||
{ | |||
var dotGitDir = GetDotGitDirectoryOfWorktreeOrMain(); |
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.
It feels a bit weird to me that something called "get dot git directory of main" invokes a method called "get dot git directory of worktree or main". It seems like it should be the other way around?
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.
We have two types of directories that can contain .git
:
a) a regular git repo with a .git
subdirectory. This might be a normal repo, or the main working tree if worktrees are used.
b) a linked working tree repo with a .git
file. This file contains the path to the real .git
directory which resides under .git/worktrees/<worktreename>
of the main working tree.
In some cases it doesn't matter if we're dealing with case A or B, but in other cases we need to get the .git
directory of the main working tree.
I tried to name the methods so that this distinction is clear, but maybe you can think of better names?
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.
Well, the outer method uses the words OfMain
which makes it sound very specific, but then delegates to a method using the words OrMain
, indicating that it won't only fetch the .git
directory of main after all. It would make sense for a method with the word Or
(non-specific) in it to invoke a method with the word Of
(specific) in it, but not the other way around. Does that make sense?
src/GitVersionCore/GitPreparer.cs
Outdated
|
||
public string GetDotGitDirectory() | ||
{ | ||
return GetDotGitDirectoryOfMain(); |
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.
A method just invoking another method feels a bit unnecessary?
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 agree. I tried to minimize the changes to existing code, but it would be clearer if we'd replace GetDotGitDirectory
with GetDotGitDirectoryOfMain
throughout the code base.
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.
Yes, that would be good. Let's just agree on the naming first. Is Main
an established word for what you describe in the codebase (or elsewhere) or are there other ways to name it? For me, Main
is a bit ambiguous, as we already have Mainline
as a versioning mode.
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'm not to fond of these names either. Maybe we can come up with something better.
Main working tree and linked working tree is what is used in the git documentation: "A repository has one main working tree (if it’s not a bare repository) and zero or more linked working trees." (https://git-scm.com/docs/git-worktree).
We could use GetDotGitDirectoryOfRepo
(instead of GetDotGitDirectoryOfMain
) and GetDotGitDirectoryOfWorktree
(instead of GetDotGitDirectoryOfWorktreeOrMain
), although the latter method name doesn't make it obvious that it returns .git
directory of the main or linked working tree.
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.
That would be an improvement, yes. 👍
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.
Done.
This returns the correct workdir when using worktrees where the git repo resides inside of the main working tree. Partial fix for #1063.
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.
Yes, with this merged those issues can be closed.
src/GitVersionCore/GitPreparer.cs
Outdated
|
||
public string GetDotGitDirectory() | ||
{ | ||
return GetDotGitDirectoryOfMain(); |
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 agree. I tried to minimize the changes to existing code, but it would be clearer if we'd replace GetDotGitDirectory
with GetDotGitDirectoryOfMain
throughout the code base.
src/GitVersionCore/GitPreparer.cs
Outdated
@@ -150,6 +150,21 @@ public string GetDotGitDirectory() | |||
return dotGitDirectory; | |||
} | |||
|
|||
public string GetDotGitDirectoryOfMain() | |||
{ | |||
var dotGitDir = GetDotGitDirectoryOfWorktreeOrMain(); |
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.
We have two types of directories that can contain .git
:
a) a regular git repo with a .git
subdirectory. This might be a normal repo, or the main working tree if worktrees are used.
b) a linked working tree repo with a .git
file. This file contains the path to the real .git
directory which resides under .git/worktrees/<worktreename>
of the main working tree.
In some cases it doesn't matter if we're dealing with case A or B, but in other cases we need to get the .git
directory of the main working tree.
I tried to name the methods so that this distinction is clear, but maybe you can think of better names?
src/GitVersionCore/GitPreparer.cs
Outdated
@@ -150,6 +150,21 @@ public string GetDotGitDirectory() | |||
return dotGitDirectory; | |||
} | |||
|
|||
public string GetDotGitDirectoryOfMain() | |||
{ | |||
var dotGitDir = GetDotGitDirectoryOfWorktreeOrMain(); |
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.
Well, the outer method uses the words OfMain
which makes it sound very specific, but then delegates to a method using the words OrMain
, indicating that it won't only fetch the .git
directory of main after all. It would make sense for a method with the word Or
(non-specific) in it to invoke a method with the word Of
(specific) in it, but not the other way around. Does that make sense?
src/GitVersionCore/GitPreparer.cs
Outdated
|
||
public string GetDotGitDirectory() | ||
{ | ||
return GetDotGitDirectoryOfMain(); |
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.
Yes, that would be good. Let's just agree on the naming first. Is Main
an established word for what you describe in the codebase (or elsewhere) or are there other ways to name it? For me, Main
is a bit ambiguous, as we already have Mainline
as a versioning mode.
Looks like there was an issue when running the windows azure pipeline build, but I ran it manually again and it succeeds. |
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'm still not quite satisfied with the GetDotGitDirectoryOfWorktree
and GetDotGitDirectoryOfRepo
methods. Are both needed? Can't we just have a GetDotGitDirectory
that does a combination of what the two methods are doing now? Since both methods return different things depending on the state of the repository, I don't think the attempt to clarify with OfRepo
and OfWorktree
is helpful, since it's misleading. I also don't see the value in having two methods doing almost the same thing. Thoughts?
How about now? |
@ermshiperete there is a failing test on linux and macos, related to a "/" GetProjectRootDirectory_NoWorktree |
When using worktrees we want to get the .git directory of the main repo (main working tree). This fixes calculating system hashs and the location of the GitVersion cache. When determining the root directory we have to use the .git directory of the linked working tree. Fixes #1063.
@arturcic Can you trigger the build again please? Doesn't look like the test failures now are related after I fixed the real failure on linux and macos. |
It seems like the pipeline has some intermittent issues. I already triggered one and it succeeded |
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 this looks good now. Any way to get the build green, or should we just merge regardless, @arturcic?
I think we can merge it. There is a unit test that is randomly failing, but that is not an issue |
Thank you so much @ermshiperete! |
This PR includes my previous PR (#1792) and generalizes the fix from chuseman (#1759).
Besides fixing the cache key creation when using worktrees it will also fix the location of the GitVersion cache so that the cache directory gets shared between all the worktrees.