Selaa lähdekoodia

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

main
Eric Amodio 7 vuotta sitten
vanhempi
commit
4707b0640d
6 muutettua tiedostoa jossa 31 lisäystä ja 19 poistoa
  1. +9
    -6
      src/commands/showQuickStashList.ts
  2. +11
    -4
      src/commands/stashApply.ts
  3. +3
    -2
      src/commands/stashDelete.ts
  4. +3
    -2
      src/commands/stashSave.ts
  5. +2
    -2
      src/quickPicks/commitDetails.ts
  6. +3
    -3
      src/quickPicks/stashList.ts

+ 9
- 6
src/commands/showQuickStashList.ts Näytä tiedosto

@ -21,18 +21,21 @@ export class ShowQuickStashListCommand extends ActiveEditorCachedCommand {
if (!repoPath) return window.showWarningMessage(`Unable to show stashed changes`);
const stash = await this.git.getStashList(repoPath);
const pick = await StashListQuickPick.show(this.git, stash, 'list', goBackCommand);
// Create a command to get back to here
const currentCommand = new CommandQuickPickItem({
label: `go back \u21A9`,
description: `\u00a0 \u2014 \u00a0\u00a0 to stashed changes`
}, Commands.ShowQuickStashList, [uri, goBackCommand]);
const pick = await StashListQuickPick.show(this.git, stash, 'list', goBackCommand, currentCommand);
if (!pick) return undefined;
if (pick instanceof CommandQuickPickItem) {
return pick.execute();
}
return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit,
new CommandQuickPickItem({
label: `go back \u21A9`,
description: `\u00a0 \u2014 \u00a0\u00a0 to stashed changes`
}, Commands.ShowQuickStashList, [uri, goBackCommand]));
return commands.executeCommand(Commands.ShowQuickCommitDetails, new GitUri(pick.commit.uri, pick.commit), pick.commit.sha, pick.commit, currentCommand);
}
catch (ex) {
Logger.error(ex, 'ShowQuickStashListCommand');

+ 11
- 4
src/commands/stashApply.ts Näytä tiedosto

@ -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';
}

+ 3
- 2
src/commands/stashDelete.ts Näytä tiedosto

@ -3,6 +3,7 @@ import { MessageItem, window } from 'vscode';
import { GitService } from '../gitService';
import { Command, Commands } from './common';
import { Logger } from '../logger';
import { CommandQuickPickItem } from '../quickPicks';
export class StashDeleteCommand extends Command {
@ -10,7 +11,7 @@ export class StashDeleteCommand extends Command {
super(Commands.StashDelete);
}
async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true) {
async execute(stashItem: { stashName: string, message: string }, confirm: boolean = true, goBackCommand?: CommandQuickPickItem) {
if (!this.git.config.insiders) return undefined;
if (!this.git.repoPath) return undefined;
if (!stashItem || !stashItem.stashName) return undefined;
@ -19,7 +20,7 @@ export class StashDeleteCommand extends Command {
if (confirm) {
const message = stashItem.message.length > 80 ? `${stashItem.message.substring(0, 80)}\u2026` : stashItem.message;
const result = await window.showWarningMessage(`Delete stashed changes '${message}'?`, { title: 'Yes' } as MessageItem, { title: 'No', isCloseAffordance: true } as MessageItem);
if (!result || result.title !== 'Yes') return undefined;
if (!result || result.title !== 'Yes') return goBackCommand && goBackCommand.execute();
}
return await this.git.stashDelete(this.git.repoPath, stashItem.stashName);

+ 3
- 2
src/commands/stashSave.ts Näytä tiedosto

@ -3,6 +3,7 @@ import { InputBoxOptions, window } from 'vscode';
import { GitService } from '../gitService';
import { Command, Commands } from './common';
import { Logger } from '../logger';
import { CommandQuickPickItem } from '../quickPicks';
export class StashSaveCommand extends Command {
@ -10,7 +11,7 @@ export class StashSaveCommand extends Command {
super(Commands.StashSave);
}
async execute(message?: string, unstagedOnly: boolean = false) {
async execute(message?: string, unstagedOnly: boolean = false, goBackCommand?: CommandQuickPickItem) {
if (!this.git.config.insiders) return undefined;
if (!this.git.repoPath) return undefined;
@ -20,7 +21,7 @@ export class StashSaveCommand extends Command {
prompt: `Please provide a stash message`,
placeHolder: `Stash message`
} as InputBoxOptions);
if (message === undefined) return undefined;
if (message === undefined) return goBackCommand && goBackCommand.execute();
}
return await this.git.stashSave(this.git.repoPath, message, unstagedOnly);

+ 2
- 2
src/quickPicks/commitDetails.ts Näytä tiedosto

@ -80,12 +80,12 @@ export class CommitDetailsQuickPick {
items.splice(index++, 0, new CommandQuickPickItem({
label: `$(git-pull-request) Apply Stashed Changes`,
description: `\u00a0 \u2014 \u00a0\u00a0 ${commit.message}`
}, Commands.StashApply, [commit as GitStashCommit, true, false]));
}, Commands.StashApply, [commit as GitStashCommit, true, false, currentCommand]));
items.splice(index++, 0, new CommandQuickPickItem({
label: `$(x) Delete Stashed Changes`,
description: `\u00a0 \u2014 \u00a0\u00a0 ${commit.message}`
}, Commands.StashDelete, [commit as GitStashCommit, true]));
}, Commands.StashDelete, [commit as GitStashCommit, true, currentCommand]));
}
if (!stash) {

+ 3
- 3
src/quickPicks/stashList.ts Näytä tiedosto

@ -7,19 +7,19 @@ import { CommandQuickPickItem, CommitQuickPickItem, getQuickPickIgnoreFocusOut }
export class StashListQuickPick {
static async show(git: GitService, stash: IGitStash, mode: 'list' | 'apply', goBackCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
static async show(git: GitService, stash: IGitStash, mode: 'list' | 'apply', goBackCommand?: CommandQuickPickItem, currentCommand?: CommandQuickPickItem): Promise<CommitQuickPickItem | CommandQuickPickItem | undefined> {
const items = ((stash && Array.from(Iterables.map(stash.commits.values(), c => new CommitQuickPickItem(c)))) || []) as (CommitQuickPickItem | CommandQuickPickItem)[];
if (mode === 'list' && git.config.insiders) {
items.splice(0, 0, new CommandQuickPickItem({
label: `$(repo-push) Stash Unstaged Changes`,
description: `\u00a0 \u2014 \u00a0\u00a0 stashes only unstaged changes`
}, Commands.StashSave, [undefined, true]));
}, Commands.StashSave, [undefined, true, currentCommand]));
items.splice(0, 0, new CommandQuickPickItem({
label: `$(repo-push) Stash Changes`,
description: `\u00a0 \u2014 \u00a0\u00a0 stashes all changes`
}, Commands.StashSave));
}, Commands.StashSave, [undefined, undefined, currentCommand]));
}
if (goBackCommand) {

Ladataan…
Peruuta
Tallenna