1
>
/*---------------------------------------------------------------------------------------------
agentHostGitService.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 * as fsPromises from 'fs/promises';
8
>
import { cp as copyFile } from '@vscode/fs-copyfile';
9
>
import * as path from '../../../base/common/path.js';
10
>
import { URI } from '../../../base/common/uri.js';
11
>
import { VSBuffer } from '../../../base/common/buffer.js';
12
>
import { parse } from '../../../base/common/glob.js';
13
>
import { generateUuid } from '../../../base/common/uuid.js';
14
>
import { INativeEnvironmentService } from '../../environment/common/environment.js';
15
>
import { IFileService } from '../../files/common/files.js';
16
>
import { ILogService } from '../../log/common/log.js';
17
>
import { FileEditKind, type ISessionFileDiff, type ISessionGitState } from '../common/state/sessionState.js';
18
>
import { buildGitBlobUri } from './gitDiffContent.js';
19
>
import { EMPTY_TREE_OBJECT, IAgentHostGitService, IBranch, IBranchDiffSafetyInfo, IRefQuery, IComputeSessionFileDiffsOptions, IDefaultBranch, IPullOptions, IPushOptions, GitRefType, IRemoteBranch, GitRef, ITag, Branch } from '../common/agentHostGitService.js';
20
>
import { LRUCache } from '../../../base/common/map.js';
21
>
import { Limiter, SequencerByKey } from '../../../base/common/async.js';
22
>
23
>
export class AgentHostGitService implements IAgentHostGitService {
24
>
declare readonly _serviceBrand: undefined;
25
>
26
>
/**
27
>
* A cache of repository roots that have already been discovered.
28
>
*/
29
>
private readonly _repositoryRoots = new LRUCache<string, URI>(100);
30
>
private readonly _repositoryRootSequencer = new SequencerByKey<string>();
31
>
32
>
constructor(
33
@IFileService private readonly _fileService: IFileService,
34
@INativeEnvironmentService private readonly _environmentService: INativeEnvironmentService,
35
@ILogService private readonly _logService: ILogService,
36
) { }
38
>
async getCurrentBranch(workingDirectory: URI): Promise<string | undefined> {
39
return (await this._runGit(workingDirectory, ['branch', '--show-current']))?.trim()
40
|| (await this._runGit(workingDirectory, ['rev-parse', '--short', 'HEAD']))?.trim()
41
|| undefined;
42
}
44
>
async getDefaultBranch(workingDirectory: URI): Promise<IDefaultBranch | undefined> {
45
// Try to read the default branch from the remote HEAD reference
46
const remoteRef = (await this._runGit(workingDirectory, ['symbolic-ref', 'refs/remotes/origin/HEAD']))?.trim();