Skip to content

Commit

Permalink
use options instead of flags in rebase command
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Dec 5, 2024
1 parent 765eaab commit 3d39d01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
23 changes: 14 additions & 9 deletions src/commands/git/rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ interface Context {
}

type Flags = '--interactive';
type RebaseOptions = { interactive?: boolean };

interface State {
repo: string | Repository;
destination: GitReference;
flags: Flags[];
options: RebaseOptions;
}

export interface RebaseGitCommandArgs {
Expand Down Expand Up @@ -82,13 +84,13 @@ export class RebaseGitCommand extends QuickCommand<State> {

async execute(state: RebaseStepState) {
const configs: { sequenceEditor?: string } = {};
if (state.flags.includes('--interactive')) {
if (state.options?.interactive) {
await this.container.rebaseEditor.enableForNextUse();
configs.sequenceEditor = getEditorCommand();
}

try {
await state.repo.git.rebase(state.destination.ref, configs, state.flags);
await state.repo.git.rebase(state.destination.ref, configs, state.options);
} catch (ex) {
Logger.error(ex, this.title);
void showGenericErrorMessage(ex);
Expand All @@ -108,8 +110,8 @@ export class RebaseGitCommand extends QuickCommand<State> {
title: this.title,
};

if (state.flags == null) {
state.flags = [];
if (state.options == null) {
state.options = {};
}

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

state.flags = result;
state.options = Object.assign(state.options ?? {}, ...result);

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

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

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

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

const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
const step: QuickPickStep<FlagsQuickPickItem<RebaseOptions>> = this.createConfirmStep(
appendReposToTitle(`Confirm ${title}`, state, context),
rebaseItems,
);

state.options = Object.assign(state.options, ...optionsArr);
const selection: StepSelection<typeof step> = yield step;
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResultBreak;
}
Expand Down
14 changes: 6 additions & 8 deletions src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,17 +1343,15 @@ export class GitProviderService implements Disposable {
}

@log()
rebase(repoPath: string | Uri, ref: string, configs: { sequenceEditor?: string }, args: string[] | undefined = []) {
rebase(
repoPath: string | Uri,
ref: string,
configs: { sequenceEditor?: string },
options: { interactive?: boolean } = {},
): Promise<void> {
const { provider, path } = this.getProvider(repoPath);
if (provider.rebase == null) throw new ProviderNotSupportedError(provider.descriptor.name);

const options: { interactive?: boolean } = {};
for (const arg of args) {
if (arg === '--interactive') {
options.interactive = true;
}
}

return provider.rebase(path, ref, configs, options);
}

Expand Down

0 comments on commit 3d39d01

Please sign in to comment.