diff options
author | Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> | 2022-11-11 13:25:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 13:25:01 +0300 |
commit | 9984da1a19d2e2e43a4e40b2bf71076df67a45a9 (patch) | |
tree | b2d74a17b41b313bf911fe105914d7810b53742a | |
parent | c9f32595a60baa78c20028be7abd3c01c0439139 (diff) |
Git - Optimistic UI update for discarding changes (#166099)
Optimistic UI update for discarding changes
-rw-r--r-- | extensions/git/src/repository.ts | 81 |
1 files 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<void> { - 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 { |