mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
Git - dispose untrusted repositories when trust state changes (#291498)
This commit is contained in:
@@ -290,6 +290,7 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
|
||||
this._unsafeRepositoriesManager = new UnsafeRepositoriesManager();
|
||||
|
||||
workspace.onDidChangeWorkspaceFolders(this.onDidChangeWorkspaceFolders, this, this.disposables);
|
||||
workspace.onDidChangeWorkspaceTrustedFolders(this.onDidChangeWorkspaceTrustedFolders, this, this.disposables);
|
||||
window.onDidChangeVisibleTextEditors(this.onDidChangeVisibleTextEditors, this, this.disposables);
|
||||
window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, this.disposables);
|
||||
workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, this.disposables);
|
||||
@@ -488,6 +489,27 @@ export class Model implements IRepositoryResolver, IBranchProtectionProviderRegi
|
||||
}
|
||||
}
|
||||
|
||||
private async onDidChangeWorkspaceTrustedFolders(): Promise<void> {
|
||||
try {
|
||||
const openRepositoriesToDispose: OpenRepository[] = [];
|
||||
|
||||
for (const openRepository of this.openRepositories) {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
openRepositoriesToDispose.forEach(r => r.dispose());
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.warn(`[Model][onDidChangeWorkspaceTrustedFolders] Error: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
private onDidChangeConfiguration(): void {
|
||||
const possibleRepositoryFolders = (workspace.workspaceFolders || [])
|
||||
.filter(folder => workspace.getConfiguration('git', folder.uri).get<boolean>('enabled') === true)
|
||||
|
||||
Reference in New Issue
Block a user