Git - dispose untrusted repositories when trust state changes (#291498)

This commit is contained in:
Ladislau Szomoru
2026-01-29 09:12:59 +01:00
committed by GitHub
parent 52c040f24c
commit e4e61e5ffa

View File

@@ -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)