diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 6d6dce2..eeb69e9 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -34,6 +34,7 @@ import { count, filter, first, flatMap, join, map, some } from '../system/iterab import { Logger } from '../system/logger'; import { getLogScope, setLogScopeExit } from '../system/logger.scope'; import { getBestPath, getScheme, isAbsolute, maybeUri, normalizePath } from '../system/path'; +import type { Deferred } from '../system/promise'; import { asSettled, cancellable, defer, getSettledValue, isPromise, PromiseCancelledError } from '../system/promise'; import { sortCompare } from '../system/string'; import { VisitedPathsTrie } from '../system/trie'; @@ -212,12 +213,14 @@ export class GitProviderService implements Disposable { Promise[]> >(); private readonly _disposable: Disposable; + private _initializingDeferred: Deferred | undefined; private readonly _pendingRepositories = new Map>(); private readonly _providers = new Map(); private readonly _repositories = new Repositories(); private readonly _visitedPaths = new VisitedPathsTrie(); constructor(private readonly container: Container) { + this._initializingDeferred = defer(); this._disposable = Disposable.from( container.subscription.onDidChange(this.onSubscriptionChanged, this), window.onDidChangeWindowState(this.onWindowStateChanged, this), @@ -615,7 +618,7 @@ export class GitProviderService implements Disposable { this._isDiscoveringRepositories = undefined; } - const deferred = defer(); + const deferred = this._initializingDeferred ?? defer(); this._isDiscoveringRepositories = deferred.promise; try { @@ -657,7 +660,12 @@ export class GitProviderService implements Disposable { queueMicrotask(() => this.fireRepositoriesChanged(added)); } } finally { - queueMicrotask(() => deferred.fulfill(this._etag)); + queueMicrotask(() => { + deferred.fulfill(this._etag); + if (this._initializingDeferred != null) { + this._initializingDeferred = undefined; + } + }); } }