Skip to content

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

Merged
merged 4 commits into from
Sep 6, 2019
Merged

Fix several issues related to worktree #1793

merged 4 commits into from
Sep 6, 2019

Conversation

ermshiperete
Copy link
Contributor

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.

Copy link
Member

@asbjornu asbjornu left a 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.

@@ -150,6 +150,21 @@ public string GetDotGitDirectory()
return dotGitDirectory;
}

public string GetDotGitDirectoryOfMain()
{
var dotGitDir = GetDotGitDirectoryOfWorktreeOrMain();
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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?


public string GetDotGitDirectory()
{
return GetDotGitDirectoryOfMain();
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@asbjornu
Copy link
Member

asbjornu commented Sep 4, 2019

With this merged, does it mean we can close #1792, #1759 and #1063? Please rebase this on HEAD of master and force-push.

ermshiperete and others added 3 commits September 4, 2019 14:37
This returns the correct workdir when using worktrees where the git
repo resides inside of the main working tree. Partial fix for #1063.
Copy link
Contributor Author

@ermshiperete ermshiperete left a 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.


public string GetDotGitDirectory()
{
return GetDotGitDirectoryOfMain();
Copy link
Contributor Author

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.

@@ -150,6 +150,21 @@ public string GetDotGitDirectory()
return dotGitDirectory;
}

public string GetDotGitDirectoryOfMain()
{
var dotGitDir = GetDotGitDirectoryOfWorktreeOrMain();
Copy link
Contributor Author

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?

@@ -150,6 +150,21 @@ public string GetDotGitDirectory()
return dotGitDirectory;
}

public string GetDotGitDirectoryOfMain()
{
var dotGitDir = GetDotGitDirectoryOfWorktreeOrMain();
Copy link
Member

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?


public string GetDotGitDirectory()
{
return GetDotGitDirectoryOfMain();
Copy link
Member

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.

@arturcic
Copy link
Member

arturcic commented Sep 5, 2019

Looks like there was an issue when running the windows azure pipeline build, but I ran it manually again and it succeeds.

Copy link
Member

@asbjornu asbjornu left a 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?

@ermshiperete
Copy link
Contributor Author

How about now?

@arturcic
Copy link
Member

arturcic commented Sep 6, 2019

@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.
@ermshiperete
Copy link
Contributor Author

@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.

@arturcic
Copy link
Member

arturcic commented Sep 6, 2019

It seems like the pipeline has some intermittent issues. I already triggered one and it succeeded

Copy link
Member

@asbjornu asbjornu left a 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?

@arturcic
Copy link
Member

arturcic commented Sep 6, 2019

I think we can merge it. There is a unit test that is randomly failing, but that is not an issue

@asbjornu asbjornu merged commit ea2a10c into GitTools:master Sep 6, 2019
@asbjornu
Copy link
Member

asbjornu commented Sep 6, 2019

Thank you so much @ermshiperete!

@arturcic arturcic added this to the 5.1.0 milestone Sep 7, 2019
@ermshiperete ermshiperete deleted the ImproveWorktree branch September 26, 2019 14:20
@chuseman chuseman mentioned this pull request Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants