-
Notifications
You must be signed in to change notification settings - Fork 37.9k
Git - dispose untrusted repositories when trust state changes #291498
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.
Pull request overview
This PR ensures Git repositories are disposed when workspace trust configuration changes, preventing repositories from remaining active after becoming untrusted.
Changes:
- Subscribes the Git model to workspace trusted-folder change events.
- Adds logic to detect repositories that are no longer trusted and dispose them.
| const dotGitPath = openRepository.repository.dotGit.commonPath ?? openRepository.repository.dotGit.path; | ||
| const isTrusted = await workspace.isResourceTrusted(Uri.file(path.dirname(dotGitPath))); | ||
|
|
||
| if (!isTrusted) { | ||
| openRepositoriesToDispose.push(openRepository); | ||
| this.logger.trace(`[Model][onDidChangeWorkspaceTrustedFolders] Repository is no longer trusted: ${openRepository.repository.root}`); | ||
| } | ||
| } |
Copilot
AI
Jan 29, 2026
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.
Trust is being evaluated against path.dirname(dotGitPath) where dotGitPath prefers repository.dotGit.commonPath. For worktrees, commonPath points at the main repo’s .git directory (see extensions/git/src/repository.ts:941-945), which can be outside the worktree folder. This can incorrectly dispose a trusted worktree (or keep an untrusted worktree) because you’re not checking the repository working tree location.
Instead, check trust for the repository root (e.g. workspace.isResourceTrusted(Uri.file(openRepository.repository.root))) so the trust decision matches the repository the user has open.
| const dotGitPath = openRepository.repository.dotGit.commonPath ?? openRepository.repository.dotGit.path; | |
| const isTrusted = await workspace.isResourceTrusted(Uri.file(path.dirname(dotGitPath))); | |
| if (!isTrusted) { | |
| openRepositoriesToDispose.push(openRepository); | |
| this.logger.trace(`[Model][onDidChangeWorkspaceTrustedFolders] Repository is no longer trusted: ${openRepository.repository.root}`); | |
| } | |
| } | |
| const isTrusted = await workspace.isResourceTrusted(Uri.file(openRepository.repository.root)); | |
| if (!isTrusted) { | |
| openRepositoriesToDispose.push(openRepository); | |
| this.logger.trace(`[Model][onDidChangeWorkspaceTrustedFolders] Repository is no longer trusted: ${openRepository.repository.root}`); | |
| } | |
| } | |
| } |
Fixes https://github.com/microsoft/vscode-internalbacklog/issues/6659