forked from gitkraken/vscode-gitlens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitProvider.ts
749 lines (691 loc) · 25.4 KB
/
gitProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
import type { CancellationToken, Disposable, Event, Range, TextDocument, Uri, WorkspaceFolder } from 'vscode';
import type { Commit, InputBox } from '../@types/vscode.git';
import type { ForcePushMode } from '../@types/vscode.git.enums';
import type { GitConfigKeys } from '../constants';
import type { SearchQuery } from '../constants.search';
import type { Features } from '../features';
import type { HostingIntegration } from '../plus/integrations/integration';
import type { GitUri } from './gitUri';
import type { GitBlame, GitBlameLine } from './models/blame';
import type { GitBranch } from './models/branch';
import type { GitCommit, GitCommitStats } from './models/commit';
import type { GitContributor, GitContributorStats } from './models/contributor';
import type { GitDiff, GitDiffFile, GitDiffFiles, GitDiffFilter, GitDiffLine, GitDiffShortStat } from './models/diff';
import type { GitFile, GitFileChange } from './models/file';
import type { GitGraph } from './models/graph';
import type { GitLog } from './models/log';
import type { MergeConflict } from './models/mergeConflict';
import type { GitPausedOperationStatus } from './models/pausedOperationStatus';
import type { GitBranchReference, GitReference } from './models/reference';
import type { GitReflog } from './models/reflog';
import type { GitRemote } from './models/remote';
import type { Repository, RepositoryChangeEvent } from './models/repository';
import type { GitRevisionRange } from './models/revision';
import type { GitStash } from './models/stash';
import type { GitStatus, GitStatusFile } from './models/status';
import type { GitTag } from './models/tag';
import type { GitTreeEntry } from './models/tree';
import type { GitUser } from './models/user';
import type { GitWorktree } from './models/worktree';
import type { RemoteProvider } from './remotes/remoteProvider';
import type { GitSearch } from './search';
import type { BranchSortOptions, TagSortOptions } from './utils/vscode/sorting';
export type GitCaches =
| 'branches'
| 'contributors'
| 'providers'
| 'remotes'
| 'stashes'
| 'status'
| 'tags'
| 'worktrees';
export type GitRepositoryCaches = Extract<GitCaches, 'branches' | 'remotes'>;
export const gitRepositoryCacheKeys = new Set<GitRepositoryCaches>(['branches', 'remotes']);
export interface GitDir {
readonly uri: Uri;
readonly commonUri?: Uri;
}
export type GitProviderId = 'git' | 'github' | 'vsls';
export interface GitProviderDescriptor {
readonly id: GitProviderId;
readonly name: string;
readonly virtual: boolean;
}
export interface RepositoryInitWatcher extends Disposable {
readonly onDidCreate: Event<Uri>;
}
export interface ScmRepository {
readonly rootUri: Uri;
readonly inputBox: InputBox;
getCommit(ref: string): Promise<Commit>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean, force?: ForcePushMode): Promise<void>;
}
export interface LeftRightCommitCountResult {
left: number;
right: number;
}
export interface PagedResult<T> {
readonly paging?: {
readonly cursor: string;
readonly more: boolean;
};
readonly values: NonNullable<T>[];
}
export interface PagingOptions {
cursor?: string;
}
export interface NextComparisonUrisResult {
current: GitUri;
next: GitUri | undefined;
deleted?: boolean | undefined;
}
export interface PreviousComparisonUrisResult {
current: GitUri;
previous: GitUri | undefined;
}
export interface PreviousLineComparisonUrisResult extends PreviousComparisonUrisResult {
line: number;
}
export interface RepositoryCloseEvent {
readonly uri: Uri;
}
export interface RepositoryOpenEvent {
readonly uri: Uri;
}
export type RepositoryVisibility = 'private' | 'public' | 'local';
export interface RepositoryVisibilityInfo {
visibility: RepositoryVisibility;
timestamp: number;
remotesHash?: string;
}
export interface BranchContributionsOverview extends GitCommitStats<number> {
readonly repoPath: string;
readonly branch: string;
readonly baseOrTargetBranch: string;
readonly mergeBase: string;
readonly commits: number;
readonly latestCommitDate: Date | undefined;
readonly firstCommitDate: Date | undefined;
readonly contributors: GitContributor[];
}
export interface GitRepositoryProvider {
reset?(repoPath: string, ref: string, options?: { hard?: boolean } | { soft?: boolean }): Promise<void>;
checkout?(
repoPath: string,
ref: string,
options?: { createBranch?: string | undefined } | { path?: string | undefined },
): Promise<void>;
excludeIgnoredUris(repoPath: string, uris: Uri[]): Promise<Uri[]>;
fetch?(
repoPath: string,
options?: {
all?: boolean | undefined;
branch?: GitBranchReference | undefined;
prune?: boolean | undefined;
pull?: boolean | undefined;
remote?: string | undefined;
},
): Promise<void>;
pull?(
repoPath: string,
options?: {
branch?: GitBranchReference | undefined;
rebase?: boolean | undefined;
tags?: boolean | undefined;
},
): Promise<void>;
push?(
repoPath: string,
options?: {
reference?: GitReference | undefined;
force?: boolean | undefined;
publish?: { remote: string };
},
): Promise<void>;
getChangedFilesCount(repoPath: string, ref?: string): Promise<GitDiffShortStat | undefined>;
getCommit(repoPath: string, ref: string): Promise<GitCommit | undefined>;
getCommitCount(repoPath: string, ref: string): Promise<number | undefined>;
getCommitFileStats?(repoPath: string | Uri, ref: string): Promise<GitFileChange[] | undefined>;
getCommitForFile(
repoPath: string,
uri: Uri,
options?: {
ref?: string | undefined;
firstIfNotFound?: boolean | undefined;
range?: Range | undefined;
},
): Promise<GitCommit | undefined>;
getCommitsForGraph(
repoPath: string,
asWebviewUri: (uri: Uri) => Uri,
options?: {
include?: { stats?: boolean };
limit?: number;
ref?: string;
},
): Promise<GitGraph>;
getCommitTags(
repoPath: string,
ref: string,
options?: {
commitDate?: Date | undefined;
mode?: 'contains' | 'pointsAt' | undefined;
},
): Promise<string[]>;
getConfig?(repoPath: string, key: GitConfigKeys): Promise<string | undefined>;
setConfig?(repoPath: string, key: GitConfigKeys, value: string | undefined): Promise<void>;
getCurrentUser(repoPath: string): Promise<GitUser | undefined>;
getDiff?(
repoPath: string | Uri,
to: string,
from?: string,
options?:
| { context?: number; includeUntracked?: never; uris?: never }
| { context?: number; includeUntracked?: never; uris: Uri[] }
| { context?: number; includeUntracked: boolean; uris?: never },
): Promise<GitDiff | undefined>;
getDiffFiles?(repoPath: string | Uri, contents: string): Promise<GitDiffFiles | undefined>;
getDiffStatus(
repoPath: string,
ref1OrRange: string | GitRevisionRange,
ref2?: string,
options?: { filters?: GitDiffFilter[]; path?: string; similarityThreshold?: number },
): Promise<GitFile[] | undefined>;
getFileStatusForCommit(repoPath: string, uri: Uri, ref: string): Promise<GitFile | undefined>;
getFirstCommitSha?(repoPath: string): Promise<string | undefined>;
getGitDir?(repoPath: string): Promise<GitDir | undefined>;
getLastFetchedTimestamp(repoPath: string): Promise<number | undefined>;
getLeftRightCommitCount(
repoPath: string,
range: GitRevisionRange,
options?: { authors?: GitUser[] | undefined; excludeMerges?: boolean },
): Promise<LeftRightCommitCountResult | undefined>;
getLog(
repoPath: string,
options?: {
all?: boolean | undefined;
authors?: GitUser[] | undefined;
cursor?: string | undefined;
limit?: number | undefined;
merges?: boolean | 'first-parent' | undefined;
ordering?: 'date' | 'author-date' | 'topo' | null | undefined;
ref?: string | undefined;
since?: string | undefined;
},
): Promise<GitLog | undefined>;
getLogRefsOnly(
repoPath: string,
options?: {
authors?: GitUser[] | undefined;
cursor?: string | undefined;
limit?: number | undefined;
merges?: boolean | 'first-parent';
ordering?: 'date' | 'author-date' | 'topo' | null | undefined;
ref?: string | undefined;
since?: string | undefined;
},
): Promise<Set<string> | undefined>;
getLogForFile(
repoPath: string,
pathOrUri: string | Uri,
options?: {
all?: boolean | undefined;
cursor?: string | undefined;
force?: boolean | undefined;
limit?: number | undefined;
ordering?: 'date' | 'author-date' | 'topo' | null | undefined;
range?: Range | undefined;
ref?: string | undefined;
renames?: boolean | undefined;
reverse?: boolean | undefined;
since?: string | undefined;
skip?: number | undefined;
},
): Promise<GitLog | undefined>;
getNextComparisonUris(
repoPath: string,
uri: Uri,
ref: string | undefined,
skip?: number,
): Promise<NextComparisonUrisResult | undefined>;
getOldestUnpushedRefForFile(repoPath: string, uri: Uri): Promise<string | undefined>;
getPreviousComparisonUris(
repoPath: string,
uri: Uri,
ref: string | undefined,
skip?: number,
): Promise<PreviousComparisonUrisResult | undefined>;
getPreviousComparisonUrisForLine(
repoPath: string,
uri: Uri,
editorLine: number,
ref: string | undefined,
skip?: number,
): Promise<PreviousLineComparisonUrisResult | undefined>;
getIncomingActivity(
repoPath: string,
options?: {
all?: boolean | undefined;
branch?: string | undefined;
limit?: number | undefined;
ordering?: 'date' | 'author-date' | 'topo' | null | undefined;
skip?: number | undefined;
},
): Promise<GitReflog | undefined>;
getRevisionContent(repoPath: string, path: string, ref: string): Promise<Uint8Array | undefined>;
getTreeEntryForRevision(repoPath: string, path: string, ref: string): Promise<GitTreeEntry | undefined>;
getTreeForRevision(repoPath: string, ref: string): Promise<GitTreeEntry[]>;
hasBranchOrTag(
repoPath: string | undefined,
options?: {
filter?:
| { branches?: ((b: GitBranch) => boolean) | undefined; tags?: ((t: GitTag) => boolean) | undefined }
| undefined;
},
): Promise<boolean>;
hasCommitBeenPushed(repoPath: string, ref: string): Promise<boolean>;
isAncestorOf(repoPath: string, ref1: string, ref2: string): Promise<boolean>;
getDiffTool?(repoPath?: string): Promise<string | undefined>;
openDiffTool?(
repoPath: string,
uri: Uri,
options?: {
ref1?: string | undefined;
ref2?: string | undefined;
staged?: boolean | undefined;
tool?: string | undefined;
},
): Promise<void>;
openDirectoryCompare?(repoPath: string, ref1: string, ref2?: string, tool?: string): Promise<void>;
resolveReference(
repoPath: string,
ref: string,
pathOrUri?: string | Uri,
options?: { force?: boolean; timeout?: number | undefined },
): Promise<string>;
richSearchCommits(
repoPath: string,
search: SearchQuery,
options?: {
limit?: number | undefined;
ordering?: 'date' | 'author-date' | 'topo' | null | undefined;
skip?: number | undefined;
},
): Promise<GitLog | undefined>;
searchCommits(
repoPath: string,
search: SearchQuery,
options?: {
cancellation?: CancellationToken;
limit?: number;
ordering?: 'date' | 'author-date' | 'topo';
},
): Promise<GitSearch>;
runGitCommandViaTerminal?(
repoPath: string,
command: string,
args: string[],
options?: { execute?: boolean },
): Promise<void>;
validateBranchOrTagName(repoPath: string, ref: string): Promise<boolean>;
validateReference(repoPath: string, ref: string): Promise<boolean>;
branches: GitBranchesSubProvider;
contributors: GitContributorsSubProvider;
patch?: GitPatchSubProvider;
remotes: GitRemotesSubProvider;
staging?: GitStagingSubProvider;
stash?: GitStashSubProvider;
status: GitStatusSubProvider;
tags: GitTagsSubProvider;
worktrees?: GitWorktreesSubProvider;
}
export type MergeDetectionConfidence = 'highest' | 'high' | 'medium';
export type GitBranchMergedStatus =
| { merged: false }
| { merged: true; confidence: MergeDetectionConfidence; localBranchOnly?: { name: string } };
export interface GitBranchesSubProvider {
getBranch(repoPath: string, name?: string): Promise<GitBranch | undefined>;
getBranches(
repoPath: string,
options?: {
filter?: ((b: GitBranch) => boolean) | undefined;
paging?: PagingOptions | undefined;
sort?: boolean | BranchSortOptions | undefined;
},
): Promise<PagedResult<GitBranch>>;
getBranchContributionsOverview(repoPath: string, ref: string): Promise<BranchContributionsOverview | undefined>;
getBranchesForCommit(
repoPath: string,
refs: string[],
branch?: string | undefined,
options?:
| { all?: boolean; commitDate?: Date; mode?: 'contains' | 'pointsAt' }
| { commitDate?: Date; mode?: 'contains' | 'pointsAt'; remotes?: boolean },
): Promise<string[]>;
getDefaultBranchName(repoPath: string | undefined, remote?: string): Promise<string | undefined>;
getMergeBase(
repoPath: string,
ref1: string,
ref2: string,
options?: { forkPoint?: boolean | undefined },
): Promise<string | undefined>;
createBranch?(repoPath: string, name: string, ref: string): Promise<void>;
/**
* Returns whether a branch has been merged into another branch
* @param repoPath The repository path
* @param branch The branch to check if merged
* @param into The branch to check if merged into
* @returns A promise of whether the branch is merged
*/
getBranchMergedStatus?(
repoPath: string,
branch: GitBranchReference,
into: GitBranchReference,
): Promise<GitBranchMergedStatus>;
getLocalBranchByUpstream?(repoPath: string, remoteBranchName: string): Promise<GitBranch | undefined>;
getPotentialMergeOrRebaseConflict?(
repoPath: string,
branch: string,
targetBranch: string,
): Promise<MergeConflict | undefined>;
getBaseBranchName?(repoPath: string, ref: string): Promise<string | undefined>;
setBaseBranchName?(repoPath: string, ref: string, base: string): Promise<void>;
getTargetBranchName?(repoPath: string, ref: string): Promise<string | undefined>;
setTargetBranchName?(repoPath: string, ref: string, target: string): Promise<void>;
renameBranch?(repoPath: string, oldName: string, newName: string): Promise<void>;
}
export interface GitContributorsSubProvider {
getContributorsStats(
repoPath: string,
options?: { merges?: boolean; since?: string },
): Promise<GitContributorStats | undefined>;
getContributors(
repoPath: string,
options?: {
all?: boolean | undefined;
merges?: boolean | 'first-parent';
ref?: string | undefined;
stats?: boolean | undefined;
},
): Promise<GitContributor[]>;
}
export interface GitPatchSubProvider {
applyUnreachableCommitForPatch(
repoPath: string,
ref: string,
options?: {
branchName?: string;
createBranchIfNeeded?: boolean;
createWorktreePath?: string;
stash?: boolean | 'prompt';
},
): Promise<void>;
createUnreachableCommitForPatch(
repoPath: string,
contents: string,
baseRef: string,
message: string,
): Promise<GitCommit | undefined>;
validatePatch(repoPath: string | undefined, contents: string): Promise<boolean>;
}
export interface GitRemotesSubProvider {
getRemote(
repoPath: string | undefined,
name: string,
cancellation?: CancellationToken,
): Promise<GitRemote | undefined>;
getRemotes(
repoPath: string | undefined,
options?: { filter?: (remote: GitRemote) => boolean; sort?: boolean },
cancellation?: CancellationToken,
): Promise<GitRemote[]>;
getDefaultRemote(repoPath: string, _cancellation?: CancellationToken): Promise<GitRemote | undefined>;
getRemotesWithProviders(
repoPath: string,
options?: { sort?: boolean },
cancellation?: CancellationToken,
): Promise<GitRemote<RemoteProvider>[]>;
getRemotesWithIntegrations(
repoPath: string,
options?: { sort?: boolean },
cancellation?: CancellationToken,
): Promise<GitRemote<RemoteProvider>[]>;
getBestRemoteWithProvider(
repoPath: string,
cancellation?: CancellationToken,
): Promise<GitRemote<RemoteProvider> | undefined>;
getBestRemotesWithProviders(
repoPath: string,
cancellation?: CancellationToken,
): Promise<GitRemote<RemoteProvider>[]>;
getBestRemoteWithIntegration(
repoPath: string,
options?: {
filter?: (remote: GitRemote, integration: HostingIntegration) => boolean;
includeDisconnected?: boolean;
},
cancellation?: CancellationToken,
): Promise<GitRemote<RemoteProvider> | undefined>;
addRemote?(repoPath: string, name: string, url: string, options?: { fetch?: boolean }): Promise<void>;
addRemoteWithResult?(
repoPath: string,
name: string,
url: string,
options?: { fetch?: boolean },
): Promise<GitRemote | undefined>;
pruneRemote?(repoPath: string, name: string): Promise<void>;
removeRemote?(repoPath: string, name: string): Promise<void>;
setRemoteAsDefault(repoPath: string, name: string, value?: boolean): Promise<void>;
}
export interface GitStagingSubProvider {
stageFile(repoPath: string, pathOrUri: string | Uri, options?: { intentToAdd?: boolean }): Promise<void>;
stageFiles(repoPath: string, pathOrUri: string[] | Uri[], options?: { intentToAdd?: boolean }): Promise<void>;
stageDirectory(repoPath: string, directoryOrUri: string | Uri, options?: { intentToAdd?: boolean }): Promise<void>;
unstageFile(repoPath: string, pathOrUri: string | Uri): Promise<void>;
unstageFiles(repoPath: string, pathOrUri: string[] | Uri[]): Promise<void>;
unstageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<void>;
}
export interface GitStashSubProvider {
applyStash(repoPath: string, stashName: string, options?: { deleteAfter?: boolean | undefined }): Promise<void>;
getStash(repoPath: string | undefined): Promise<GitStash | undefined>;
getStashCommitFiles(
repoPath: string,
ref: string,
options?: { include?: { stats?: boolean } },
): Promise<GitFileChange[]>;
deleteStash(repoPath: string, stashName: string, ref?: string): Promise<void>;
renameStash(repoPath: string, stashName: string, ref: string, message: string, stashOnRef?: string): Promise<void>;
saveStash(
repoPath: string,
message?: string,
uris?: Uri[],
options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean },
): Promise<void>;
saveSnapshot(repoPath: string, message?: string): Promise<void>;
}
export interface GitStatusSubProvider {
getStatus(repoPath: string | undefined): Promise<GitStatus | undefined>;
getStatusForFile?(repoPath: string, uri: Uri): Promise<GitStatusFile | undefined>;
getStatusForFiles?(repoPath: string, pathOrGlob: Uri): Promise<GitStatusFile[] | undefined>;
getPausedOperationStatus?(repoPath: string): Promise<GitPausedOperationStatus | undefined>;
abortPausedOperation?(repoPath: string, options?: { quit?: boolean }): Promise<void>;
continuePausedOperation?(repoPath: string, options?: { skip?: boolean }): Promise<void>;
}
export interface GitTagsSubProvider {
getTag(repoPath: string, name: string): Promise<GitTag | undefined>;
getTags(
repoPath: string,
options?: {
filter?: ((t: GitTag) => boolean) | undefined;
paging?: PagingOptions | undefined;
sort?: boolean | TagSortOptions | undefined;
},
): Promise<PagedResult<GitTag>>;
createTag?(repoPath: string, name: string, ref: string, message?: string): Promise<void>;
deleteTag?(repoPath: string, name: string): Promise<void>;
}
export interface GitWorktreesSubProvider {
createWorktree(
repoPath: string,
path: string,
options?: { commitish?: string; createBranch?: string; detach?: boolean; force?: boolean },
): Promise<void>;
createWorktreeWithResult(
repoPath: string,
path: string,
options?: { commitish?: string; createBranch?: string; detach?: boolean; force?: boolean },
): Promise<GitWorktree | undefined>;
getWorktree(repoPath: string, predicate: (w: GitWorktree) => boolean): Promise<GitWorktree | undefined>;
getWorktrees(repoPath: string): Promise<GitWorktree[]>;
getWorktreesDefaultUri(repoPath: string): Promise<Uri | undefined>;
deleteWorktree(repoPath: string, path: string | Uri, options?: { force?: boolean }): Promise<void>;
}
export type GitSubProvider =
| GitBranchesSubProvider
| GitContributorsSubProvider
| GitPatchSubProvider
| GitRemotesSubProvider
| GitStagingSubProvider
| GitStashSubProvider
| GitStatusSubProvider
| GitTagsSubProvider
| GitWorktreesSubProvider;
export type GitSubProviderProps = keyof {
[P in keyof GitProvider as NonNullable<GitProvider[P]> extends GitSubProvider ? P : never]: GitProvider[P];
};
export type NonNullableGitSubProviderProps = keyof {
[P in keyof GitProvider as GitProvider[P] extends GitSubProvider ? P : never]: GitProvider[P];
};
export type GitSubProviderForRepo<T extends GitSubProvider> = {
[K in keyof T]: RemoveFirstArg<T[K]>;
};
export function createSubProviderProxyForRepo<T extends GitSubProvider, U extends GitSubProviderForRepo<T>>(
target: T,
rp: string,
): U {
return new Proxy(target, {
get: (target, prop: string | symbol): unknown => {
const value = target[prop as keyof T];
if (typeof value === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return (...args: unknown[]) => value.call(target, rp, ...args);
}
return value;
},
}) as unknown as U;
}
export interface GitProvider extends GitRepositoryProvider, Disposable {
get onDidChange(): Event<void>;
get onWillChangeRepository(): Event<RepositoryChangeEvent>;
get onDidChangeRepository(): Event<RepositoryChangeEvent>;
get onDidCloseRepository(): Event<RepositoryCloseEvent>;
get onDidOpenRepository(): Event<RepositoryOpenEvent>;
readonly descriptor: GitProviderDescriptor;
readonly supportedSchemes: Set<string>;
discoverRepositories(
uri: Uri,
options?: { cancellation?: CancellationToken; depth?: number; silent?: boolean },
): Promise<Repository[]>;
updateContext?(): void;
openRepository(
folder: WorkspaceFolder | undefined,
uri: Uri,
root: boolean,
suspended?: boolean,
closed?: boolean,
): Repository[];
openRepositoryInitWatcher?(): RepositoryInitWatcher;
supports(feature: Features): Promise<boolean>;
visibility(
repoPath: string,
remotes?: GitRemote[],
): Promise<[visibility: RepositoryVisibility, cacheKey: string | undefined]>;
getOpenScmRepositories(): Promise<ScmRepository[]>;
getScmRepository(repoPath: string): Promise<ScmRepository | undefined>;
getOrOpenScmRepository(repoPath: string): Promise<ScmRepository | undefined>;
canHandlePathOrUri(scheme: string, pathOrUri: string | Uri): string | undefined;
findRepositoryUri(uri: Uri, isDirectory?: boolean): Promise<Uri | undefined>;
getAbsoluteUri(pathOrUri: string | Uri, base: string | Uri): Uri;
getBestRevisionUri(repoPath: string, path: string, ref: string | undefined): Promise<Uri | undefined>;
getRelativePath(pathOrUri: string | Uri, base: string | Uri): string;
getRevisionUri(repoPath: string, path: string, ref: string): Uri;
// getRootUri(pathOrUri: string | Uri): Uri;
getWorkingUri(repoPath: string, uri: Uri): Promise<Uri | undefined>;
applyChangesToWorkingFile?(uri: GitUri, ref1?: string, ref2?: string): Promise<void>;
clone?(url: string, parentPath: string): Promise<string | undefined>;
/**
* Returns the blame of a file
* @param uri Uri of the file to blame
* @param document Optional TextDocument to blame the contents of if dirty
*/
getBlame(uri: GitUri, document?: TextDocument | undefined): Promise<GitBlame | undefined>;
/**
* Returns the blame of a file, using the editor contents (for dirty editors)
* @param uri Uri of the file to blame
* @param contents Contents from the editor to use
*/
getBlameContents(uri: GitUri, contents: string): Promise<GitBlame | undefined>;
/**
* Returns the blame of a single line
* @param uri Uri of the file to blame
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param document Optional TextDocument to blame the contents of if dirty
* @param options.forceSingleLine Forces blame to be for the single line (rather than the whole file)
*/
getBlameForLine(
uri: GitUri,
editorLine: number,
document?: TextDocument | undefined,
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined>;
/**
* Returns the blame of a single line, using the editor contents (for dirty editors)
* @param uri Uri of the file to blame
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param contents Contents from the editor to use
*/
getBlameForLineContents(
uri: GitUri,
editorLine: number,
contents: string,
options?: { forceSingleLine?: boolean },
): Promise<GitBlameLine | undefined>;
getBlameForRange(uri: GitUri, range: Range): Promise<GitBlame | undefined>;
getBlameForRangeContents(uri: GitUri, range: Range, contents: string): Promise<GitBlame | undefined>;
getBlameRange(blame: GitBlame, uri: GitUri, range: Range): GitBlame | undefined;
/**
* Returns a file diff between two commits
* @param uri Uri of the file to diff
* @param ref1 Commit to diff from
* @param ref2 Commit to diff to
*/
getDiffForFile(uri: GitUri, ref1: string | undefined, ref2?: string): Promise<GitDiffFile | undefined>;
/**
* Returns a file diff between a commit and the specified contents
* @param uri Uri of the file to diff
* @param ref Commit to diff from
* @param contents Contents to use for the diff
*/
getDiffForFileContents(uri: GitUri, ref: string, contents: string): Promise<GitDiffFile | undefined>;
/**
* Returns a line diff between two commits
* @param uri Uri of the file to diff
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param ref1 Commit to diff from
* @param ref2 Commit to diff to
*/
getDiffForLine(
uri: GitUri,
editorLine: number,
ref1: string | undefined,
ref2?: string,
): Promise<GitDiffLine | undefined>;
hasUnsafeRepositories?(): boolean;
isTrackable(uri: Uri): boolean;
isTracked(uri: Uri): Promise<boolean>;
}
export interface RevisionUriData {
ref?: string;
repoPath: string;
uncPath?: string;
}