-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixes #3090 and #2575 - Treats .git/gitdir as cwd on "empty" bare clones #3092
base: main
Are you sure you want to change the base?
Conversation
5df0c1b
to
8a0a323
Compare
fa54bdf
to
fc0ffd4
Compare
@eamodio Hello, could you please have a look at this PR? |
fc0ffd4
to
5ab5ff8
Compare
@d13 Hey sorry for the ping but could you look at this PR? Or is there someone else who can? I've been waiting for feedback for about a month now |
@d13 Still waiting for feedback on this |
5ab5ff8
to
c15d92d
Compare
@axosoft-ramint Sorry for the ping, but could I get you to look into this? I've been manually compiling the source every version to fix this issue... |
c15d92d
to
0eb5f1f
Compare
@hwangh95 Thanks! It may be a while before I get to this, but it's on my list now. |
…n "empty" bare clones There are cases for having bare clones with multiple worktrees in the same folder to manage various versions in a workspace Currently, however, the only supported way to do this is to have the .git/ files such as HEAD, branches/, refs/, worktrees/, etc in the same folder as your actual worktrees. This makes your workspace very cluttered and is counterproductive to the structured way of multiple worktrees What many of us prefer is to have an "empty" bare clone with the normal bare clone files within the .git/ folder or another folder labeled .bare and use a .git file with a gitdir reference This fix will allow for the worktrees view to function the same way it would show on a `git worktree list` command
0eb5f1f
to
ff729b7
Compare
@axosoft-ramint Are there any updates on this? |
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.
Thank you for the PR and sorry for the LONG delay here. Please test things out with the following suggestions and if it works, we should be able to get this in ASAP.
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. | |||
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). | |||
|
|||
## [Unreleased] | |||
- Fixes [#3090](https://github.com/gitkraken/vscode-gitlens/issues/3090) - Manually created empty bare clone repositories in a trusted directory crash worktree view since LocalGitProvider.findRepositoryUri returns just ".git" *and* Fixes [#2575](https://github.com/gitkraken/vscode-gitlens/issues/2575) - Existing worktrees recognized, but incorrectly organized — thanks to [PR #3092](https://github.com/gitkraken/vscode-gitlens/pull/3092) |
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.
Nit: please split into 2 "Fixes" lines
// We can assume rev_parse__git_dir will always return a value since we know we are in a repo | ||
({ commonPath: data } = (await this.rev_parse__git_dir(cwd)) as { | ||
path: string; | ||
commonPath?: string; | ||
}); | ||
|
||
// If the git dir is .git or a path pointed to by gitdir: ..., | ||
// we should treat it as an "empty" version of a bare clone | ||
// This is the case when git dir == git common dir, or when commonPath is undefined | ||
data = data ?? '.'; | ||
|
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.
Please replace this with the following (assuming it works in your testing). In my testing this seems to resolve the issue and takes advantage of the path normalization that rev_parse__git_dir
is already doing. It also avoids returning the cwd
if rev_parse__git_dir
really returns no data (which shouldn't happen), but keeps this safer.
// We can assume rev_parse__git_dir will always return a value since we know we are in a repo | |
({ commonPath: data } = (await this.rev_parse__git_dir(cwd)) as { | |
path: string; | |
commonPath?: string; | |
}); | |
// If the git dir is .git or a path pointed to by gitdir: ..., | |
// we should treat it as an "empty" version of a bare clone | |
// This is the case when git dir == git common dir, or when commonPath is undefined | |
data = data ?? '.'; | |
const result = await this.rev_parse__git_dir(cwd); | |
const repoPath = result?.commonPath ?? result?.path; | |
if (repoPath?.length) return [true, repoPath]; |
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.
Hmmm the issue is this doesn't solve the case where it's a bare clone with a .git folder and worktrees in it. Something like
repo/
repo/.git
repo/worktree1
repo/worktree2
doesn't get collapsed into one repo, but several repos with repeating worktrees. I think we should check when dotGitPath == commonDotGitPath
but I don't know if we should change rev_parse__git_dir
or just write a custom check like this
// We can assume rev_parse__git_dir will always return a value since we know we are in a repo | |
({ commonPath: data } = (await this.rev_parse__git_dir(cwd)) as { | |
path: string; | |
commonPath?: string; | |
}); | |
// If the git dir is .git or a path pointed to by gitdir: ..., | |
// we should treat it as an "empty" version of a bare clone | |
// This is the case when git dir == git common dir, or when commonPath is undefined | |
data = data ?? '.'; | |
data = await this.git<string>( | |
{ cwd: cwd, errors: GitErrorHandling.Ignore }, | |
'rev-parse', | |
'--git-dir', | |
'--git-common-dir', | |
); | |
data = data.trim(); | |
if (data.length) { | |
const [path, commonPath] = data.split('\n').map(r => r.trim()); | |
return [true, normalizePath((commonPath === '.' || commonPath === path ? cwd : commonPath).trimStart().replace(/[\r|\n]+$/, ''))]; | |
} | |
} |
Description
There are cases for having bare clones with multiple worktrees in the same folder to manage various versions in a workspace
Currently, however, the only supported way to do this is to have the .git/ files such as HEAD, branches/, refs/, worktrees/, etc in the same folder as your actual worktrees. This makes your workspace very cluttered and is counterproductive to the structured way of multiple worktrees
What many of us prefer is to have an "empty" bare clone with the normal bare clone files within the .git/ folder or another folder labeled .bare and use a .git file with a gitdir reference
This fix will allow for the worktrees view to function the same way it would show on a
git worktree list
commandChecklist
Fixes $XXX -
orCloses #XXX -
prefix to auto-close the issue that your PR addressesRefs: #3090, #2575