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