Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/git/src/api/git.d.ts
5240 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 interface Worktree {
80
readonly name: string;
81
readonly path: string;
82
readonly ref: string;
83
readonly main: boolean;
84
readonly detached: boolean;
85
}
86
87
export const enum Status {
88
INDEX_MODIFIED,
89
INDEX_ADDED,
90
INDEX_DELETED,
91
INDEX_RENAMED,
92
INDEX_COPIED,
93
94
MODIFIED,
95
DELETED,
96
UNTRACKED,
97
IGNORED,
98
INTENT_TO_ADD,
99
INTENT_TO_RENAME,
100
TYPE_CHANGED,
101
102
ADDED_BY_US,
103
ADDED_BY_THEM,
104
DELETED_BY_US,
105
DELETED_BY_THEM,
106
BOTH_ADDED,
107
BOTH_DELETED,
108
BOTH_MODIFIED
109
}
110
111
export interface Change {
112
113
/**
114
* Returns either `originalUri` or `renameUri`, depending
115
* on whether this change is a rename change. When
116
* in doubt always use `uri` over the other two alternatives.
117
*/
118
readonly uri: Uri;
119
readonly originalUri: Uri;
120
readonly renameUri: Uri | undefined;
121
readonly status: Status;
122
}
123
124
export interface DiffChange extends Change {
125
readonly insertions: number;
126
readonly deletions: number;
127
}
128
129
export type RepositoryKind = 'repository' | 'submodule' | 'worktree';
130
131
export interface RepositoryState {
132
readonly HEAD: Branch | undefined;
133
readonly refs: Ref[];
134
readonly remotes: Remote[];
135
readonly submodules: Submodule[];
136
readonly worktrees: Worktree[];
137
readonly rebaseCommit: Commit | undefined;
138
139
readonly mergeChanges: Change[];
140
readonly indexChanges: Change[];
141
readonly workingTreeChanges: Change[];
142
readonly untrackedChanges: Change[];
143
144
readonly onDidChange: Event<void>;
145
}
146
147
export interface RepositoryUIState {
148
readonly selected: boolean;
149
readonly onDidChange: Event<void>;
150
}
151
152
export interface RepositoryAccessDetails {
153
readonly rootUri: Uri;
154
readonly lastAccessTime: number;
155
}
156
157
/**
158
* Log options.
159
*/
160
export interface LogOptions {
161
/** Max number of log entries to retrieve. If not specified, the default is 32. */
162
readonly maxEntries?: number;
163
readonly path?: string;
164
/** A commit range, such as "0a47c67f0fb52dd11562af48658bc1dff1d75a38..0bb4bdea78e1db44d728fd6894720071e303304f" */
165
readonly range?: string;
166
readonly reverse?: boolean;
167
readonly sortByAuthorDate?: boolean;
168
readonly shortStats?: boolean;
169
readonly author?: string;
170
readonly grep?: string;
171
readonly refNames?: string[];
172
readonly maxParents?: number;
173
readonly skip?: number;
174
}
175
176
export interface CommitOptions {
177
all?: boolean | 'tracked';
178
amend?: boolean;
179
signoff?: boolean;
180
/**
181
* true - sign the commit
182
* false - do not sign the commit
183
* undefined - use the repository/global git config
184
*/
185
signCommit?: boolean;
186
empty?: boolean;
187
noVerify?: boolean;
188
requireUserConfig?: boolean;
189
useEditor?: boolean;
190
verbose?: boolean;
191
/**
192
* string - execute the specified command after the commit operation
193
* undefined - execute the command specified in git.postCommitCommand
194
* after the commit operation
195
* null - do not execute any command after the commit operation
196
*/
197
postCommitCommand?: string | null;
198
}
199
200
export interface FetchOptions {
201
remote?: string;
202
ref?: string;
203
all?: boolean;
204
prune?: boolean;
205
depth?: number;
206
}
207
208
export interface InitOptions {
209
defaultBranch?: string;
210
}
211
212
export interface CloneOptions {
213
parentPath?: Uri;
214
/**
215
* ref is only used if the repository cache is missed.
216
*/
217
ref?: string;
218
recursive?: boolean;
219
/**
220
* If no postCloneAction is provided, then the users setting for git.openAfterClone is used.
221
*/
222
postCloneAction?: 'none';
223
}
224
225
export interface RefQuery {
226
readonly contains?: string;
227
readonly count?: number;
228
readonly pattern?: string | string[];
229
readonly sort?: 'alphabetically' | 'committerdate' | 'creatordate';
230
}
231
232
export interface BranchQuery extends RefQuery {
233
readonly remote?: boolean;
234
}
235
236
export interface Repository {
237
238
readonly rootUri: Uri;
239
readonly inputBox: InputBox;
240
readonly state: RepositoryState;
241
readonly ui: RepositoryUIState;
242
readonly kind: RepositoryKind;
243
244
readonly onDidCommit: Event<void>;
245
readonly onDidCheckout: Event<void>;
246
247
getConfigs(): Promise<{ key: string; value: string; }[]>;
248
getConfig(key: string): Promise<string>;
249
setConfig(key: string, value: string): Promise<string>;
250
unsetConfig(key: string): Promise<string>;
251
getGlobalConfig(key: string): Promise<string>;
252
253
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
254
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>;
255
buffer(ref: string, path: string): Promise<Buffer>;
256
show(ref: string, path: string): Promise<string>;
257
getCommit(ref: string): Promise<Commit>;
258
259
add(paths: string[]): Promise<void>;
260
revert(paths: string[]): Promise<void>;
261
clean(paths: string[]): Promise<void>;
262
263
apply(patch: string, reverse?: boolean): Promise<void>;
264
apply(patch: string, options?: { allowEmpty?: boolean; reverse?: boolean; threeWay?: boolean; }): Promise<void>;
265
diff(cached?: boolean): Promise<string>;
266
diffWithHEAD(): Promise<Change[]>;
267
diffWithHEAD(path: string): Promise<string>;
268
diffWithHEADShortStats(path?: string): Promise<CommitShortStat>;
269
diffWith(ref: string): Promise<Change[]>;
270
diffWith(ref: string, path: string): Promise<string>;
271
diffIndexWithHEAD(): Promise<Change[]>;
272
diffIndexWithHEAD(path: string): Promise<string>;
273
diffIndexWithHEADShortStats(path?: string): Promise<CommitShortStat>;
274
diffIndexWith(ref: string): Promise<Change[]>;
275
diffIndexWith(ref: string, path: string): Promise<string>;
276
diffBlobs(object1: string, object2: string): Promise<string>;
277
diffBetween(ref1: string, ref2: string): Promise<Change[]>;
278
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
279
diffBetweenPatch(ref1: string, ref2: string, path?: string): Promise<string>;
280
diffBetweenWithStats(ref1: string, ref2: string, path?: string): Promise<DiffChange[]>;
281
282
hashObject(data: string): Promise<string>;
283
284
createBranch(name: string, checkout: boolean, ref?: string): Promise<void>;
285
deleteBranch(name: string, force?: boolean): Promise<void>;
286
getBranch(name: string): Promise<Branch>;
287
getBranches(query: BranchQuery, cancellationToken?: CancellationToken): Promise<Ref[]>;
288
getBranchBase(name: string): Promise<Branch | undefined>;
289
setBranchUpstream(name: string, upstream: string): Promise<void>;
290
291
checkIgnore(paths: string[]): Promise<Set<string>>;
292
293
getRefs(query: RefQuery, cancellationToken?: CancellationToken): Promise<Ref[]>;
294
295
getMergeBase(ref1: string, ref2: string): Promise<string | undefined>;
296
297
tag(name: string, message: string, ref?: string | undefined): Promise<void>;
298
deleteTag(name: string): Promise<void>;
299
300
status(): Promise<void>;
301
checkout(treeish: string): Promise<void>;
302
303
addRemote(name: string, url: string): Promise<void>;
304
removeRemote(name: string): Promise<void>;
305
renameRemote(name: string, newName: string): Promise<void>;
306
307
fetch(options?: FetchOptions): Promise<void>;
308
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
309
pull(unshallow?: boolean): Promise<void>;
310
push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise<void>;
311
312
blame(path: string): Promise<string>;
313
log(options?: LogOptions): Promise<Commit[]>;
314
315
commit(message: string, opts?: CommitOptions): Promise<void>;
316
merge(ref: string): Promise<void>;
317
mergeAbort(): Promise<void>;
318
319
createStash(options?: { message?: string; includeUntracked?: boolean; staged?: boolean }): Promise<void>;
320
applyStash(index?: number): Promise<void>;
321
popStash(index?: number): Promise<void>;
322
dropStash(index?: number): Promise<void>;
323
324
createWorktree(options?: { path?: string; commitish?: string; branch?: string }): Promise<string>;
325
deleteWorktree(path: string, options?: { force?: boolean }): Promise<void>;
326
327
migrateChanges(sourceRepositoryPath: string, options?: { confirmation?: boolean; deleteFromSource?: boolean; untracked?: boolean }): Promise<void>;
328
}
329
330
export interface RemoteSource {
331
readonly name: string;
332
readonly description?: string;
333
readonly url: string | string[];
334
}
335
336
export interface RemoteSourceProvider {
337
readonly name: string;
338
readonly icon?: string; // codicon name
339
readonly supportsQuery?: boolean;
340
getRemoteSources(query?: string): ProviderResult<RemoteSource[]>;
341
getBranches?(url: string): ProviderResult<string[]>;
342
publishRepository?(repository: Repository): Promise<void>;
343
}
344
345
export interface RemoteSourcePublisher {
346
readonly name: string;
347
readonly icon?: string; // codicon name
348
publishRepository(repository: Repository): Promise<void>;
349
}
350
351
export interface Credentials {
352
readonly username: string;
353
readonly password: string;
354
}
355
356
export interface CredentialsProvider {
357
getCredentials(host: Uri): ProviderResult<Credentials>;
358
}
359
360
export interface PostCommitCommandsProvider {
361
getCommands(repository: Repository): Command[];
362
}
363
364
export interface PushErrorHandler {
365
handlePushError(repository: Repository, remote: Remote, refspec: string, error: Error & { gitErrorCode: GitErrorCodes }): Promise<boolean>;
366
}
367
368
export interface BranchProtection {
369
readonly remote: string;
370
readonly rules: BranchProtectionRule[];
371
}
372
373
export interface BranchProtectionRule {
374
readonly include?: string[];
375
readonly exclude?: string[];
376
}
377
378
export interface BranchProtectionProvider {
379
onDidChangeBranchProtection: Event<Uri>;
380
provideBranchProtection(): BranchProtection[];
381
}
382
383
export interface AvatarQueryCommit {
384
readonly hash: string;
385
readonly authorName?: string;
386
readonly authorEmail?: string;
387
}
388
389
export interface AvatarQuery {
390
readonly commits: AvatarQueryCommit[];
391
readonly size: number;
392
}
393
394
export interface SourceControlHistoryItemDetailsProvider {
395
provideAvatar(repository: Repository, query: AvatarQuery): ProviderResult<Map<string, string | undefined>>;
396
provideHoverCommands(repository: Repository): ProviderResult<Command[]>;
397
provideMessageLinks(repository: Repository, message: string): ProviderResult<string>;
398
}
399
400
export type APIState = 'uninitialized' | 'initialized';
401
402
export interface PublishEvent {
403
repository: Repository;
404
branch?: string;
405
}
406
407
export interface API {
408
readonly state: APIState;
409
readonly onDidChangeState: Event<APIState>;
410
readonly onDidPublish: Event<PublishEvent>;
411
readonly git: Git;
412
readonly repositories: Repository[];
413
readonly recentRepositories: Iterable<RepositoryAccessDetails>;
414
readonly onDidOpenRepository: Event<Repository>;
415
readonly onDidCloseRepository: Event<Repository>;
416
417
toGitUri(uri: Uri, ref: string): Uri;
418
getRepository(uri: Uri): Repository | null;
419
getRepositoryRoot(uri: Uri): Promise<Uri | null>;
420
getRepositoryWorkspace(uri: Uri): Promise<Uri[] | null>;
421
init(root: Uri, options?: InitOptions): Promise<Repository | null>;
422
/**
423
* Checks the cache of known cloned repositories, and clones if the repository is not found.
424
* Make sure to pass `postCloneAction` 'none' if you want to have the uri where you can find the repository returned.
425
* @returns The URI of a folder or workspace file which, when opened, will open the cloned repository.
426
*/
427
clone(uri: Uri, options?: CloneOptions): Promise<Uri | null>;
428
openRepository(root: Uri): Promise<Repository | null>;
429
430
registerRemoteSourcePublisher(publisher: RemoteSourcePublisher): Disposable;
431
registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
432
registerCredentialsProvider(provider: CredentialsProvider): Disposable;
433
registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable;
434
registerPushErrorHandler(handler: PushErrorHandler): Disposable;
435
registerBranchProtectionProvider(root: Uri, provider: BranchProtectionProvider): Disposable;
436
registerSourceControlHistoryItemDetailsProvider(provider: SourceControlHistoryItemDetailsProvider): Disposable;
437
}
438
439
export interface GitExtension {
440
441
readonly enabled: boolean;
442
readonly onDidChangeEnablement: Event<boolean>;
443
444
/**
445
* Returns a specific API version.
446
*
447
* Throws error if git extension is disabled. You can listen to the
448
* [GitExtension.onDidChangeEnablement](#GitExtension.onDidChangeEnablement) event
449
* to know when the extension becomes enabled/disabled.
450
*
451
* @param version Version number.
452
* @returns API instance
453
*/
454
getAPI(version: 1): API;
455
}
456
457
export const enum GitErrorCodes {
458
BadConfigFile = 'BadConfigFile',
459
BadRevision = 'BadRevision',
460
AuthenticationFailed = 'AuthenticationFailed',
461
NoUserNameConfigured = 'NoUserNameConfigured',
462
NoUserEmailConfigured = 'NoUserEmailConfigured',
463
NoRemoteRepositorySpecified = 'NoRemoteRepositorySpecified',
464
NotAGitRepository = 'NotAGitRepository',
465
NotASafeGitRepository = 'NotASafeGitRepository',
466
NotAtRepositoryRoot = 'NotAtRepositoryRoot',
467
Conflict = 'Conflict',
468
StashConflict = 'StashConflict',
469
UnmergedChanges = 'UnmergedChanges',
470
PushRejected = 'PushRejected',
471
ForcePushWithLeaseRejected = 'ForcePushWithLeaseRejected',
472
ForcePushWithLeaseIfIncludesRejected = 'ForcePushWithLeaseIfIncludesRejected',
473
RemoteConnectionError = 'RemoteConnectionError',
474
DirtyWorkTree = 'DirtyWorkTree',
475
CantOpenResource = 'CantOpenResource',
476
GitNotFound = 'GitNotFound',
477
CantCreatePipe = 'CantCreatePipe',
478
PermissionDenied = 'PermissionDenied',
479
CantAccessRemote = 'CantAccessRemote',
480
RepositoryNotFound = 'RepositoryNotFound',
481
RepositoryIsLocked = 'RepositoryIsLocked',
482
BranchNotFullyMerged = 'BranchNotFullyMerged',
483
NoRemoteReference = 'NoRemoteReference',
484
InvalidBranchName = 'InvalidBranchName',
485
BranchAlreadyExists = 'BranchAlreadyExists',
486
NoLocalChanges = 'NoLocalChanges',
487
NoStashFound = 'NoStashFound',
488
LocalChangesOverwritten = 'LocalChangesOverwritten',
489
NoUpstreamBranch = 'NoUpstreamBranch',
490
IsInSubmodule = 'IsInSubmodule',
491
WrongCase = 'WrongCase',
492
CantLockRef = 'CantLockRef',
493
CantRebaseMultipleBranches = 'CantRebaseMultipleBranches',
494
PatchDoesNotApply = 'PatchDoesNotApply',
495
NoPathFound = 'NoPathFound',
496
UnknownPath = 'UnknownPath',
497
EmptyCommitMessage = 'EmptyCommitMessage',
498
BranchFastForwardRejected = 'BranchFastForwardRejected',
499
BranchNotYetBorn = 'BranchNotYetBorn',
500
TagConflict = 'TagConflict',
501
CherryPickEmpty = 'CherryPickEmpty',
502
CherryPickConflict = 'CherryPickConflict',
503
WorktreeContainsChanges = 'WorktreeContainsChanges',
504
WorktreeAlreadyExists = 'WorktreeAlreadyExists',
505
WorktreeBranchAlreadyUsed = 'WorktreeBranchAlreadyUsed'
506
}
507
508