Path: blob/main/src/vs/workbench/contrib/git/common/gitService.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 { IDisposable } from '../../../../base/common/lifecycle.js';7import { IObservable } from '../../../../base/common/observable.js';8import { URI } from '../../../../base/common/uri.js';9import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';1011export enum GitRefType {12Head,13RemoteHead,14Tag15}1617export interface GitRef {18readonly type: GitRefType;19readonly name?: string;20readonly commit?: string;21readonly remote?: string;22}2324export interface GitRefQuery {25readonly contains?: string;26readonly count?: number;27readonly pattern?: string | string[];28readonly sort?: 'alphabetically' | 'committerdate' | 'creatordate';29}3031export interface GitChange {32readonly uri: URI;33readonly originalUri: URI | undefined;34readonly modifiedUri: URI | undefined;35}3637export interface GitDiffChange extends GitChange {38readonly insertions: number;39readonly deletions: number;40}4142export interface GitRemote {43readonly name: string;44readonly fetchUrl?: string;45readonly pushUrl?: string;46readonly isReadOnly: boolean;47}4849export interface GitRepositoryState {50readonly HEAD?: GitBranch;51readonly remotes: readonly GitRemote[];52readonly mergeChanges: readonly GitChange[];53readonly indexChanges: readonly GitChange[];54readonly workingTreeChanges: readonly GitChange[];55readonly untrackedChanges: readonly GitChange[];56}5758export interface GitBranch extends GitRef {59readonly upstream?: GitUpstreamRef;60readonly ahead?: number;61readonly behind?: number;62}6364export interface GitBaseRef {65readonly name: string;66readonly isProtected: boolean;67}6869export interface GitUpstreamRef {70readonly remote: string;71readonly name: string;72readonly commit?: string;73}7475export interface IGitRepository {76readonly rootUri: URI;7778readonly state: IObservable<GitRepositoryState>;79updateState(state: GitRepositoryState): void;8081getRefs(query: GitRefQuery, token?: CancellationToken): Promise<GitRef[]>;82diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise<GitDiffChange[]>;83diffBetweenWithStats2(ref: string, path?: string): Promise<GitDiffChange[]>;84}8586export interface IGitExtensionDelegate {87readonly repositories: Iterable<IGitRepository>;88openRepository(uri: URI): Promise<IGitRepository | undefined>;8990getRefs(root: URI, query?: GitRefQuery, token?: CancellationToken): Promise<GitRef[]>;91diffBetweenWithStats(root: URI, ref1: string, ref2: string, path?: string): Promise<GitDiffChange[]>;92diffBetweenWithStats2(root: URI, ref: string, path?: string): Promise<GitDiffChange[]>;93}9495export const IGitService = createDecorator<IGitService>('gitService');9697export interface IGitService {98readonly _serviceBrand: undefined;99100readonly repositories: Iterable<IGitRepository>;101102setDelegate(delegate: IGitExtensionDelegate): IDisposable;103104openRepository(uri: URI): Promise<IGitRepository | undefined>;105}106107108