Skip to content

Commit 2b0e420

Browse files
committed
Changes more provider methods to be optional
- Throws a new not supported error for many provider methods Changes stash method naming for consistency
1 parent 0a4daa6 commit 2b0e420

File tree

6 files changed

+101
-114
lines changed

6 files changed

+101
-114
lines changed

src/env/node/git/localGitProvider.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5769,7 +5769,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
57695769
}
57705770

57715771
@log()
5772-
async stashApply(repoPath: string, stashName: string, options?: { deleteAfter?: boolean }): Promise<void> {
5772+
async applyStash(repoPath: string, stashName: string, options?: { deleteAfter?: boolean }): Promise<void> {
57735773
try {
57745774
await this.git.stash__apply(repoPath, stashName, Boolean(options?.deleteAfter));
57755775
} catch (ex) {
@@ -5798,13 +5798,13 @@ export class LocalGitProvider implements GitProvider, Disposable {
57985798
}
57995799

58005800
@log()
5801-
async stashDelete(repoPath: string, stashName: string, ref?: string): Promise<void> {
5801+
async deleteStash(repoPath: string, stashName: string, ref?: string): Promise<void> {
58025802
await this.git.stash__delete(repoPath, stashName, ref);
58035803
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['stashes'] });
58045804
}
58055805

58065806
@log()
5807-
async stashRename(
5807+
async renameStash(
58085808
repoPath: string,
58095809
stashName: string,
58105810
ref: string,
@@ -5815,8 +5815,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
58155815
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['stashes'] });
58165816
}
58175817

5818-
@log<LocalGitProvider['stashSave']>({ args: { 2: uris => uris?.length } })
5819-
async stashSave(
5818+
@log<LocalGitProvider['saveStash']>({ args: { 2: uris => uris?.length } })
5819+
async saveStash(
58205820
repoPath: string,
58215821
message?: string,
58225822
uris?: Uri[],
@@ -5863,7 +5863,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
58635863
}
58645864

58655865
@log()
5866-
async stashSaveSnapshot(repoPath: string, message?: string): Promise<void> {
5866+
async saveStashSnapshot(repoPath: string, message?: string): Promise<void> {
58675867
const id = await this.git.stash__create(repoPath);
58685868
if (id == null) return;
58695869

src/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ export class ProviderNotFoundError extends Error {
210210
}
211211
}
212212

213+
export class ProviderNotSupportedError extends Error {
214+
constructor(provider: string) {
215+
super(`Action is not supported on the ${provider} provider.`);
216+
217+
Error.captureStackTrace?.(this, ProviderNotSupportedError);
218+
}
219+
}
220+
213221
export class RequestClientError extends Error {
214222
constructor(public readonly original: Error) {
215223
super(original.message);

src/git/gitProvider.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ export interface RepositoryVisibilityInfo {
113113
}
114114

115115
export interface GitProviderRepository {
116-
addRemote(repoPath: string, name: string, url: string, options?: { fetch?: boolean }): Promise<void>;
117-
pruneRemote(repoPath: string, name: string): Promise<void>;
118-
removeRemote(repoPath: string, name: string): Promise<void>;
116+
addRemote?(repoPath: string, name: string, url: string, options?: { fetch?: boolean }): Promise<void>;
117+
pruneRemote?(repoPath: string, name: string): Promise<void>;
118+
removeRemote?(repoPath: string, name: string): Promise<void>;
119119
applyUnreachableCommitForPatch?(
120120
repoPath: string,
121121
ref: string,
@@ -126,7 +126,7 @@ export interface GitProviderRepository {
126126
stash?: boolean | 'prompt';
127127
},
128128
): Promise<void>;
129-
checkout(
129+
checkout?(
130130
repoPath: string,
131131
ref: string,
132132
options?: { createBranch?: string | undefined } | { path?: string | undefined },
@@ -139,7 +139,7 @@ export interface GitProviderRepository {
139139
): Promise<GitCommit | undefined>;
140140
excludeIgnoredUris(repoPath: string, uris: Uri[]): Promise<Uri[]>;
141141

142-
fetch(
142+
fetch?(
143143
repoPath: string,
144144
options?: {
145145
all?: boolean | undefined;
@@ -149,15 +149,15 @@ export interface GitProviderRepository {
149149
remote?: string | undefined;
150150
},
151151
): Promise<void>;
152-
pull(
152+
pull?(
153153
repoPath: string,
154154
options?: {
155155
branch?: GitBranchReference | undefined;
156156
rebase?: boolean | undefined;
157157
tags?: boolean | undefined;
158158
},
159159
): Promise<void>;
160-
push(
160+
push?(
161161
repoPath: string,
162162
options?: {
163163
reference?: GitReference | undefined;
@@ -333,7 +333,7 @@ export interface GitProviderRepository {
333333
options?: { filter?: (remote: GitRemote) => boolean; sort?: boolean },
334334
): Promise<GitRemote[]>;
335335
getRevisionContent(repoPath: string, path: string, ref: string): Promise<Uint8Array | undefined>;
336-
getStash(repoPath: string | undefined): Promise<GitStash | undefined>;
336+
getStash?(repoPath: string | undefined): Promise<GitStash | undefined>;
337337
getStatus(repoPath: string | undefined): Promise<GitStatus | undefined>;
338338
getStatusForFile(repoPath: string, uri: Uri): Promise<GitStatusFile | undefined>;
339339
getStatusForFiles(repoPath: string, pathOrGlob: Uri): Promise<GitStatusFile[] | undefined>;
@@ -359,8 +359,8 @@ export interface GitProviderRepository {
359359
hasCommitBeenPushed(repoPath: string, ref: string): Promise<boolean>;
360360
isAncestorOf(repoPath: string, ref1: string, ref2: string): Promise<boolean>;
361361

362-
getDiffTool(repoPath?: string): Promise<string | undefined>;
363-
openDiffTool(
362+
getDiffTool?(repoPath?: string): Promise<string | undefined>;
363+
openDiffTool?(
364364
repoPath: string,
365365
uri: Uri,
366366
options?: {
@@ -370,7 +370,7 @@ export interface GitProviderRepository {
370370
tool?: string | undefined;
371371
},
372372
): Promise<void>;
373-
openDirectoryCompare(repoPath: string, ref1: string, ref2?: string, tool?: string): Promise<void>;
373+
openDirectoryCompare?(repoPath: string, ref1: string, ref2?: string, tool?: string): Promise<void>;
374374

375375
resolveReference(
376376
repoPath: string,
@@ -413,16 +413,16 @@ export interface GitProviderRepository {
413413
unstageFile(repoPath: string, pathOrUri: string | Uri): Promise<void>;
414414
unstageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<void>;
415415

416-
stashApply?(repoPath: string, stashName: string, options?: { deleteAfter?: boolean | undefined }): Promise<void>;
417-
stashDelete?(repoPath: string, stashName: string, ref?: string): Promise<void>;
418-
stashRename?(repoPath: string, stashName: string, ref: string, message: string, stashOnRef?: string): Promise<void>;
419-
stashSave?(
416+
applyStash?(repoPath: string, stashName: string, options?: { deleteAfter?: boolean | undefined }): Promise<void>;
417+
deleteStash?(repoPath: string, stashName: string, ref?: string): Promise<void>;
418+
renameStash?(repoPath: string, stashName: string, ref: string, message: string, stashOnRef?: string): Promise<void>;
419+
saveStash?(
420420
repoPath: string,
421421
message?: string,
422422
uris?: Uri[],
423423
options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean },
424424
): Promise<void>;
425-
stashSaveSnapshot?(repoPath: string, message?: string): Promise<void>;
425+
saveStashSnapshot?(repoPath: string, message?: string): Promise<void>;
426426

427427
createWorktree?(
428428
repoPath: string,
@@ -476,7 +476,7 @@ export interface GitProvider extends GitProviderRepository, Disposable {
476476
// getRootUri(pathOrUri: string | Uri): Uri;
477477
getWorkingUri(repoPath: string, uri: Uri): Promise<Uri | undefined>;
478478

479-
applyChangesToWorkingFile(uri: GitUri, ref1?: string, ref2?: string): Promise<void>;
479+
applyChangesToWorkingFile?(uri: GitUri, ref1?: string, ref2?: string): Promise<void>;
480480
clone?(url: string, parentPath: string): Promise<string | undefined>;
481481
/**
482482
* Returns the blame of a file

0 commit comments

Comments
 (0)