From 9984da1a19d2e2e43a4e40b2bf71076df67a45a9 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Fri, 11 Nov 2022 11:25:01 +0100 Subject: Git - Optimistic UI update for discarding changes (#166099) Optimistic UI update for discarding changes --- extensions/git/src/repository.ts | 81 ++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 8c5464b6aa8..ef7977ae46d 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -1387,47 +1387,62 @@ export class Repository implements Disposable { } async clean(resources: Uri[]): Promise { - await this.run(Operation.Clean, async () => { - const toClean: string[] = []; - const toCheckout: string[] = []; - const submodulesToUpdate: string[] = []; - const resourceStates = [...this.workingTreeGroup.resourceStates, ...this.untrackedGroup.resourceStates]; - - resources.forEach(r => { - const fsPath = r.fsPath; - - for (const submodule of this.submodules) { - if (path.join(this.root, submodule.path) === fsPath) { - submodulesToUpdate.push(fsPath); + await this.run( + Operation.Clean, + async () => { + const toClean: string[] = []; + const toCheckout: string[] = []; + const submodulesToUpdate: string[] = []; + const resourceStates = [...this.workingTreeGroup.resourceStates, ...this.untrackedGroup.resourceStates]; + + resources.forEach(r => { + const fsPath = r.fsPath; + + for (const submodule of this.submodules) { + if (path.join(this.root, submodule.path) === fsPath) { + submodulesToUpdate.push(fsPath); + return; + } + } + + const raw = r.toString(); + const scmResource = find(resourceStates, sr => sr.resourceUri.toString() === raw); + + if (!scmResource) { return; } - } - const raw = r.toString(); - const scmResource = find(resourceStates, sr => sr.resourceUri.toString() === raw); + switch (scmResource.type) { + case Status.UNTRACKED: + case Status.IGNORED: + toClean.push(fsPath); + break; - if (!scmResource) { - return; - } + default: + toCheckout.push(fsPath); + break; + } + }); - switch (scmResource.type) { - case Status.UNTRACKED: - case Status.IGNORED: - toClean.push(fsPath); - break; + await this.repository.clean(toClean); + await this.repository.checkout('', toCheckout); + await this.repository.updateSubmodules(submodulesToUpdate); - default: - toCheckout.push(fsPath); - break; - } - }); + this.closeDiffEditors([], [...toClean, ...toCheckout]); + }, + () => { + const resourcePaths = resources.map(r => r.fsPath); + + // Remove resource(s) from working group + const workingTreeGroup = this.workingTreeGroup.resourceStates + .filter(r => !resourcePaths.includes(r.resourceUri.fsPath)); - await this.repository.clean(toClean); - await this.repository.checkout('', toCheckout); - await this.repository.updateSubmodules(submodulesToUpdate); + // Remove resource(s) from untracked group + const untrackedGroup = this.untrackedGroup.resourceStates + .filter(r => !resourcePaths.includes(r.resourceUri.fsPath)); - this.closeDiffEditors([], [...toClean, ...toCheckout]); - }); + return { workingTreeGroup, untrackedGroup }; + }); } closeDiffEditors(indexResources: string[] | undefined, workingTreeResources: string[] | undefined, ignoreSetting: boolean = false): void { -- cgit v1.2.3