diff --git a/src/vs/base/common/arrays.ts b/src/vs/base/common/arrays.ts index 65187b136fd825506107d3ae10348fb73a0c8b0b..3d92f2bceebaa3218944b391bb8571b44d5b9a3f 100644 --- a/src/vs/base/common/arrays.ts +++ b/src/vs/base/common/arrays.ts @@ -257,8 +257,12 @@ export function fill(num: number, valueFn: () => T, arr: T[] = []): T[] { return arr; } -export function index(array: T[], indexer: (t: T) => string): { [key: string]: T; } { - const result = Object.create(null); - array.forEach(t => result[indexer(t)] = t); - return result; +export function index(array: T[], indexer: (t: T) => string): { [key: string]: T; }; +export function index(array: T[], indexer: (t: T) => string, merger?: (t: T, r: R) => R): { [key: string]: R; }; +export function index(array: T[], indexer: (t: T) => string, merger: (t: T, r: R) => R = t => t as any): { [key: string]: R; } { + return array.reduce((r, t) => { + const key = indexer(t); + r[key] = merger(t, r[key]); + return r; + }, Object.create(null)); } \ No newline at end of file diff --git a/src/vs/workbench/parts/git/node/git.lib.ts b/src/vs/workbench/parts/git/node/git.lib.ts index d0922c2b65aebee4afe0f9ad32d2e3ec0462064b..25868a7d08210a638bb92433f7bae68cf5ac36ed 100644 --- a/src/vs/workbench/parts/git/node/git.lib.ts +++ b/src/vs/workbench/parts/git/node/git.lib.ts @@ -11,9 +11,10 @@ import * as pfs from 'vs/base/node/pfs'; import { guessMimeTypes, isBinaryMime } from 'vs/base/common/mime'; import { IDisposable, toDisposable, dispose } from 'vs/base/common/lifecycle'; import { assign } from 'vs/base/common/objects'; +import { sequence } from 'vs/base/common/async'; import { v4 as UUIDv4 } from 'vs/base/common/uuid'; import { localize } from 'vs/nls'; -import { uniqueFilter } from 'vs/base/common/arrays'; +import { uniqueFilter, index } from 'vs/base/common/arrays'; import { IRawFileStatus, RefType, IRef, IBranch, IRemote, GitErrorCodes, IPushOptions } from 'vs/workbench/parts/git/common/git'; import { detectMimesFromStream } from 'vs/base/node/mime'; import { IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files'; @@ -447,8 +448,11 @@ export class Repository { } clean(paths: string[]): Promise { - const args = [ 'clean', '-f', '-q', '--' ].concat(paths); - return this.run(args); + const byDirname = index(paths, p => path.dirname(p), (p, r) => (r || []).concat([p])); + const groups = Object.keys(byDirname).map(key => byDirname[key]); + const tasks = groups.map(group => () => this.run([ 'clean', '-f', '-q', '--' ].concat(group))); + + return sequence(tasks); } undo(): Promise {