Skip to content

Commit

Permalink
Adds default confirm selection for flags
Browse files Browse the repository at this point in the history
Makes git flags type safe
  • Loading branch information
eamodio committed Sep 17, 2019
1 parent 6f0fac7 commit 4893385
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 178 deletions.
27 changes: 16 additions & 11 deletions src/commands/git/cherry-pick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getBranchesAndOrTags,
getValidateGitReferenceFn,
QuickCommandBase,
QuickPickStep,
StepAsyncGenerator,
StepSelection,
StepState
Expand All @@ -16,17 +17,19 @@ import {
CommitQuickPickItem,
Directive,
DirectiveQuickPickItem,
GitFlagsQuickPickItem,
FlagsQuickPickItem,
ReferencesQuickPickItem,
RepositoryQuickPickItem
} from '../../quickpicks';
import { runGitCommandInTerminal } from '../../terminal';
import { Logger } from '../../logger';

type Flags = '--edit';

interface State {
repo: Repository;
references?: GitReference[];
flags: string[];
flags: Flags[];
}

export interface CherryPickGitCommandArgs {
Expand Down Expand Up @@ -80,6 +83,10 @@ export class CherryPickGitCommand extends QuickCommandBase<State> {
let repos;
let selectedBranchOrTag: GitReference | undefined;

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

while (true) {
try {
if (repos === undefined) {
Expand Down Expand Up @@ -198,10 +205,10 @@ export class CherryPickGitCommand extends QuickCommandBase<State> {
state.references = selection.map(i => i.item);
}

const step = this.createConfirmStep<GitFlagsQuickPickItem>(
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
`Confirm ${this.title}${Strings.pad(GlyphChars.Dot, 2, 2)}${state.repo.formattedName}`,
[
{
FlagsQuickPickItem.create<Flags>(state.flags, [], {
label: this.title,
description: `${
state.references!.length === 1
Expand All @@ -212,10 +219,9 @@ export class CherryPickGitCommand extends QuickCommandBase<State> {
state.references!.length === 1
? `commit ${state.references![0].name}`
: `${state.references!.length} commits`
} onto ${destination.name}`,
item: []
},
{
} onto ${destination.name}`
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--edit'], {
label: `${this.title} & Edit`,
description: `--edit ${
state.references!.length === 1
Expand All @@ -226,9 +232,8 @@ export class CherryPickGitCommand extends QuickCommandBase<State> {
state.references!.length === 1
? `commit ${state.references![0].name}`
: `${state.references!.length} commits`
} onto ${destination.name}`,
item: ['--edit']
}
} onto ${destination.name}`
})
]
);
const selection: StepSelection<typeof step> = yield step;
Expand Down
44 changes: 22 additions & 22 deletions src/commands/git/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use strict';
import { Container } from '../../container';
import { Repository } from '../../git/gitService';
import { QuickCommandBase, StepAsyncGenerator, StepSelection, StepState } from '../quickCommand';
import { GitFlagsQuickPickItem, RepositoryQuickPickItem } from '../../quickpicks';
import { QuickCommandBase, QuickPickStep, StepAsyncGenerator, StepSelection, StepState } from '../quickCommand';
import { FlagsQuickPickItem, RepositoryQuickPickItem } from '../../quickpicks';
import { Dates, Strings } from '../../system';
import { GlyphChars } from '../../constants';
import { Logger } from '../../logger';

type Flags = '--all' | '--prune';

interface State {
repos: Repository[];
flags: string[];
flags: Flags[];
}

export interface FetchGitCommandArgs {
Expand Down Expand Up @@ -48,6 +50,10 @@ export class FetchGitCommand extends QuickCommandBase<State> {
const state: StepState<State> = this._initialState === undefined ? { counter: 0 } : this._initialState;
let repos;

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

while (true) {
try {
if (repos === undefined) {
Expand Down Expand Up @@ -102,53 +108,49 @@ export class FetchGitCommand extends QuickCommandBase<State> {
}
}

const step = this.createConfirmStep<GitFlagsQuickPickItem>(
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
`Confirm ${this.title}${Strings.pad(GlyphChars.Dot, 2, 2)}${
state.repos.length === 1
? `${state.repos[0].formattedName}${fetchedOn}`
: `${state.repos.length} repositories`
}`,
[
{
FlagsQuickPickItem.create<Flags>(state.flags, [], {
label: this.title,
description: '',
detail: `Will fetch ${
state.repos.length === 1
? state.repos[0].formattedName
: `${state.repos.length} repositories`
}`,
item: []
},
{
}`
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--prune'], {
label: `${this.title} & Prune`,
description: '--prune',
detail: `Will fetch and prune ${
state.repos.length === 1
? state.repos[0].formattedName
: `${state.repos.length} repositories`
}`,
item: ['--prune']
},
{
}`
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--all'], {
label: `${this.title} All`,
description: '--all',
detail: `Will fetch all remotes of ${
state.repos.length === 1
? state.repos[0].formattedName
: `${state.repos.length} repositories`
}`,
item: ['--all']
},
{
}`
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--all', '--prune'], {
label: `${this.title} All & Prune`,
description: '--all --prune',
detail: `Will fetch and prune all remotes of ${
state.repos.length === 1
? state.repos[0].formattedName
: `${state.repos.length} repositories`
}`,
item: ['--all', '--prune']
}
}`
})
]
);
const selection: StepSelection<typeof step> = yield step;
Expand All @@ -162,8 +164,6 @@ export class FetchGitCommand extends QuickCommandBase<State> {
}

state.flags = selection[0].item;
} else {
state.flags = state.flags || [];
}

this.execute(state as State);
Expand Down
41 changes: 22 additions & 19 deletions src/commands/git/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ import {
getBranchesAndOrTags,
getValidateGitReferenceFn,
QuickCommandBase,
QuickPickStep,
StepAsyncGenerator,
StepSelection,
StepState
} from '../quickCommand';
import {
Directive,
DirectiveQuickPickItem,
GitFlagsQuickPickItem,
FlagsQuickPickItem,
ReferencesQuickPickItem,
RepositoryQuickPickItem
} from '../../quickpicks';
import { Strings } from '../../system';
import { runGitCommandInTerminal } from '../../terminal';
import { Logger } from '../../logger';

type Flags = '--ff-only' | '--no-ff' | '--squash';

interface State {
repo: Repository;
reference: GitReference;
flags: string[];
flags: Flags[];
}

export interface MergeGitCommandArgs {
Expand Down Expand Up @@ -68,6 +71,10 @@ export class MergeGitCommand extends QuickCommandBase<State> {
const state: StepState<State> = this._initialState === undefined ? { counter: 0 } : this._initialState;
let repos;

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

while (true) {
try {
if (repos === undefined) {
Expand Down Expand Up @@ -156,42 +163,38 @@ export class MergeGitCommand extends QuickCommandBase<State> {
break;
}

const step = this.createConfirmStep<GitFlagsQuickPickItem>(
const step: QuickPickStep<FlagsQuickPickItem<Flags>> = this.createConfirmStep(
`Confirm ${this.title}${Strings.pad(GlyphChars.Dot, 2, 2)}${state.repo.formattedName}`,
[
{
FlagsQuickPickItem.create<Flags>(state.flags, [], {
label: this.title,
description: `${state.reference.name} into ${destination.name}`,
detail: `Will merge ${Strings.pluralize('commit', count)} from ${
state.reference.name
} into ${destination.name}`,
item: []
},
{
} into ${destination.name}`
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--ff-only'], {
label: `Fast-forward ${this.title}`,
description: `--ff-only ${state.reference.name} into ${destination.name}`,
detail: `Will fast-forward merge ${Strings.pluralize('commit', count)} from ${
state.reference.name
} into ${destination.name}`,
item: ['--ff-only']
},
{
} into ${destination.name}`
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--no-ff'], {
label: `No Fast-forward ${this.title}`,
description: `--no-ff ${state.reference.name} into ${destination.name}`,
detail: `Will create a merge commit when merging ${Strings.pluralize(
'commit',
count
)} from ${state.reference.name} into ${destination.name}`,
item: ['--no-ff']
},
{
)} from ${state.reference.name} into ${destination.name}`
}),
FlagsQuickPickItem.create<Flags>(state.flags, ['--squash'], {
label: `Squash ${this.title}`,
description: `--squash ${state.reference.name} into ${destination.name}`,
detail: `Will squash ${Strings.pluralize('commit', count)} from ${
state.reference.name
} into one when merging into ${destination.name}`,
item: ['--squash']
}
} into one when merging into ${destination.name}`
})
]
);
const selection: StepSelection<typeof step> = yield step;
Expand Down

0 comments on commit 4893385

Please sign in to comment.