Skip to content

Commit

Permalink
Closes #1269 - splits revert and revert + edit
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 16, 2020
1 parent 413f17a commit a8432e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Changed

- Increases the thickness (boldness) of a handful of icons to better match VS Code codicons
- Changes the options on the _Git Command Palette_'s _revert_ command to now be _Revert_ (`--no-edit`) and _Revert & Edit_ (`--edit`) — closes [#1269](https://github.com/eamodio/vscode-gitlens/issues/1269)
- Changes the thickness (boldness) of a handful of icons to better match VS Code codicons

### Fixed

Expand Down
34 changes: 23 additions & 11 deletions src/commands/git/revert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
import { QuickPickItem } from 'vscode';
import { Container } from '../../container';
import { GitBranch, GitLog, GitReference, GitRevisionReference, Repository } from '../../git/git';
import {
Expand All @@ -15,6 +14,7 @@ import {
StepSelection,
StepState,
} from '../quickCommand';
import { FlagsQuickPickItem } from '../../quickpicks';

interface Context {
repos: Repository[];
Expand All @@ -23,9 +23,12 @@ interface Context {
title: string;
}

type Flags = '--edit' | '--no-edit';

interface State<Refs = GitRevisionReference | GitRevisionReference[]> {
repo: string | Repository;
references: Refs;
flags: Flags[];
}

export interface RevertGitCommandArgs {
Expand Down Expand Up @@ -65,7 +68,7 @@ export class RevertGitCommand extends QuickCommand<State> {
}

execute(state: RevertStepState<State<GitRevisionReference[]>>) {
return state.repo.revert(...state.references.map(c => c.ref).reverse());
return state.repo.revert(...state.flags, ...state.references.map(c => c.ref).reverse());
}

protected async *steps(state: PartialStepState<State>): StepGenerator {
Expand All @@ -76,6 +79,10 @@ export class RevertGitCommand extends QuickCommand<State> {
title: this.title,
};

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

if (state.references != null && !Array.isArray(state.references)) {
state.references = [state.references];
}
Expand Down Expand Up @@ -142,30 +149,35 @@ export class RevertGitCommand extends QuickCommand<State> {
state.references = result;
}

const result = yield* this.confirmStep(state as RevertStepState<State<GitRevisionReference[]>>, context);
const result = yield* this.confirmStep(state as RevertStepState, context);
if (result === StepResult.Break) continue;

state.flags = result;

QuickCommand.endSteps(state);
this.execute(state as RevertStepState<State<GitRevisionReference[]>>);
}

return state.counter < 0 ? StepResult.Break : undefined;
}

private *confirmStep(
state: RevertStepState<State<GitRevisionReference[]>>,
context: Context,
): StepResultGenerator<void> {
const step: QuickPickStep<QuickPickItem> = this.createConfirmStep(
private *confirmStep(state: RevertStepState, context: Context): StepResultGenerator<Flags[]> {
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
appendReposToTitle(`Confirm ${context.title}`, state, context),
[
{
FlagsQuickPickItem.create<Flags>(state.flags, ['--no-edit'], {
label: this.title,
description: '--no-edit',
detail: `Will revert ${GitReference.toString(state.references)}`,
},
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--edit'], {
label: `${this.title} & Edit`,
description: '--edit',
detail: `Will revert and edit ${GitReference.toString(state.references)}`,
}),
],
);
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? undefined : StepResult.Break;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
}

0 comments on commit a8432e5

Please sign in to comment.