Browse Source

Adds pick commit button to branches/tags

main
Eric Amodio 3 years ago
parent
commit
315bda0e66
6 changed files with 37 additions and 11 deletions
  1. +4
    -1
      src/commands/git/merge.ts
  2. +4
    -1
      src/commands/git/rebase.ts
  3. +5
    -3
      src/commands/gitCommands.ts
  4. +5
    -3
      src/commands/quickCommand.buttons.ts
  5. +11
    -2
      src/commands/quickCommand.steps.ts
  6. +8
    -1
      src/commands/quickCommand.ts

+ 4
- 1
src/commands/git/merge.ts View File

@ -24,6 +24,7 @@ interface Context {
cache: Map<string, Promise<GitLog | undefined>>; cache: Map<string, Promise<GitLog | undefined>>;
destination: GitBranch; destination: GitBranch;
pickCommit: boolean; pickCommit: boolean;
pickCommitForItem: boolean;
selectedBranchOrTag: GitReference | undefined; selectedBranchOrTag: GitReference | undefined;
showTags: boolean; showTags: boolean;
title: string; title: string;
@ -80,6 +81,7 @@ export class MergeGitCommand extends QuickCommand {
cache: new Map<string, Promise<GitLog | undefined>>(), cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!, destination: undefined!,
pickCommit: false, pickCommit: false,
pickCommitForItem: false,
selectedBranchOrTag: undefined, selectedBranchOrTag: undefined,
showTags: true, showTags: true,
title: this.title, title: this.title,
@ -120,6 +122,7 @@ export class MergeGitCommand extends QuickCommand {
} }
context.title = `${this.title} into ${GitReference.toString(context.destination, { icon: false })}`; context.title = `${this.title} into ${GitReference.toString(context.destination, { icon: false })}`;
context.pickCommitForItem = false;
if (state.counter < 2 || state.reference == null) { if (state.counter < 2 || state.reference == null) {
const pickCommitToggle = new QuickCommandButtons.PickCommitToggle(context.pickCommit, context, () => { const pickCommitToggle = new QuickCommandButtons.PickCommitToggle(context.pickCommit, context, () => {
@ -153,7 +156,7 @@ export class MergeGitCommand extends QuickCommand {
if ( if (
state.counter < 3 && state.counter < 3 &&
context.selectedBranchOrTag != null && context.selectedBranchOrTag != null &&
(context.pickCommit || state.reference.ref === context.destination.ref)
(context.pickCommit || context.pickCommitForItem || state.reference.ref === context.destination.ref)
) { ) {
const ref = context.selectedBranchOrTag.ref; const ref = context.selectedBranchOrTag.ref;

+ 4
- 1
src/commands/git/rebase.ts View File

@ -25,6 +25,7 @@ interface Context {
cache: Map<string, Promise<GitLog | undefined>>; cache: Map<string, Promise<GitLog | undefined>>;
destination: GitBranch; destination: GitBranch;
pickCommit: boolean; pickCommit: boolean;
pickCommitForItem: boolean;
selectedBranchOrTag: GitReference | undefined; selectedBranchOrTag: GitReference | undefined;
showTags: boolean; showTags: boolean;
title: string; title: string;
@ -101,6 +102,7 @@ export class RebaseGitCommand extends QuickCommand {
cache: new Map<string, Promise<GitLog | undefined>>(), cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!, destination: undefined!,
pickCommit: false, pickCommit: false,
pickCommitForItem: false,
selectedBranchOrTag: undefined, selectedBranchOrTag: undefined,
showTags: true, showTags: true,
title: this.title, title: this.title,
@ -141,6 +143,7 @@ export class RebaseGitCommand extends QuickCommand {
} }
context.title = `${this.title} ${GitReference.toString(context.destination, { icon: false })}`; context.title = `${this.title} ${GitReference.toString(context.destination, { icon: false })}`;
context.pickCommitForItem = false;
if (state.counter < 2 || state.reference == null) { if (state.counter < 2 || state.reference == null) {
const pickCommitToggle = new QuickCommandButtons.PickCommitToggle(context.pickCommit, context, () => { const pickCommitToggle = new QuickCommandButtons.PickCommitToggle(context.pickCommit, context, () => {
@ -174,7 +177,7 @@ export class RebaseGitCommand extends QuickCommand {
if ( if (
state.counter < 3 && state.counter < 3 &&
context.selectedBranchOrTag != null && context.selectedBranchOrTag != null &&
(context.pickCommit || state.reference.ref === context.destination.ref)
(context.pickCommit || context.pickCommitForItem || state.reference.ref === context.destination.ref)
) { ) {
const ref = context.selectedBranchOrTag.ref; const ref = context.selectedBranchOrTag.ref;

+ 5
- 3
src/commands/gitCommands.ts View File

@ -468,9 +468,11 @@ export class GitCommandsCommand extends Command {
disposables.push( disposables.push(
scope, scope,
quickpick.onDidHide(() => resolve(undefined)), quickpick.onDidHide(() => resolve(undefined)),
quickpick.onDidTriggerItemButton(async e =>
step.onDidClickItemButton?.(quickpick, e.button, e.item),
),
quickpick.onDidTriggerItemButton(async e => {
if ((await step.onDidClickItemButton?.(quickpick, e.button, e.item)) === true) {
resolve(await this.nextStep(quickpick, commandsStep.command!, [e.item]));
}
}),
quickpick.onDidTriggerButton(async e => { quickpick.onDidTriggerButton(async e => {
if (e === QuickInputButtons.Back) { if (e === QuickInputButtons.Back) {
void goBack(); void goBack();

+ 5
- 3
src/commands/quickCommand.buttons.ts View File

@ -38,10 +38,7 @@ export class ToggleQuickInputButton implements QuickInputButton {
} }
/** /**
*
* @param quickInput
* @returns `true` if the step should be retried (refreshed) * @returns `true` if the step should be retried (refreshed)
*
*/ */
onDidClick?(quickInput: QuickInput): boolean | void | Promise<boolean | void>; onDidClick?(quickInput: QuickInput): boolean | void | Promise<boolean | void>;
@ -89,6 +86,11 @@ export namespace QuickCommandButtons {
} }
}; };
export const PickCommit: QuickInputButton = {
iconPath: new ThemeIcon('git-commit'),
tooltip: 'Choose a Specific Commit',
};
export const PickCommitToggle = class extends ToggleQuickInputButton { export const PickCommitToggle = class extends ToggleQuickInputButton {
constructor(on = false, context: { showTags: boolean }, onDidClick?: (quickInput: QuickInput) => void) { constructor(on = false, context: { showTags: boolean }, onDidClick?: (quickInput: QuickInput) => void) {
super( super(

+ 11
- 2
src/commands/quickCommand.steps.ts View File

@ -563,7 +563,7 @@ export async function* pickBranchesStep<
export async function* pickBranchOrTagStep< export async function* pickBranchOrTagStep<
State extends PartialStepState & { repo: Repository }, State extends PartialStepState & { repo: Repository },
Context extends { repos: Repository[]; showTags?: boolean; title: string },
Context extends { repos: Repository[]; pickCommitForItem?: boolean; showTags?: boolean; title: string },
>( >(
state: State, state: State,
context: Context, context: Context,
@ -591,7 +591,10 @@ export async function* pickBranchOrTagStep<
const getBranchesAndOrTagsFn = async () => { const getBranchesAndOrTagsFn = async () => {
return getBranchesAndOrTags(state.repo, context.showTags ? ['branches', 'tags'] : ['branches'], { return getBranchesAndOrTags(state.repo, context.showTags ? ['branches', 'tags'] : ['branches'], {
buttons: [QuickCommandButtons.RevealInSideBar],
buttons:
typeof context.pickCommitForItem === 'boolean'
? [QuickCommandButtons.PickCommit, QuickCommandButtons.RevealInSideBar]
: [QuickCommandButtons.RevealInSideBar],
filter: filter, filter: filter,
picked: picked, picked: picked,
sort: true, sort: true,
@ -616,6 +619,11 @@ export async function* pickBranchOrTagStep<
: branchesAndOrTags, : branchesAndOrTags,
additionalButtons: [...(additionalButtons ?? []), showTagsButton], additionalButtons: [...(additionalButtons ?? []), showTagsButton],
onDidClickItemButton: (quickpick, button, { item }) => { onDidClickItemButton: (quickpick, button, { item }) => {
if (button === QuickCommandButtons.PickCommit) {
context.pickCommitForItem = true;
return true;
}
if (button === QuickCommandButtons.RevealInSideBar) { if (button === QuickCommandButtons.RevealInSideBar) {
if (GitReference.isBranch(item)) { if (GitReference.isBranch(item)) {
void GitActions.Branch.reveal(item, { select: true, expand: true }); void GitActions.Branch.reveal(item, { select: true, expand: true });
@ -625,6 +633,7 @@ export async function* pickBranchOrTagStep<
void GitActions.Commit.reveal(item, { select: true, expand: true }); void GitActions.Commit.reveal(item, { select: true, expand: true });
} }
} }
return false;
}, },
onDidClickButton: async (quickpick, button) => { onDidClickButton: async (quickpick, button) => {
if (button === showTagsButton) { if (button === showTagsButton) {

+ 8
- 1
src/commands/quickCommand.ts View File

@ -46,7 +46,14 @@ export interface QuickPickStep {
onDidAccept?(quickpick: QuickPick<T>): boolean | Promise<boolean>; onDidAccept?(quickpick: QuickPick<T>): boolean | Promise<boolean>;
onDidChangeValue?(quickpick: QuickPick<T>): boolean | Promise<boolean>; onDidChangeValue?(quickpick: QuickPick<T>): boolean | Promise<boolean>;
onDidClickButton?(quickpick: QuickPick<T>, button: QuickInputButton): boolean | void | Promise<boolean | void>; onDidClickButton?(quickpick: QuickPick<T>, button: QuickInputButton): boolean | void | Promise<boolean | void>;
onDidClickItemButton?(quickpick: QuickPick<T>, button: QuickInputButton, item: T): void | Promise<void>;
/**
* @returns `true` if the current item should be selected
*/
onDidClickItemButton?(
quickpick: QuickPick<T>,
button: QuickInputButton,
item: T,
): boolean | void | Promise<boolean | void>;
onDidLoadMore?(quickpick: QuickPick<T>): (DirectiveQuickPickItem | T)[] | Promise<(DirectiveQuickPickItem | T)[]>; onDidLoadMore?(quickpick: QuickPick<T>): (DirectiveQuickPickItem | T)[] | Promise<(DirectiveQuickPickItem | T)[]>;
onDidPressKey?(quickpick: QuickPick<T>, key: Keys): void | Promise<void>; onDidPressKey?(quickpick: QuickPick<T>, key: Keys): void | Promise<void>;
onValidateValue?(quickpick: QuickPick<T>, value: string, items: T[]): boolean | Promise<boolean>; onValidateValue?(quickpick: QuickPick<T>, value: string, items: T[]): boolean | Promise<boolean>;

Loading…
Cancel
Save