Repository navigation
git: remove repo from SCM when workspace folder is removed - #327124
Open
Shreyash (Iitian001) wants to merge 3 commits into
Open
Shreyash (Iitian001) wants to merge 3 commits into
Shreyash (Iitian001) wants to merge 3 commits into
Conversation
When a workspace folder is removed from a multi-root workspace, the corresponding git repository was not being removed from the SCM panel. The original code used getOpenRepository(folder.uri) to find repos to dispose, which internally relies on isDescendant(repoRoot, resourcePath). This check fails when the repo root IS the workspace folder (i.e. the most common case), because a path is not a descendant of itself. Fix by iterating all open repositories and checking whether their root is equal to or a descendant of any removed workspace folder, rather than relying on the indirect URI-based lookup. Additionally, prune stale closedRepositories workspace state entries for any removed workspace folders. Without this, repos that were manually closed before the folder was removed would ghost back into the SCM panel the next time the workspace is opened. Fixes microsoft#108757
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Ladislau Szomoru (@lszomoru)Matched files:
|
Comment on lines
+484
to
+487
| const openRepositoriesToDispose = this.openRepositories | ||
| .filter(r => removed.some(folder => isDescendant(folder.uri.fsPath, r.repository.root) || r.repository.root === folder.uri.fsPath)) | ||
| .filter(r => !activeRepositories.has(r.repository)) | ||
| .filter(r => !(workspace.workspaceFolders || []).some(f => isDescendant(f.uri.fsPath, r.repository.root))); |
| for (const folder of removed) { | ||
| for (const closedRepo of this._closedRepositoriesManager.repositories) { | ||
| if (isDescendant(folder.uri.fsPath, closedRepo) || closedRepo === folder.uri.fsPath) { | ||
| this._closedRepositoriesManager.deleteRepository(closedRepo); |
Author
|
@microsoft-github-policy-service agree |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #108757
When a workspace folder is removed from a multi-root workspace, the corresponding git repository was not removed from the Source Control view.
Root cause
onDidChangeWorkspaceFolderslooked up repositories to dispose withgetOpenRepository(folder.uri), which resolves a repository containing the folder URI. That misses repositories rooted inside the removed folder and does not account for repositories opened above it (for example withgit.openRepositoryInParentFolders).Fix
The handler now walks
this.openRepositoriesand disposes a repository when its root equals, contains, or is contained by a removed workspace folder, unless:Manually closed repository markers (
closedRepositories) are intentionally left untouched, so a repository the user closed is not reopened by the follow-up scan.Testing