Path: blob/main/src/vs/workbench/contrib/chat/electron-browser/pluginGitCommandService.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CancellationToken } from '../../../../base/common/cancellation.js';6import { URI } from '../../../../base/common/uri.js';7import { generateUuid } from '../../../../base/common/uuid.js';8import { ILocalGitService } from '../../../../platform/git/common/localGitService.js';9import { IPluginGitService } from '../common/plugins/pluginGitService.js';1011/**12* Desktop implementation that always runs git locally via the shared process.13* The plugin cache is always on the local machine, so there is no need to14* delegate to the git extension (which may be running on a remote host).15*16* Cancellation tokens are mapped to operation IDs so that cancel requests17* survive the IPC boundary to the shared process (tokens don't serialise).18*/19export class NativePluginGitCommandService implements IPluginGitService {20declare readonly _serviceBrand: undefined;2122constructor(23@ILocalGitService private readonly _localGitService: ILocalGitService,24) { }2526private _withCancel<T>(token: CancellationToken | undefined, fn: (operationId: string) => Promise<T>): Promise<T> {27const operationId = generateUuid();28const listener = token?.onCancellationRequested(() => {29this._localGitService.cancel(operationId).catch(() => { /* ignore */ });30});31return fn(operationId).finally(() => listener?.dispose());32}3334async cloneRepository(cloneUrl: string, targetDir: URI, ref?: string, token?: CancellationToken): Promise<void> {35await this._withCancel(token, id => this._localGitService.clone(id, cloneUrl, targetDir.fsPath, ref));36}3738async pull(repoDir: URI, token?: CancellationToken): Promise<boolean> {39return this._withCancel(token, id => this._localGitService.pull(id, repoDir.fsPath));40}4142async checkout(repoDir: URI, treeish: string, detached?: boolean, token?: CancellationToken): Promise<void> {43await this._withCancel(token, id => this._localGitService.checkout(id, repoDir.fsPath, treeish, detached));44}4546async revParse(repoDir: URI, ref: string): Promise<string> {47return this._localGitService.revParse(repoDir.fsPath, ref);48}4950async fetch(repoDir: URI, token?: CancellationToken): Promise<void> {51await this._withCancel(token, id => this._localGitService.fetch(id, repoDir.fsPath));52}5354async fetchRepository(repoDir: URI, token?: CancellationToken): Promise<void> {55await this._withCancel(token, id => this._localGitService.fetch(id, repoDir.fsPath));56}5758async revListCount(repoDir: URI, fromRef: string, toRef: string): Promise<number> {59return this._localGitService.revListCount(repoDir.fsPath, fromRef, toRef);60}61}626364