Skip to content

Commit 12c62fc

Browse files
committed
Refactors Git provider into sub-providers
- Branch operations
1 parent 1f0bef0 commit 12c62fc

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

+1061
-969
lines changed

src/commands/copyCurrentBranch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CopyCurrentBranchCommand extends ActiveEditorCommand {
2424
if (repository == null) return;
2525

2626
try {
27-
const branch = await repository.git.getBranch();
27+
const branch = await repository.git.branches().getBranch();
2828
if (branch?.name) {
2929
await env.clipboard.writeText(branch.name);
3030
}

src/commands/createPullRequestOnRemote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class CreatePullRequestOnRemoteCommand extends GlCommandBase {
3535
if (repo == null) return;
3636

3737
if (args == null) {
38-
const branch = await repo.git.getBranch();
38+
const branch = await repo.git.branches().getBranch();
3939
if (branch?.upstream == null) {
4040
void window.showErrorMessage(
4141
`Unable to create a pull request for branch \`${branch?.name}\` because it has no upstream branch`,

src/commands/git/branch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export class BranchGitCommand extends QuickCommand {
362362
if (state.counter < 3 || state.reference == null) {
363363
const result = yield* pickBranchOrTagStep(state, context, {
364364
placeholder: `Choose a base to create the new branch from`,
365-
picked: state.reference?.ref ?? (await state.repo.git.getBranch())?.ref,
365+
picked: state.reference?.ref ?? (await state.repo.git.branches().getBranch())?.ref,
366366
title: 'Select Base to Create Branch From',
367367
value: isRevisionReference(state.reference) ? state.reference.ref : undefined,
368368
});
@@ -423,7 +423,7 @@ export class BranchGitCommand extends QuickCommand {
423423
await state.repo.switch(state.reference.ref, { createBranch: state.name });
424424
} else {
425425
try {
426-
await state.repo.git.createBranch(state.name, state.reference.ref);
426+
await state.repo.git.branches().createBranch?.(state.name, state.reference.ref);
427427
} catch (ex) {
428428
Logger.error(ex);
429429
// TODO likely need some better error handling here
@@ -433,7 +433,7 @@ export class BranchGitCommand extends QuickCommand {
433433

434434
if (state.associateWithIssue != null) {
435435
const issue = state.associateWithIssue;
436-
const branch = await state.repo.git.getBranch(state.name);
436+
const branch = await state.repo.git.branches().getBranch(state.name);
437437
// TODO: These descriptors are hacked in. Use an integration function to get the right resource for the issue.
438438
const owner = getIssueOwner(issue);
439439
if (branch != null && owner != null) {
@@ -675,7 +675,7 @@ export class BranchGitCommand extends QuickCommand {
675675

676676
endSteps(state);
677677
try {
678-
await state.repo.git.renameBranch(state.reference.ref, state.name);
678+
await state.repo.git.branches().renameBranch?.(state.reference.ref, state.name);
679679
} catch (ex) {
680680
Logger.error(ex);
681681
// TODO likely need some better error handling here

src/commands/git/cherry-pick.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class CherryPickGitCommand extends QuickCommand<State> {
132132
}
133133

134134
if (context.destination == null) {
135-
const branch = await state.repo.git.getBranch();
135+
const branch = await state.repo.git.branches().getBranch();
136136
if (branch == null) break;
137137

138138
context.destination = branch;
@@ -173,14 +173,13 @@ export class CherryPickGitCommand extends QuickCommand<State> {
173173
}
174174

175175
if (context.selectedBranchOrTag == null && state.references?.length) {
176-
const branches = await this.container.git.getCommitBranches(
177-
state.repo.path,
176+
const branches = await state.repo.git.branches().getBranchesForCommit(
178177
state.references.map(r => r.ref),
179178
undefined,
180179
{ mode: 'contains' },
181180
);
182181
if (branches.length) {
183-
const branch = await state.repo.git.getBranch(branches[0]);
182+
const branch = await state.repo.git.branches().getBranch(branches[0]);
184183
if (branch != null) {
185184
context.selectedBranchOrTag = branch;
186185
}

src/commands/git/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class LogGitCommand extends QuickCommand<State> {
118118
assertStateStepRepository(state);
119119

120120
if (state.reference === 'HEAD') {
121-
const branch = await state.repo.git.getBranch();
121+
const branch = await state.repo.git.branches().getBranch();
122122
state.reference = branch;
123123
}
124124

src/commands/git/merge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class MergeGitCommand extends QuickCommand<State> {
125125
}
126126

127127
if (context.destination == null) {
128-
const branch = await state.repo.git.getBranch();
128+
const branch = await state.repo.git.branches().getBranch();
129129
if (branch == null) break;
130130

131131
context.destination = branch;

src/commands/git/pull.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PullGitCommand extends QuickCommand<State> {
6767
if (isBranchReference(state.reference)) {
6868
// Only resort to a branch fetch if the branch isn't the current one
6969
if (!isBranch(state.reference) || !state.reference.current) {
70-
const currentBranch = await state.repos[0].git.getBranch();
70+
const currentBranch = await state.repos[0].git.branches().getBranch();
7171
if (currentBranch?.name !== state.reference.name) {
7272
return state.repos[0].fetch({ branch: state.reference, pull: true });
7373
}
@@ -167,7 +167,7 @@ export class PullGitCommand extends QuickCommand<State> {
167167
);
168168
} else {
169169
const [repo] = state.repos;
170-
const branch = await repo.git.getBranch(state.reference.name);
170+
const branch = await repo.git.branches().getBranch(state.reference.name);
171171

172172
if (branch?.upstream == null) {
173173
step = this.createConfirmStep(

src/commands/git/push.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class PushGitCommand extends QuickCommand<State> {
197197
{ placeholder: 'Cannot push a remote branch' },
198198
);
199199
} else {
200-
const branch = await repo.git.getBranch(state.reference.name);
200+
const branch = await repo.git.branches().getBranch(state.reference.name);
201201

202202
if (branch != null && branch?.upstream == null) {
203203
for (const remote of await repo.git.getRemotes()) {

src/commands/git/rebase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
135135
}
136136

137137
if (context.branch == null) {
138-
const branch = await state.repo.git.getBranch();
138+
const branch = await state.repo.git.branches().getBranch();
139139
if (branch == null) break;
140140

141141
context.branch = branch;

src/commands/git/reset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class ResetGitCommand extends QuickCommand<State> {
110110
}
111111

112112
if (context.destination == null) {
113-
const branch = await state.repo.git.getBranch();
113+
const branch = await state.repo.git.branches().getBranch();
114114
if (branch == null) break;
115115

116116
context.destination = branch;

0 commit comments

Comments
 (0)