alefragnani / vscode-project-manager

Project Manager Extension for Visual Studio Code
GNU General Public License v3.0
1.87k stars 222 forks source link

[FEATURE] - Automatic detection of worktrees in the repository #743

Open iwdath opened 2 months ago

iwdath commented 2 months ago

When creating a worktree with GitLens, the project in the sidebar and status bar is named the same as the branch. This is because when a worktree is created, it is placed at the path repoName.worktrees/worktreeName, and its name matches the branch name.

I’m not sure how feasible this is, but it would be great if the worktree project name matched the repository name, not the branch. The repository name can be obtained from the worktree folder name, which is easy to determine as .worktrees is always indicated at the end.

The fact that the project is named after the branch can be confusing, especially when there are many different branches displayed in the sidebar, sometimes with the same names. As an alternative, the worktree project could be named in the format repoName [worktreeName] to avoid repeating project names in the sidebar.

alefragnani commented 2 months ago

Hi @iwdath ,

Could you please provide more details about your use case?

I'm not sure I did understand what the worktree name convention is causing to the projects displayed in the Side Bar. Are you talking about the projectManager.git.baseFolders setting, and the projects that the extension detects and displays in the Side Bar? If that's the case, could you please provide a screenshot of your project list?

The worktree support was added a long time ago in #134, but I never used worktree personally.

Hope this helps

iwdath commented 2 months ago

Hi @alefragnani,

Yes, perhaps I didn’t quite accurately formulate the problem. Git worktrees are displayed as projects, but their names might not be very convenient.

I checked the extension settings and found that using the projectManager.showParentFolderInfoOnDuplicates: true parameter slightly improves the situation. However, this parameter only affects the list in the sidebar, and it does not change the status bar.

In this video, I demonstrated how the extension works with two different projects, which have Git worktrees with the same name. The problem is that the project name is determined by the folder name, and if two Git worktrees have the same name, it becomes difficult to determine which project they belong to. This becomes even more difficult because the projects are sorted in alphabetical order, and in my case, as shown in the video, the Git worktrees are located at the beginning of the list, and the projects are at the end. Imagine what would happen if there were many more projects and Git worktrees.

Therefore, I suggest modifying the extension so that it “out of the box”, or when enabling a certain parameter in the extension settings, identifies Git worktrees and forms a slightly different project name for them. Now, the project name is determined by the folder name and looks like this:

angular branch-test.worktrees angular trendycookies.worktrees branch-test trendycookies

Agree, it would be much easier to understand which project the Git worktrees belong to if the list looked like this:

branch-test branch-test [angular] trendycookies trendycookies [angular]

With such an arrangement of projects, Git worktrees will always be located next to their projects, which will simplify the search for the required project.