Adds go back support to stash apply, delete, & save

This commit is contained in:
Eric Amodio
2017-04-09 01:18:45 -04:00
parent 3aab904aaf
commit 4707b0640d
6 changed files with 31 additions and 19 deletions

View File

@@ -4,6 +4,7 @@ import { GitService, GitStashCommit } from '../gitService';
import { Command, Commands } from './common';
import { CommitQuickPickItem, StashListQuickPick } from '../quickPicks';
import { Logger } from '../logger';
import { CommandQuickPickItem } from '../quickPicks';
export class StashApplyCommand extends Command {
@@ -11,7 +12,7 @@ export class StashApplyCommand extends Command {
super(Commands.StashApply);
}
async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true, deleteAfter: boolean = false) {
async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true, deleteAfter: boolean = false, goBackCommand?: CommandQuickPickItem) {
if (!this.git.config.insiders) return undefined;
if (!this.git.repoPath) return undefined;
@@ -19,9 +20,15 @@ export class StashApplyCommand extends Command {
const stash = await this.git.getStashList(this.git.repoPath);
if (!stash) return window.showInformationMessage(`There are no stashed changes`);
const pick = await StashListQuickPick.show(this.git, stash, 'apply');
if (!pick || !(pick instanceof CommitQuickPickItem)) return undefined;
const currentCommand = new CommandQuickPickItem({
label: `go back \u21A9`,
description: `\u00a0 \u2014 \u00a0\u00a0 to apply stashed changes`
}, Commands.StashApply, [stashItem, confirm, deleteAfter, goBackCommand]);
const pick = await StashListQuickPick.show(this.git, stash, 'apply', goBackCommand, currentCommand);
if (!pick || !(pick instanceof CommitQuickPickItem)) return goBackCommand && goBackCommand.execute();
goBackCommand = currentCommand;
stashItem = pick.commit as GitStashCommit;
}
@@ -29,7 +36,7 @@ export class StashApplyCommand extends Command {
if (confirm) {
const message = stashItem.message.length > 80 ? `${stashItem.message.substring(0, 80)}\u2026` : stashItem.message;
const result = await window.showWarningMessage(`Apply stashed changes '${message}' to your working tree?`, { title: 'Yes, delete after applying' } as MessageItem, { title: 'Yes' } as MessageItem, { title: 'No', isCloseAffordance: true } as MessageItem);
if (!result || result.title === 'No') return undefined;
if (!result || result.title === 'No') return goBackCommand && goBackCommand.execute();
deleteAfter = result.title !== 'Yes';
}