| 1 | /*--------------------------------------------------------------------------------------------- |
| 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 { |
| 7 | CancellationToken, |
| 8 | Command, |
| 9 | Disposable, |
| 10 | Event, |
| 11 | ProviderResult, |
| 12 | Uri, |
| 13 | } from "vscode"; |
| 14 | export { ProviderResult } from "vscode"; |
| 15 | |
| 16 | export interface Git { |
| 17 | readonly path: string; |
| 18 | } |
| 19 | |
| 20 | export interface InputBox { |
| 21 | value: string; |
| 22 | } |
| 23 | |
| 24 | export const enum ForcePushMode { |
| 25 | Force, |
| 26 | ForceWithLease, |
| 27 | ForceWithLeaseIfIncludes, |
| 28 | } |
| 29 | |
| 30 | export const enum RefType { |
| 31 | Head, |
| 32 | RemoteHead, |
| 33 | Tag, |
| 34 | } |
| 35 | |
| 36 | export interface Ref { |
| 37 | readonly type: RefType; |
| 38 | readonly name?: string; |
| 39 | readonly commit?: string; |
| 40 | readonly remote?: string; |
| 41 | } |
| 42 | |
| 43 | export interface UpstreamRef { |
| 44 | readonly remote: string; |
| 45 | readonly name: string; |
| 46 | readonly commit?: string; |
| 47 | } |
| 48 | |
| 49 | export interface Branch extends Ref { |
| 50 | readonly upstream?: UpstreamRef; |
| 51 | readonly ahead?: number; |
| 52 | readonly behind?: number; |
| 53 | } |
| 54 | |
| 55 | export interface CommitShortStat { |
| 56 | readonly files: number; |
| 57 | readonly insertions: number; |
| 58 | readonly deletions: number; |
| 59 | } |
| 60 | |
| 61 | export interface Commit { |
| 62 | readonly hash: string; |
| 63 | readonly message: string; |
| 64 | readonly parents: string[]; |
| 65 | readonly authorDate?: Date; |
| 66 | readonly authorName?: string; |
| 67 | readonly authorEmail?: string; |
| 68 | readonly commitDate?: Date; |
| 69 | readonly shortStat?: CommitShortStat; |
| 70 | } |
| 71 | |
| 72 | export interface Submodule { |
| 73 | readonly name: string; |
| 74 | readonly path: string; |
| 75 | readonly url: string; |
| 76 | } |
| 77 | |
| 78 | export interface Remote { |
| 79 | readonly name: string; |
| 80 | readonly fetchUrl?: string; |
| 81 | readonly pushUrl?: string; |
| 82 | readonly isReadOnly: boolean; |
| 83 | } |
| 84 | |
| 85 | export const enum Status { |
| 86 | INDEX_MODIFIED, |
| 87 | INDEX_ADDED, |
| 88 | INDEX_DELETED, |
| 89 | INDEX_RENAMED, |
| 90 | INDEX_COPIED, |
| 91 | |
| 92 | MODIFIED, |
| 93 | DELETED, |
| 94 | UNTRACKED, |
| 95 | IGNORED, |
| 96 | INTENT_TO_ADD, |
| 97 | INTENT_TO_RENAME, |
| 98 | TYPE_CHANGED, |
| 99 | |
| 100 | ADDED_BY_US, |
| 101 | ADDED_BY_THEM, |
| 102 | DELETED_BY_US, |
| 103 | DELETED_BY_THEM, |
| 104 | BOTH_ADDED, |
| 105 | BOTH_DELETED, |
| 106 | BOTH_MODIFIED, |
| 107 | } |
| 108 | |
| 109 | export interface Change { |
| 110 | /** |
| 111 | * Returns either `originalUri` or `renameUri`, depending |
| 112 | * on whether this change is a rename change. When |
| 113 | * in doubt always use `uri` over the other two alternatives. |
| 114 | */ |
| 115 | readonly uri: Uri; |
| 116 | readonly originalUri: Uri; |
| 117 | readonly renameUri: Uri | undefined; |
| 118 | readonly status: Status; |
| 119 | } |
| 120 | |
| 121 | export interface RepositoryState { |
| 122 | readonly HEAD: Branch | undefined; |
| 123 | readonly refs: Ref[]; |
| 124 | readonly remotes: Remote[]; |
| 125 | readonly submodules: Submodule[]; |
| 126 | readonly rebaseCommit: Commit | undefined; |
| 127 | |
| 128 | readonly mergeChanges: Change[]; |
| 129 | readonly indexChanges: Change[]; |
| 130 | readonly workingTreeChanges: Change[]; |
| 131 | |
| 132 | readonly onDidChange: Event<void>; |
| 133 | } |
| 134 | |
| 135 | export interface RepositoryUIState { |
| 136 | readonly selected: boolean; |
| 137 | readonly onDidChange: Event<void>; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Log options. |
| 142 | */ |
| 143 | export interface LogOptions { |
| 144 | /** Max number of log entries to retrieve. If not specified, the default is 32. */ |
| 145 | readonly maxEntries?: number; |
| 146 | readonly path?: string; |
| 147 | /** A commit range, such as "0a47c67f0fb52dd11562af48658bc1dff1d75a38..0bb4bdea78e1db44d728fd6894720071e303304f" */ |
| 148 | readonly range?: string; |
| 149 | readonly reverse?: boolean; |
| 150 | readonly sortByAuthorDate?: boolean; |
| 151 | readonly shortStats?: boolean; |
| 152 | readonly author?: string; |
| 153 | } |
| 154 | |
| 155 | export interface CommitOptions { |
| 156 | all?: boolean | "tracked"; |
| 157 | amend?: boolean; |
| 158 | signoff?: boolean; |
| 159 | signCommit?: boolean; |
| 160 | empty?: boolean; |
| 161 | noVerify?: boolean; |
| 162 | requireUserConfig?: boolean; |
| 163 | useEditor?: boolean; |
| 164 | verbose?: boolean; |
| 165 | /** |
| 166 | * string - execute the specified command after the commit operation |
| 167 | * undefined - execute the command specified in git.postCommitCommand |
| 168 | * after the commit operation |
| 169 | * null - do not execute any command after the commit operation |
| 170 | */ |
| 171 | postCommitCommand?: string | null; |
| 172 | } |
| 173 | |
| 174 | export interface FetchOptions { |
| 175 | remote?: string; |
| 176 | ref?: string; |
| 177 | all?: boolean; |
| 178 | prune?: boolean; |
| 179 | depth?: number; |
| 180 | } |
| 181 | |
| 182 | export interface InitOptions { |
| 183 | defaultBranch?: string; |
| 184 | } |
| 185 | |
| 186 | export interface RefQuery { |
| 187 | readonly contains?: string; |
| 188 | readonly count?: number; |
| 189 | readonly pattern?: string; |
| 190 | readonly sort?: "alphabetically" | "committerdate"; |
| 191 | } |
| 192 | |
| 193 | export interface BranchQuery extends RefQuery { |
| 194 | readonly remote?: boolean; |
| 195 | } |
| 196 | |
| 197 | export interface Repository { |
| 198 | readonly rootUri: Uri; |
| 199 | readonly inputBox: InputBox; |
| 200 | readonly state: RepositoryState; |
| 201 | readonly ui: RepositoryUIState; |
| 202 | |
| 203 | readonly onDidCommit: Event<void>; |
| 204 | |
| 205 | getConfigs(): Promise<{ key: string; value: string }[]>; |
| 206 | getConfig(key: string): Promise<string>; |
| 207 | setConfig(key: string, value: string): Promise<string>; |
| 208 | getGlobalConfig(key: string): Promise<string>; |
| 209 | |
| 210 | getObjectDetails( |
| 211 | treeish: string, |
| 212 | path: string, |
| 213 | ): Promise<{ mode: string; object: string; size: number }>; |
| 214 | detectObjectType( |
| 215 | object: string, |
| 216 | ): Promise<{ mimetype: string; encoding?: string }>; |
| 217 | buffer(ref: string, path: string): Promise<Buffer>; |
| 218 | show(ref: string, path: string): Promise<string>; |
| 219 | getCommit(ref: string): Promise<Commit>; |
| 220 | |
| 221 | add(paths: string[]): Promise<void>; |
| 222 | revert(paths: string[]): Promise<void>; |
| 223 | clean(paths: string[]): Promise<void>; |
| 224 | |
| 225 | apply(patch: string, reverse?: boolean): Promise<void>; |
| 226 | diff(cached?: boolean): Promise<string>; |
| 227 | diffWithHEAD(): Promise<Change[]>; |
| 228 | diffWithHEAD(path: string): Promise<string>; |
| 229 | diffWith(ref: string): Promise<Change[]>; |
| 230 | diffWith(ref: string, path: string): Promise<string>; |
| 231 | diffIndexWithHEAD(): Promise<Change[]>; |
| 232 | diffIndexWithHEAD(path: string): Promise<string>; |
| 233 | diffIndexWith(ref: string): Promise<Change[]>; |
| 234 | diffIndexWith(ref: string, path: string): Promise<string>; |
| 235 | diffBlobs(object1: string, object2: string): Promise<string>; |
| 236 | diffBetween(ref1: string, ref2: string): Promise<Change[]>; |
| 237 | diffBetween(ref1: string, ref2: string, path: string): Promise<string>; |
| 238 | |
| 239 | hashObject(data: string): Promise<string>; |
| 240 | |
| 241 | createBranch(name: string, checkout: boolean, ref?: string): Promise<void>; |
| 242 | deleteBranch(name: string, force?: boolean): Promise<void>; |
| 243 | getBranch(name: string): Promise<Branch>; |
| 244 | getBranches( |
| 245 | query: BranchQuery, |
| 246 | cancellationToken?: CancellationToken, |
| 247 | ): Promise<Ref[]>; |
| 248 | getBranchBase(name: string): Promise<Branch | undefined>; |
| 249 | setBranchUpstream(name: string, upstream: string): Promise<void>; |
| 250 | |
| 251 | getRefs( |
| 252 | query: RefQuery, |
| 253 | cancellationToken?: CancellationToken, |
| 254 | ): Promise<Ref[]>; |
| 255 | |
| 256 | getMergeBase(ref1: string, ref2: string): Promise<string | undefined>; |
| 257 | |
| 258 | tag(name: string, upstream: string): Promise<void>; |
| 259 | deleteTag(name: string): Promise<void>; |
| 260 | |
| 261 | status(): Promise<void>; |
| 262 | checkout(treeish: string): Promise<void>; |
| 263 | |
| 264 | addRemote(name: string, url: string): Promise<void>; |
| 265 | removeRemote(name: string): Promise<void>; |
| 266 | renameRemote(name: string, newName: string): Promise<void>; |
| 267 | |
| 268 | fetch(options?: FetchOptions): Promise<void>; |
| 269 | fetch(remote?: string, ref?: string, depth?: number): Promise<void>; |
| 270 | pull(unshallow?: boolean): Promise<void>; |
| 271 | push( |
| 272 | remoteName?: string, |
| 273 | branchName?: string, |
| 274 | setUpstream?: boolean, |
| 275 | force?: ForcePushMode, |
| 276 | ): Promise<void>; |
| 277 | |
| 278 | blame(path: string): Promise<string>; |
| 279 | log(options?: LogOptions): Promise<Commit[]>; |
| 280 | |
| 281 | commit(message: string, opts?: CommitOptions): Promise<void>; |
| 282 | merge(ref: string): Promise<void>; |
| 283 | mergeAbort(): Promise<void>; |
| 284 | } |
| 285 | |
| 286 | export interface RemoteSource { |
| 287 | readonly name: string; |
| 288 | readonly description?: string; |
| 289 | readonly url: string | string[]; |
| 290 | } |
| 291 | |
| 292 | export interface RemoteSourceProvider { |
| 293 | readonly name: string; |
| 294 | readonly icon?: string; // codicon name |
| 295 | readonly supportsQuery?: boolean; |
| 296 | getRemoteSources(query?: string): ProviderResult<RemoteSource[]>; |
| 297 | getBranches?(url: string): ProviderResult<string[]>; |
| 298 | publishRepository?(repository: Repository): Promise<void>; |
| 299 | } |
| 300 | |
| 301 | export interface RemoteSourcePublisher { |
| 302 | readonly name: string; |
| 303 | readonly icon?: string; // codicon name |
| 304 | publishRepository(repository: Repository): Promise<void>; |
| 305 | } |
| 306 | |
| 307 | export interface Credentials { |
| 308 | readonly username: string; |
| 309 | readonly password: string; |
| 310 | } |
| 311 | |
| 312 | export interface CredentialsProvider { |
| 313 | getCredentials(host: Uri): ProviderResult<Credentials>; |
| 314 | } |
| 315 | |
| 316 | export interface PostCommitCommandsProvider { |
| 317 | getCommands(repository: Repository): Command[]; |
| 318 | } |
| 319 | |
| 320 | export interface PushErrorHandler { |
| 321 | handlePushError( |
| 322 | repository: Repository, |
| 323 | remote: Remote, |
| 324 | refspec: string, |
| 325 | error: Error & { gitErrorCode: GitErrorCodes }, |
| 326 | ): Promise<boolean>; |
| 327 | } |
| 328 | |
| 329 | export interface BranchProtection { |
| 330 | readonly remote: string; |
| 331 | readonly rules: BranchProtectionRule[]; |
| 332 | } |
| 333 | |
| 334 | export interface BranchProtectionRule { |
| 335 | readonly include?: string[]; |
| 336 | readonly exclude?: string[]; |
| 337 | } |
| 338 | |
| 339 | export interface BranchProtectionProvider { |
| 340 | onDidChangeBranchProtection: Event<Uri>; |
| 341 | provideBranchProtection(): BranchProtection[]; |
| 342 | } |
| 343 | |
| 344 | export type APIState = "uninitialized" | "initialized"; |
| 345 | |
| 346 | export interface PublishEvent { |
| 347 | repository: Repository; |
| 348 | branch?: string; |
| 349 | } |
| 350 | |
| 351 | export interface API { |
| 352 | readonly state: APIState; |
| 353 | readonly onDidChangeState: Event<APIState>; |
| 354 | readonly onDidPublish: Event<PublishEvent>; |
| 355 | readonly git: Git; |
| 356 | readonly repositories: Repository[]; |
| 357 | readonly onDidOpenRepository: Event<Repository>; |
| 358 | readonly onDidCloseRepository: Event<Repository>; |
| 359 | |
| 360 | toGitUri(uri: Uri, ref: string): Uri; |
| 361 | getRepository(uri: Uri): Repository | null; |
| 362 | init(root: Uri, options?: InitOptions): Promise<Repository | null>; |
| 363 | openRepository(root: Uri): Promise<Repository | null>; |
| 364 | |
| 365 | registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable; |
| 366 | registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable; |
| 367 | registerCredentialsProvider(provider: CredentialsProvider): Disposable; |
| 368 | registerPostCommitCommandsProvider( |
| 369 | provider: PostCommitCommandsProvider, |
| 370 | ): Disposable; |
| 371 | registerPushErrorHandler(handler: PushErrorHandler): Disposable; |
| 372 | registerBranchProtectionProvider( |
| 373 | root: Uri, |
| 374 | provider: BranchProtectionProvider, |
| 375 | ): Disposable; |
| 376 | } |
| 377 | |
| 378 | export interface GitExtension { |
| 379 | readonly enabled: boolean; |
| 380 | readonly onDidChangeEnablement: Event<boolean>; |
| 381 | |
| 382 | /** |
| 383 | * Returns a specific API version. |
| 384 | * |
| 385 | * Throws error if git extension is disabled. You can listen to the |
| 386 | * [GitExtension.onDidChangeEnablement](#GitExtension.onDidChangeEnablement) event |
| 387 | * to know when the extension becomes enabled/disabled. |
| 388 | * |
| 389 | * @param version Version number. |
| 390 | * @returns API instance |
| 391 | */ |
| 392 | getAPI(version: 1): API; |
| 393 | } |
| 394 | |
| 395 | export const enum GitErrorCodes { |
| 396 | BadConfigFile = "BadConfigFile", |
| 397 | AuthenticationFailed = "AuthenticationFailed", |
| 398 | NoUserNameConfigured = "NoUserNameConfigured", |
| 399 | NoUserEmailConfigured = "NoUserEmailConfigured", |
| 400 | NoRemoteRepositorySpecified = "NoRemoteRepositorySpecified", |
| 401 | NotAGitRepository = "NotAGitRepository", |
| 402 | NotAtRepositoryRoot = "NotAtRepositoryRoot", |
| 403 | Conflict = "Conflict", |
| 404 | StashConflict = "StashConflict", |
| 405 | UnmergedChanges = "UnmergedChanges", |
| 406 | PushRejected = "PushRejected", |
| 407 | ForcePushWithLeaseRejected = "ForcePushWithLeaseRejected", |
| 408 | ForcePushWithLeaseIfIncludesRejected = "ForcePushWithLeaseIfIncludesRejected", |
| 409 | RemoteConnectionError = "RemoteConnectionError", |
| 410 | DirtyWorkTree = "DirtyWorkTree", |
| 411 | CantOpenResource = "CantOpenResource", |
| 412 | GitNotFound = "GitNotFound", |
| 413 | CantCreatePipe = "CantCreatePipe", |
| 414 | PermissionDenied = "PermissionDenied", |
| 415 | CantAccessRemote = "CantAccessRemote", |
| 416 | RepositoryNotFound = "RepositoryNotFound", |
| 417 | RepositoryIsLocked = "RepositoryIsLocked", |
| 418 | BranchNotFullyMerged = "BranchNotFullyMerged", |
| 419 | NoRemoteReference = "NoRemoteReference", |
| 420 | InvalidBranchName = "InvalidBranchName", |
| 421 | BranchAlreadyExists = "BranchAlreadyExists", |
| 422 | NoLocalChanges = "NoLocalChanges", |
| 423 | NoStashFound = "NoStashFound", |
| 424 | LocalChangesOverwritten = "LocalChangesOverwritten", |
| 425 | NoUpstreamBranch = "NoUpstreamBranch", |
| 426 | IsInSubmodule = "IsInSubmodule", |
| 427 | WrongCase = "WrongCase", |
| 428 | CantLockRef = "CantLockRef", |
| 429 | CantRebaseMultipleBranches = "CantRebaseMultipleBranches", |
| 430 | PatchDoesNotApply = "PatchDoesNotApply", |
| 431 | NoPathFound = "NoPathFound", |
| 432 | UnknownPath = "UnknownPath", |
| 433 | EmptyCommitMessage = "EmptyCommitMessage", |
| 434 | BranchFastForwardRejected = "BranchFastForwardRejected", |
| 435 | BranchNotYetBorn = "BranchNotYetBorn", |
| 436 | TagConflict = "TagConflict", |
| 437 | } |