/** * VS Code Git Extension API type definitions * Based on the vscode.git extension API * @see https://github.com/microsoft/vscode/blob/main/extensions/git/src/api/git.d.ts */ import type { Uri, Event, Disposable } from 'vscode'; export interface Git { readonly path: string; } export interface InputBox { value: string; } export const enum ForcePushMode { Force, ForceWithLease, ForceWithLeaseIfIncludes, } export const enum RefType { Head, RemoteHead, Tag, } export interface Ref { readonly type: RefType; readonly name?: string; readonly commit?: string; readonly remote?: string; } export interface UpstreamRef { readonly remote: string; readonly name: string; } export interface Branch extends Ref { readonly upstream?: UpstreamRef; readonly ahead?: number; readonly behind?: number; } export interface Commit { readonly hash: string; readonly message: string; readonly parents: string[]; readonly authorDate?: Date; readonly authorName?: string; readonly authorEmail?: string; readonly commitDate?: Date; } export interface Submodule { readonly name: string; readonly path: string; readonly url: string; } export interface Remote { readonly name: string; readonly fetchUrl?: string; readonly pushUrl?: string; readonly isReadOnly: boolean; } export const enum Status { INDEX_MODIFIED, INDEX_ADDED, INDEX_DELETED, INDEX_RENAMED, INDEX_COPIED, MODIFIED, DELETED, UNTRACKED, IGNORED, INTENT_TO_ADD, INTENT_TO_RENAME, TYPE_CHANGED, ADDED_BY_US, ADDED_BY_THEM, DELETED_BY_US, DELETED_BY_THEM, BOTH_ADDED, BOTH_DELETED, BOTH_MODIFIED, } export interface Change { readonly uri: Uri; readonly originalUri: Uri; readonly renameUri: Uri | undefined; readonly status: Status; } export interface RepositoryState { readonly HEAD: Branch | undefined; readonly refs: Ref[]; readonly remotes: Remote[]; readonly submodules: Submodule[]; readonly rebaseCommit: Commit | undefined; readonly mergeChanges: Change[]; readonly indexChanges: Change[]; readonly workingTreeChanges: Change[]; readonly onDidChange: Event; } export interface RepositoryUIState { readonly selected: boolean; readonly onDidChange: Event; } export interface CommitOptions { all?: boolean | 'tracked'; amend?: boolean; signoff?: boolean; signCommit?: boolean; empty?: boolean; noVerify?: boolean; requireUserConfig?: boolean; useEditor?: boolean; verbose?: boolean; postCommitCommand?: string | null; } export interface FetchOptions { remote?: string; ref?: string; all?: boolean; prune?: boolean; depth?: number; } export interface BranchQuery { readonly remote?: boolean; readonly pattern?: string; readonly count?: number; readonly contains?: string; readonly sort?: 'alphabetically' | 'committerdate'; } export interface LogOptions { readonly maxEntries?: number; readonly path?: string; readonly reverse?: boolean; readonly sortByAuthorDate?: boolean; readonly shortStats?: boolean; readonly range?: string; } export interface Repository { readonly rootUri: Uri; readonly inputBox: InputBox; readonly state: RepositoryState; readonly ui: RepositoryUIState; getConfigs(): Promise<{ key: string; value: string }[]>; getConfig(key: string): Promise; setConfig(key: string, value: string): Promise; getGlobalConfig(key: string): Promise; getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }>; detectObjectType(object: string): Promise<{ mimetype: string; encoding?: string }>; buffer(ref: string, path: string): Promise; show(ref: string, path: string): Promise; getCommit(ref: string): Promise; add(paths: string[]): Promise; revert(paths: string[]): Promise; clean(paths: string[]): Promise; apply(patch: string, reverse?: boolean): Promise; diff(cached?: boolean): Promise; diffWithHEAD(): Promise; diffWithHEAD(path: string): Promise; diffWith(ref: string): Promise; diffWith(ref: string, path: string): Promise; diffIndexWithHEAD(): Promise; diffIndexWithHEAD(path: string): Promise; diffIndexWith(ref: string): Promise; diffIndexWith(ref: string, path: string): Promise; diffBlobs(object1: string, object2: string): Promise; diffBetween(ref1: string, ref2: string): Promise; diffBetween(ref1: string, ref2: string, path: string): Promise; hashObject(data: string): Promise; createBranch(name: string, checkout: boolean, ref?: string): Promise; deleteBranch(name: string, force?: boolean): Promise; getBranch(name: string): Promise; getBranches(query: BranchQuery): Promise; getBranchBase(name: string): Promise; setBranchUpstream(name: string, upstream: string): Promise; getRefs(query: { contains?: string; count?: number; pattern?: string; sort?: 'alphabetically' | 'committerdate' }): Promise; getMergeBase(ref1: string, ref2: string): Promise; tag(name: string, upstream: string): Promise; deleteTag(name: string): Promise; status(): Promise; checkout(treeish: string): Promise; addRemote(name: string, url: string): Promise; removeRemote(name: string): Promise; renameRemote(name: string, newName: string): Promise; fetch(options?: FetchOptions): Promise; fetch(remote?: string, ref?: string, depth?: number): Promise; pull(unshallow?: boolean): Promise; push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise; blame(path: string): Promise; log(options?: LogOptions): Promise; commit(message: string, opts?: CommitOptions): Promise; } export interface RemoteSource { readonly name: string; readonly description?: string; readonly url: string | string[]; } export interface RemoteSourceProvider { readonly name: string; readonly icon?: string; readonly supportsQuery?: boolean; getRemoteSources(query?: string): Promise; getBranches?(url: string): Promise; publishRepository?(repository: Repository): Promise; } export interface RemoteSourcePublisher { readonly name: string; readonly icon?: string; publishRepository(repository: Repository): Promise; } export interface Credentials { readonly username: string; readonly password: string; } export interface CredentialsProvider { getCredentials(host: Uri): Promise; } export interface PostCommitCommandsProvider { getCommands(repository: Repository): Promise>; } export interface PushErrorHandler { handlePushError(repository: Repository, remote: Remote, refspec: string, error: Error & { gitErrorCode?: string }): Promise; } export interface BranchProtection { readonly remote: string; readonly rules: BranchProtectionRule[]; } export interface BranchProtectionRule { readonly include?: string[]; readonly exclude?: string[]; } export interface BranchProtectionProvider { onDidChangeBranchProtection: Event; provideBranchProtection(): Promise; } export type APIState = 'uninitialized' | 'initialized'; export interface PublishEvent { repository: Repository; branch?: string; } export interface API { readonly state: APIState; readonly onDidChangeState: Event; readonly onDidPublish: Event; readonly git: Git; readonly repositories: Repository[]; readonly onDidOpenRepository: Event; readonly onDidCloseRepository: Event; toGitUri(uri: Uri, ref: string): Uri; getRepository(uri: Uri): Repository | null; init(root: Uri): Promise; openRepository(root: Uri): Promise; registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable; registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable; registerCredentialsProvider(provider: CredentialsProvider): Disposable; registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable; registerPushErrorHandler(handler: PushErrorHandler): Disposable; registerBranchProtectionProvider(root: Uri, provider: BranchProtectionProvider): Disposable; } export interface GitExtension { readonly enabled: boolean; readonly onDidChangeEnablement: Event; getAPI(version: 1): API; } export const enum GitErrorCodes { BadConfigFile = 'BadConfigFile', AuthenticationFailed = 'AuthenticationFailed', NoUserNameConfigured = 'NoUserNameConfigured', NoUserEmailConfigured = 'NoUserEmailConfigured', NoRemoteRepositorySpecified = 'NoRemoteRepositorySpecified', NotAGitRepository = 'NotAGitRepository', NotAtRepositoryRoot = 'NotAtRepositoryRoot', Conflict = 'Conflict', StashConflict = 'StashConflict', UnmergedChanges = 'UnmergedChanges', PushRejected = 'PushRejected', RemoteConnectionError = 'RemoteConnectionError', DirtyWorkTree = 'DirtyWorkTree', CantOpenResource = 'CantOpenResource', GitNotFound = 'GitNotFound', CantCreatePipe = 'CantCreatePipe', PermissionDenied = 'PermissionDenied', CantAccessRemote = 'CantAccessRemote', RepositoryNotFound = 'RepositoryNotFound', RepositoryIsLocked = 'RepositoryIsLocked', BranchNotFullyMerged = 'BranchNotFullyMerged', NoRemoteReference = 'NoRemoteReference', InvalidBranchName = 'InvalidBranchName', BranchAlreadyExists = 'BranchAlreadyExists', NoLocalChanges = 'NoLocalChanges', NoStashFound = 'NoStashFound', LocalChangesOverwritten = 'LocalChangesOverwritten', NoUpstreamBranch = 'NoUpstreamBranch', IsInSubmodule = 'IsInSubmodule', WrongCase = 'WrongCase', CantLockRef = 'CantLockRef', CantRebaseMultipleBranches = 'CantRebaseMultipleBranches', PatchDoesNotApply = 'PatchDoesNotApply', NoPathFound = 'NoPathFound', UnknownPath = 'UnknownPath', EmptyCommitMessage = 'EmptyCommitMessage', BranchFastForwardRejected = 'BranchFastForwardRejected', TagConflict = 'TagConflict', }