diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index e06ef71489c..1d748fa750e 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -1231,12 +1231,8 @@ export class Repository implements Disposable { } async add(resources: Uri[], opts?: { update?: boolean }): Promise { - const config = workspace.getConfiguration('git', Uri.file(this.root)); - const optimisticUpdate = config.get('optimisticUpdate') === true; - const operation = optimisticUpdate ? Operation.AddNoProgress : Operation.Add; - await this.run( - operation, + this.optimisticUpdateEnabled() ? Operation.AddNoProgress : Operation.Add, async () => { await this.repository.add(resources.map(r => r.fsPath), opts); this.closeDiffEditors([], [...resources.map(r => r.fsPath)]); @@ -1286,12 +1282,8 @@ export class Repository implements Disposable { } async revert(resources: Uri[]): Promise { - const config = workspace.getConfiguration('git', Uri.file(this.root)); - const optimisticUpdate = config.get('optimisticUpdate') === true; - const operation = optimisticUpdate ? Operation.RevertFilesNoProgress : Operation.RevertFiles; - await this.run( - operation, + this.optimisticUpdateEnabled() ? Operation.RevertFilesNoProgress : Operation.RevertFiles, async () => { await this.repository.revert('HEAD', resources.map(r => r.fsPath)); this.closeDiffEditors([...resources.length !== 0 ? @@ -1401,12 +1393,8 @@ export class Repository implements Disposable { } async clean(resources: Uri[]): Promise { - const config = workspace.getConfiguration('git', Uri.file(this.root)); - const optimisticUpdate = config.get('optimisticUpdate') === true; - const operation = optimisticUpdate ? Operation.CleanNoProgress : Operation.Clean; - await this.run( - operation, + this.optimisticUpdateEnabled() ? Operation.CleanNoProgress : Operation.Clean, async () => { const toClean: string[] = []; const toCheckout: string[] = []; @@ -2016,10 +2004,7 @@ export class Repository implements Disposable { const result = await this.retryRun(operation, runOperation); if (!isReadOnly(operation)) { - const scopedConfig = workspace.getConfiguration('git', Uri.file(this.repository.root)); - const optimisticUpdate = scopedConfig.get('optimisticUpdate') === true; - - await this.updateModelState(optimisticUpdate ? getOptimisticResourceGroups() : undefined); + await this.updateModelState(this.optimisticUpdateEnabled() ? getOptimisticResourceGroups() : undefined); } return result; @@ -2481,6 +2466,11 @@ export class Repository implements Disposable { } } + private optimisticUpdateEnabled(): boolean { + const config = workspace.getConfiguration('git', Uri.file(this.root)); + return config.get('optimisticUpdate') === true; + } + public isBranchProtected(name: string = this.HEAD?.name ?? ''): boolean { return this.isBranchProtectedMatcher ? this.isBranchProtectedMatcher(name) : false; }