Skip to content

Commit 246e12e

Browse files
committed
Refactors Git provider into sub-providers
- Remote operations - Tag operations
1 parent 6f23b56 commit 246e12e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+819
-694
lines changed

src/annotations/lineAnnotationController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class LineAnnotationController implements Disposable {
157157
const prs = new Map<string, Promise<PullRequest | undefined>>();
158158
if (lines.size === 0) return prs;
159159

160-
const remotePromise = this.container.git.getBestRemoteWithIntegration(repoPath);
160+
const remotePromise = this.container.git.remotes(repoPath).getBestRemoteWithIntegration();
161161

162162
for (const [, state] of lines) {
163163
if (state.commit.isUncommitted) continue;

src/avatars.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ async function getAvatarUriFromRemoteProvider(
227227
// account = await remote?.provider.getAccountForEmail(email, { avatarSize: size });
228228
// } else {
229229
if (typeof repoPathOrCommit !== 'string') {
230-
const remote = await Container.instance.git.getBestRemoteWithIntegration(repoPathOrCommit.repoPath);
230+
const remote = await Container.instance.git
231+
.remotes(repoPathOrCommit.repoPath)
232+
.getBestRemoteWithIntegration();
231233
if (remote?.hasIntegration()) {
232234
account = await (
233235
await remote.getIntegration()

src/commands/copyDeepLink.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
128128

129129
try {
130130
let chosenRemote;
131-
const remotes = await this.container.git.getRemotes(repoPath, { sort: true });
131+
const remotes = await this.container.git.remotes(repoPath).getRemotes({ sort: true });
132132
const defaultRemote = remotes.find(r => r.default);
133133
if (args.remote && !args.prePickRemote) {
134134
chosenRemote = remotes.find(r => r.name === args?.remote);
@@ -291,7 +291,7 @@ export class CopyFileDeepLinkCommand extends ActiveEditorCommand {
291291

292292
try {
293293
let chosenRemote;
294-
const remotes = await this.container.git.getRemotes(repoPath, { sort: true });
294+
const remotes = await this.container.git.remotes(repoPath).getRemotes({ sort: true });
295295
const defaultRemote = remotes.find(r => r.default);
296296
if (args.remote && !args.prePickRemote) {
297297
chosenRemote = remotes.find(r => r.name === args?.remote);

src/commands/createPullRequestOnRemote.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export class CreatePullRequestOnRemoteCommand extends GlCommandBase {
5151
};
5252
}
5353

54-
const compareRemote = await repo.git.getRemote(args.remote);
54+
const compareRemote = await repo.git.remotes().getRemote(args.remote);
5555
if (compareRemote?.provider == null) return;
5656

5757
const providerId = compareRemote.provider.id;
58-
const remotes = (await repo.git.getRemotes({
58+
const remotes = (await repo.git.remotes().getRemotes({
5959
filter: r => r.provider?.id === providerId,
6060
sort: true,
6161
})) as GitRemote<RemoteProvider>[];

src/commands/ghpr/openOrCreateWorktree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class OpenOrCreateWorktreeCommand extends GlCommandBase {
8686
const remoteUrl = remoteUri.toString();
8787
const [, remoteDomain, remotePath] = parseGitRemoteUrl(remoteUrl);
8888

89-
const remotes = await repo.git.getRemotes({ filter: r => r.matches(remoteDomain, remotePath) });
89+
const remotes = await repo.git.remotes().getRemotes({ filter: r => r.matches(remoteDomain, remotePath) });
9090
const remote = remotes[0] as GitRemote | undefined;
9191

9292
let addRemote: { name: string; url: string } | undefined;

src/commands/git/push.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class PushGitCommand extends QuickCommand<State> {
200200
const branch = await repo.git.branches().getBranch(state.reference.name);
201201

202202
if (branch != null && branch?.upstream == null) {
203-
for (const remote of await repo.git.getRemotes()) {
203+
for (const remote of await repo.git.remotes().getRemotes()) {
204204
items.push(
205205
createFlagsQuickPickItem<Flags>(
206206
state.flags,
@@ -317,7 +317,7 @@ export class PushGitCommand extends QuickCommand<State> {
317317
pushDetails = '';
318318
}
319319

320-
for (const remote of await repo.git.getRemotes()) {
320+
for (const remote of await repo.git.remotes().getRemotes()) {
321321
items.push(
322322
createFlagsQuickPickItem<Flags>(
323323
state.flags,

src/commands/git/remote.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ export class RemoteGitCommand extends QuickCommand<State> {
288288
state.flags = ['-f'];
289289
}
290290

291-
let alreadyExists = (await state.repo.git.getRemotes({ filter: r => r.name === state.name })).length !== 0;
291+
let alreadyExists =
292+
(await state.repo.git.remotes().getRemotes({ filter: r => r.name === state.name })).length !== 0;
292293

293294
while (this.canStepsContinue(state)) {
294295
if (state.counter < 3 || state.name == null || alreadyExists) {
@@ -298,7 +299,8 @@ export class RemoteGitCommand extends QuickCommand<State> {
298299
});
299300
if (result === StepResultBreak) continue;
300301

301-
alreadyExists = (await state.repo.git.getRemotes({ filter: r => r.name === result })).length !== 0;
302+
alreadyExists =
303+
(await state.repo.git.remotes().getRemotes({ filter: r => r.name === result })).length !== 0;
302304
if (alreadyExists) {
303305
state.counter--;
304306
continue;
@@ -364,7 +366,9 @@ export class RemoteGitCommand extends QuickCommand<State> {
364366
while (this.canStepsContinue(state)) {
365367
if (state.remote != null) {
366368
if (typeof state.remote === 'string') {
367-
const [remote] = await state.repo.git.getRemotes({ filter: r => r.name === state.remote });
369+
const [remote] = await state.repo.git
370+
.remotes()
371+
.getRemotes({ filter: r => r.name === state.remote });
368372
if (remote != null) {
369373
state.remote = remote;
370374
} else {
@@ -390,7 +394,7 @@ export class RemoteGitCommand extends QuickCommand<State> {
390394

391395
endSteps(state);
392396
try {
393-
await state.repo.git.removeRemote(state.remote.name);
397+
await state.repo.git.remotes().removeRemote?.(state.remote.name);
394398
} catch (ex) {
395399
Logger.error(ex);
396400
void showGenericErrorMessage('Unable to remove remote');
@@ -420,7 +424,9 @@ export class RemoteGitCommand extends QuickCommand<State> {
420424
while (this.canStepsContinue(state)) {
421425
if (state.remote != null) {
422426
if (typeof state.remote === 'string') {
423-
const [remote] = await state.repo.git.getRemotes({ filter: r => r.name === state.remote });
427+
const [remote] = await state.repo.git
428+
.remotes()
429+
.getRemotes({ filter: r => r.name === state.remote });
424430
if (remote != null) {
425431
state.remote = remote;
426432
} else {
@@ -445,7 +451,7 @@ export class RemoteGitCommand extends QuickCommand<State> {
445451
if (result === StepResultBreak) continue;
446452

447453
endSteps(state);
448-
void state.repo.git.pruneRemote(state.remote.name);
454+
void state.repo.git.remotes().pruneRemote?.(state.remote.name);
449455
}
450456
}
451457

src/commands/git/tag.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class TagGitCommand extends QuickCommand<State> {
292292

293293
endSteps(state);
294294
try {
295-
await state.repo.git.createTag(state.name, state.reference.ref, state.message);
295+
await state.repo.git.tags().createTag?.(state.name, state.reference.ref, state.message);
296296
} catch (ex) {
297297
Logger.error(ex, context.title);
298298
void showGenericErrorMessage(ex);
@@ -381,7 +381,7 @@ export class TagGitCommand extends QuickCommand<State> {
381381
endSteps(state);
382382
for (const { ref } of state.references) {
383383
try {
384-
await state.repo.git.deleteTag(ref);
384+
await state.repo.git.tags().deleteTag?.(ref);
385385
} catch (ex) {
386386
Logger.error(ex, context.title);
387387
void showGenericErrorMessage(ex);

src/commands/openAssociatedPullRequestOnRemote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorComman
3636
} else {
3737
try {
3838
const repo = await getRepositoryOrShowPicker('Open Associated Pull Request', undefined, undefined, {
39-
filter: async r => (await this.container.git.getBestRemoteWithIntegration(r.uri)) != null,
39+
filter: async r => (await this.container.git.remotes(r.uri).getBestRemoteWithIntegration()) != null,
4040
});
4141
if (repo == null) return;
4242

src/commands/openFileOnRemote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
121121
args = { range: true, ...args };
122122

123123
try {
124-
let remotes = await this.container.git.getRemotesWithProviders(gitUri.repoPath, { sort: true });
124+
let remotes = await this.container.git.remotes(gitUri.repoPath).getRemotesWithProviders({ sort: true });
125125

126126
let range: Range | undefined;
127127
if (args.range) {

0 commit comments

Comments
 (0)