Skip to content

Commit b0934b0

Browse files
committed
Avoids stale promise grouping on git change
1 parent 05f70b8 commit b0934b0

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

src/env/browser/providers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import type { SharedGkStorageLocationProvider } from '../../plus/repos/sharedGkS
99
import type { GkWorkspacesSharedStorageProvider } from '../../plus/workspaces/workspacesSharedStorageProvider';
1010
import type { GitResult } from '../node/git/git';
1111

12-
export function git(_options: GitCommandOptions, ..._args: any[]): Promise<GitResult<string | Buffer>> {
12+
export function git(
13+
_container: Container,
14+
_options: GitCommandOptions,
15+
..._args: any[]
16+
): Promise<GitResult<string | Buffer>> {
1317
return Promise.resolve({ stdout: '', exitCode: 0 });
1418
}
1519

src/env/node/git/git.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { CancellationToken, Disposable, OutputChannel } from 'vscode';
77
import { env, Uri, window, workspace } from 'vscode';
88
import { hrtime } from '@env/hrtime';
99
import { GlyphChars } from '../../../constants';
10+
import type { Container } from '../../../container';
1011
import { CancellationError, isCancellationError } from '../../../errors';
1112
import type { FilteredGitFeatures, GitFeatureOrPrefix, GitFeatures } from '../../../features';
1213
import { gitFeaturesByVersion } from '../../../features';
@@ -232,10 +233,24 @@ export type GitResult<T extends string | Buffer | unknown> = {
232233
readonly cancelled?: boolean;
233234
};
234235

235-
export class Git {
236+
export class Git implements Disposable {
237+
private readonly _disposable: Disposable;
236238
/** Map of running git commands -- avoids running duplicate overlaping commands */
237239
private readonly pendingCommands = new Map<string, Promise<RunResult<string | Buffer>>>();
238240

241+
constructor(container: Container) {
242+
this._disposable = container.events.on('git:cache:reset', e => {
243+
// Ignore provider resets (e.g. it needs to be git specific)
244+
if (e.data.types?.every(t => t === 'providers')) return;
245+
246+
this.pendingCommands.clear();
247+
});
248+
}
249+
250+
dispose(): void {
251+
this._disposable.dispose();
252+
}
253+
239254
async exec(
240255
options: ExitCodeOnlyGitCommandOptions,
241256
...args: readonly (string | undefined)[]

src/env/node/git/vslsGitProvider.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ import { Git } from './git';
1313
import { LocalGitProvider } from './localGitProvider';
1414

1515
export class VslsGit extends Git {
16-
constructor(private readonly localGit: Git) {
17-
super();
16+
constructor(
17+
container: Container,
18+
private readonly localGit: Git,
19+
) {
20+
super(container);
1821
}
1922

2023
override async exec<T extends string | Buffer>(options: GitCommandOptions, ...args: any[]): Promise<GitResult<T>> {

src/env/node/providers.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@ import { LocalSharedGkStorageLocationProvider } from './gk/localSharedGkStorageL
1616
import { LocalGkWorkspacesSharedStorageProvider } from './gk/localWorkspacesSharedStorageProvider';
1717

1818
let gitInstance: Git | undefined;
19-
function ensureGit() {
20-
if (gitInstance == null) {
21-
gitInstance = new Git();
22-
}
19+
function ensureGit(container: Container) {
20+
gitInstance ??= new Git(container);
2321
return gitInstance;
2422
}
2523

26-
export function git(options: GitCommandOptions, ...args: any[]): Promise<GitResult<string | Buffer>> {
27-
return ensureGit().exec(options, ...args);
24+
export function git(
25+
container: Container,
26+
options: GitCommandOptions,
27+
...args: any[]
28+
): Promise<GitResult<string | Buffer>> {
29+
return ensureGit(container).exec(options, ...args);
2830
}
2931

3032
export async function getSupportedGitProviders(container: Container): Promise<GitProvider[]> {
31-
const git = ensureGit();
33+
const git = ensureGit(container);
3234

3335
const providers: GitProvider[] = [
3436
new LocalGitProvider(container, git),
35-
new VslsGitProvider(container, new VslsGit(git)),
37+
new VslsGitProvider(container, new VslsGit(container, git)),
3638
];
3739

3840
if (configuration.get('virtualRepositories.enabled')) {

src/vsls/host.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export class VslsHostService implements Disposable {
151151
const [cwd, isRootWorkspace] = this.convertGitCommandCwd(options.cwd);
152152

153153
const result = await git(
154+
this.container,
154155
{ ...options, cwd: cwd, cancellation: cancellation },
155156
...this.convertGitCommandArgs(args, isRootWorkspace),
156157
);

0 commit comments

Comments
 (0)