Skip to content

Commit 3d39d01

Browse files
committed
use options instead of flags in rebase command
1 parent 765eaab commit 3d39d01

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/commands/git/rebase.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ interface Context {
3939
}
4040

4141
type Flags = '--interactive';
42+
type RebaseOptions = { interactive?: boolean };
4243

4344
interface State {
4445
repo: string | Repository;
4546
destination: GitReference;
4647
flags: Flags[];
48+
options: RebaseOptions;
4749
}
4850

4951
export interface RebaseGitCommandArgs {
@@ -82,13 +84,13 @@ export class RebaseGitCommand extends QuickCommand<State> {
8284

8385
async execute(state: RebaseStepState) {
8486
const configs: { sequenceEditor?: string } = {};
85-
if (state.flags.includes('--interactive')) {
87+
if (state.options?.interactive) {
8688
await this.container.rebaseEditor.enableForNextUse();
8789
configs.sequenceEditor = getEditorCommand();
8890
}
8991

9092
try {
91-
await state.repo.git.rebase(state.destination.ref, configs, state.flags);
93+
await state.repo.git.rebase(state.destination.ref, configs, state.options);
9294
} catch (ex) {
9395
Logger.error(ex, this.title);
9496
void showGenericErrorMessage(ex);
@@ -108,8 +110,8 @@ export class RebaseGitCommand extends QuickCommand<State> {
108110
title: this.title,
109111
};
110112

111-
if (state.flags == null) {
112-
state.flags = [];
113+
if (state.options == null) {
114+
state.options = {};
113115
}
114116

115117
let skippedStepOne = false;
@@ -212,7 +214,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
212214
const result = yield* this.confirmStep(state as RebaseStepState, context);
213215
if (result === StepResultBreak) continue;
214216

215-
state.flags = result;
217+
state.options = Object.assign(state.options ?? {}, ...result);
216218

217219
endSteps(state);
218220
void this.execute(state as RebaseStepState);
@@ -221,7 +223,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
221223
return state.counter < 0 ? StepResultBreak : undefined;
222224
}
223225

224-
private async *confirmStep(state: RebaseStepState, context: Context): AsyncStepResultGenerator<Flags[]> {
226+
private async *confirmStep(state: RebaseStepState, context: Context): AsyncStepResultGenerator<RebaseOptions[]> {
225227
const counts = await this.container.git.getLeftRightCommitCount(
226228
state.repo.path,
227229
createRevisionRange(state.destination.ref, context.branch.ref, '...'),
@@ -253,8 +255,9 @@ export class RebaseGitCommand extends QuickCommand<State> {
253255
return StepResultBreak;
254256
}
255257

258+
const optionsArr: RebaseOptions[] = [];
256259
const rebaseItems = [
257-
createFlagsQuickPickItem<Flags>(state.flags, ['--interactive'], {
260+
createFlagsQuickPickItem<RebaseOptions>(optionsArr, [{ interactive: true }], {
258261
label: `Interactive ${this.title}`,
259262
description: '--interactive',
260263
detail: `Will interactively update ${getReferenceLabel(context.branch, {
@@ -267,7 +270,7 @@ export class RebaseGitCommand extends QuickCommand<State> {
267270

268271
if (behind > 0) {
269272
rebaseItems.unshift(
270-
createFlagsQuickPickItem<Flags>(state.flags, [], {
273+
createFlagsQuickPickItem<RebaseOptions>(optionsArr, [{}], {
271274
label: this.title,
272275
detail: `Will update ${getReferenceLabel(context.branch, {
273276
label: false,
@@ -278,10 +281,12 @@ export class RebaseGitCommand extends QuickCommand<State> {
278281
);
279282
}
280283

281-
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
284+
const step: QuickPickStep<FlagsQuickPickItem<RebaseOptions>> = this.createConfirmStep(
282285
appendReposToTitle(`Confirm ${title}`, state, context),
283286
rebaseItems,
284287
);
288+
289+
state.options = Object.assign(state.options, ...optionsArr);
285290
const selection: StepSelection<typeof step> = yield step;
286291
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResultBreak;
287292
}

src/git/gitProviderService.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,17 +1343,15 @@ export class GitProviderService implements Disposable {
13431343
}
13441344

13451345
@log()
1346-
rebase(repoPath: string | Uri, ref: string, configs: { sequenceEditor?: string }, args: string[] | undefined = []) {
1346+
rebase(
1347+
repoPath: string | Uri,
1348+
ref: string,
1349+
configs: { sequenceEditor?: string },
1350+
options: { interactive?: boolean } = {},
1351+
): Promise<void> {
13471352
const { provider, path } = this.getProvider(repoPath);
13481353
if (provider.rebase == null) throw new ProviderNotSupportedError(provider.descriptor.name);
13491354

1350-
const options: { interactive?: boolean } = {};
1351-
for (const arg of args) {
1352-
if (arg === '--interactive') {
1353-
options.interactive = true;
1354-
}
1355-
}
1356-
13571355
return provider.rebase(path, ref, configs, options);
13581356
}
13591357

0 commit comments

Comments
 (0)