diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 706c0acd0d2ff0dfb17c4e4e6a41b34d9ca20ca4..723cde0ed7d7154471f7352af42d0392548a3746 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -1212,9 +1212,27 @@ export class Repository implements Disposable { } } + private static KnownHugeFolderNames = ['node_modules']; + + private async findKnownHugeFolderPathsToIgnore(): Promise { + const folderPaths: string[] = []; + + for (const folderName of Repository.KnownHugeFolderNames) { + const folderPath = path.join(this.repository.root, folderName); + + if (await new Promise(c => fs.exists(folderPath, c))) { + folderPaths.push(folderPath); + } + } + + const ignored = await this.checkIgnore(folderPaths); + + return folderPaths.filter(p => !ignored.has(p)); + } + @throttle private async updateModelState(): Promise { - const { status, didHitLimit } = await this.repository.getStatus(); + const { status, didHitLimit } = await this.repository.getStatus(100); const config = workspace.getConfiguration('git'); const shouldIgnore = config.get('ignoreLimitWarning') === true; const useIcons = !config.get('decorations.enabled', true); @@ -1222,15 +1240,34 @@ export class Repository implements Disposable { this.isRepositoryHuge = didHitLimit; if (didHitLimit && !shouldIgnore && !this.didWarnAboutLimit) { + const knownHugeFolderPaths = await this.findKnownHugeFolderPathsToIgnore(); + const gitWarn = localize('huge', "The git repository at '{0}' has too many active changes, only a subset of Git features will be enabled.", this.repository.root); const neverAgain = { title: localize('neveragain', "Don't Show Again") }; - window.showWarningMessage(localize('huge', "The git repository at '{0}' has too many active changes, only a subset of Git features will be enabled.", this.repository.root), neverAgain).then(result => { + if (knownHugeFolderPaths.length > 0) { + const folderPath = knownHugeFolderPaths[0]; + const folderName = path.basename(folderPath); + + const addKnown = localize('add known', "Would you like to add '{0}' to .gitignore?", folderName); + const yes = { title: localize('yes', "Yes") }; + + const result = await window.showWarningMessage(`${gitWarn} ${addKnown}`, yes, neverAgain); + if (result === neverAgain) { config.update('ignoreLimitWarning', true, false); + this.didWarnAboutLimit = true; + } else if (result === yes) { + this.ignore([Uri.file(folderPath)]); } - }); + } else { + const result = await window.showWarningMessage(gitWarn, neverAgain); - this.didWarnAboutLimit = true; + if (result === neverAgain) { + config.update('ignoreLimitWarning', true, false); + } + + this.didWarnAboutLimit = true; + } } let HEAD: Branch | undefined;