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