Add setting to control repository scan

This commit is contained in:
Ladislau Szomoru 2022-01-26 20:07:00 +01:00
parent 4c76c01e08
commit c32b9a6114
No known key found for this signature in database
GPG key ID: 2B88287CB9DB080B
3 changed files with 20 additions and 5 deletions

View file

@ -2229,6 +2229,17 @@
"description": "%config.experimental.installGuide%",
"default": "default"
},
"git.repositoryScanIgnoredFolders": {
"type": "array",
"items": {
"type": "string"
},
"default": [
"node_modules"
],
"scope": "resource",
"markdownDescription": "%config.repositoryScanIgnoredFolders%"
},
"git.repositoryScanMaxDepth": {
"type": "number",
"scope": "resource",

View file

@ -195,6 +195,7 @@
"config.showUnpublishedCommitsButton.never": "Never shows the action button.",
"config.statusLimit": "Controls how to limit the number of changes that can be parsed from Git status command. Can be set to 0 for no limit.",
"config.experimental.installGuide": "Experimental improvements for the git setup flow.",
"config.repositoryScanIgnoredFolders": "List of folders that are ignored while scanning for Git repositories when `#git.autoRepositoryDetection#` is set to `true` or `subFolders`.",
"config.repositoryScanMaxDepth": "Controls the depth used when scanning workspace folders for Git repositories when `#git.autoRepositoryDetection#` is set to `true` or `subFolders`. Can be set to `-1` for no limit.",
"submenu.explorer": "Git",
"submenu.commit": "Commit",

View file

@ -142,12 +142,10 @@ export class Model implements IRemoteSourcePublisherRegistry, IPushErrorHandlerR
private async scanWorkspaceFolders(): Promise<void> {
const config = workspace.getConfiguration('git');
const autoRepositoryDetection = config.get<boolean | 'subFolders' | 'openEditors'>('autoRepositoryDetection');
const repositoryScanMaxDepth = config.get<number>('repositoryScanMaxDepth', 1);
// Log repository scan settings
if (Log.logLevel <= LogLevel.Trace) {
this.outputChannel.appendLine(`${logTimestamp()} Trace: autoRepositoryDetection="${autoRepositoryDetection}"`);
this.outputChannel.appendLine(`${logTimestamp()} Trace: repositoryScanMaxDepth=${repositoryScanMaxDepth}`);
}
if (autoRepositoryDetection !== true && autoRepositoryDetection !== 'subFolders') {
@ -158,7 +156,10 @@ export class Model implements IRemoteSourcePublisherRegistry, IPushErrorHandlerR
const root = folder.uri.fsPath;
// Workspace folder children
const subfolders = new Set(await this.traverseWorkspaceFolder(root, repositoryScanMaxDepth));
const repositoryScanMaxDepth = (workspace.isTrusted ? workspace.getConfiguration('git', folder.uri) : config).get<number>('repositoryScanMaxDepth', 1);
const repositoryScanIgnoredFolders = (workspace.isTrusted ? workspace.getConfiguration('git', folder.uri) : config).get<string[]>('repositoryScanIgnoredFolders', []);
const subfolders = new Set(await this.traverseWorkspaceFolder(root, repositoryScanMaxDepth, repositoryScanIgnoredFolders));
// Repository scan folders
const scanPaths = (workspace.isTrusted ? workspace.getConfiguration('git', folder.uri) : config).get<string[]>('scanRepositories') || [];
@ -179,7 +180,7 @@ export class Model implements IRemoteSourcePublisherRegistry, IPushErrorHandlerR
}));
}
private async traverseWorkspaceFolder(workspaceFolder: string, maxDepth: number): Promise<string[]> {
private async traverseWorkspaceFolder(workspaceFolder: string, maxDepth: number, repositoryScanIgnoredFolders: string[]): Promise<string[]> {
const result: string[] = [];
const foldersToTravers = [{ path: workspaceFolder, depth: 0 }];
@ -189,7 +190,9 @@ export class Model implements IRemoteSourcePublisherRegistry, IPushErrorHandlerR
if (currentFolder.depth < maxDepth || maxDepth === -1) {
const children = await fs.promises.readdir(currentFolder.path, { withFileTypes: true });
const childrenFolders = children
.filter(dirent => dirent.isDirectory() && dirent.name !== '.git')
.filter(dirent =>
dirent.isDirectory() && dirent.name !== '.git' &&
!repositoryScanIgnoredFolders.find(f => pathEquals(dirent.name, f)))
.map(dirent => path.join(currentFolder.path, dirent.name));
result.push(...childrenFolders);