Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/electron-browser/pluginGitCommandService.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { CancellationToken } from '../../../../base/common/cancellation.js';
7
import { URI } from '../../../../base/common/uri.js';
8
import { generateUuid } from '../../../../base/common/uuid.js';
9
import { ILocalGitService } from '../../../../platform/git/common/localGitService.js';
10
import { IPluginGitService } from '../common/plugins/pluginGitService.js';
11
12
/**
13
* Desktop implementation that always runs git locally via the shared process.
14
* The plugin cache is always on the local machine, so there is no need to
15
* delegate to the git extension (which may be running on a remote host).
16
*
17
* Cancellation tokens are mapped to operation IDs so that cancel requests
18
* survive the IPC boundary to the shared process (tokens don't serialise).
19
*/
20
export class NativePluginGitCommandService implements IPluginGitService {
21
declare readonly _serviceBrand: undefined;
22
23
constructor(
24
@ILocalGitService private readonly _localGitService: ILocalGitService,
25
) { }
26
27
private _withCancel<T>(token: CancellationToken | undefined, fn: (operationId: string) => Promise<T>): Promise<T> {
28
const operationId = generateUuid();
29
const listener = token?.onCancellationRequested(() => {
30
this._localGitService.cancel(operationId).catch(() => { /* ignore */ });
31
});
32
return fn(operationId).finally(() => listener?.dispose());
33
}
34
35
async cloneRepository(cloneUrl: string, targetDir: URI, ref?: string, token?: CancellationToken): Promise<void> {
36
await this._withCancel(token, id => this._localGitService.clone(id, cloneUrl, targetDir.fsPath, ref));
37
}
38
39
async pull(repoDir: URI, token?: CancellationToken): Promise<boolean> {
40
return this._withCancel(token, id => this._localGitService.pull(id, repoDir.fsPath));
41
}
42
43
async checkout(repoDir: URI, treeish: string, detached?: boolean, token?: CancellationToken): Promise<void> {
44
await this._withCancel(token, id => this._localGitService.checkout(id, repoDir.fsPath, treeish, detached));
45
}
46
47
async revParse(repoDir: URI, ref: string): Promise<string> {
48
return this._localGitService.revParse(repoDir.fsPath, ref);
49
}
50
51
async fetch(repoDir: URI, token?: CancellationToken): Promise<void> {
52
await this._withCancel(token, id => this._localGitService.fetch(id, repoDir.fsPath));
53
}
54
55
async fetchRepository(repoDir: URI, token?: CancellationToken): Promise<void> {
56
await this._withCancel(token, id => this._localGitService.fetch(id, repoDir.fsPath));
57
}
58
59
async revListCount(repoDir: URI, fromRef: string, toRef: string): Promise<number> {
60
return this._localGitService.revListCount(repoDir.fsPath, fromRef, toRef);
61
}
62
}
63
64