1
>
/*---------------------------------------------------------------------------------------------
localGitService.ts
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 * as cp from 'child_process';
7
>
import { CancellationError } from '../../../base/common/errors.js';
8
>
import { generateUuid } from '../../../base/common/uuid.js';
9
>
import { IGitPullOptions, ILocalGitService } from '../common/localGitService.js';
10
>
import { ILogService } from '../../log/common/log.js';
11
>
12
>
export class LocalGitService implements ILocalGitService {
13
>
declare readonly _serviceBrand: undefined;
14
>
15
>
private _runningProcesses = new Map<string, cp.ChildProcess>();
16
>
17
>
constructor(
18
>
@ILogService private readonly _logService: ILogService,
19
>
private readonly _execFile: typeof cp.execFile = cp.execFile,
20
>
) { }
21
>
22
>
private _exec(operationId: string, args: string[], cwd?: string): Promise<string> {
23
>
return new Promise((resolve, reject) => {
24
>
this._logService.trace(`[LocalGitService] git ${args.join(' ')}${cwd ? ` (cwd: ${cwd})` : ''}`);
25
>
const proc = this._execFile('git', args, { cwd, encoding: 'utf8' }, (err, stdout, stderr) => {
26
>
if (!this._runningProcesses.delete(operationId)) {
27
reject(new CancellationError());
28
return;
29
}
31
this._logService.error(`[LocalGitService] git ${args[0]} failed:`, err.message, stderr);
32
reject(err);
33
return;
34
}
36
>
});
37
>
38
>
this._runningProcesses.set(operationId, proc);
39
>
});
40
>
}
41
>
42
>
async clone(operationId: string, cloneUrl: string, targetPath: string, ref?: string): Promise<void> {
43
const args = ['clone'];
44
if (ref) {