You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.5 KiB

преди 7 години
преди 6 години
преди 7 години
преди 7 години
преди 6 години
преди 6 години
преди 6 години
  1. 'use strict';
  2. import { MessageItem, window } from 'vscode';
  3. import { GlyphChars } from '../constants';
  4. import { Container } from '../container';
  5. import { GitStashCommit } from '../git/gitService';
  6. import { Logger } from '../logger';
  7. import { Messages } from '../messages';
  8. import { CommandQuickPickItem } from '../quickpicks';
  9. import { Command, CommandContext, Commands, isCommandViewContextWithCommit } from './common';
  10. export interface StashDeleteCommandArgs {
  11. confirm?: boolean;
  12. stashItem?: { stashName: string; message: string; repoPath: string };
  13. goBackCommand?: CommandQuickPickItem;
  14. }
  15. export class StashDeleteCommand extends Command {
  16. constructor() {
  17. super(Commands.StashDelete);
  18. }
  19. protected async preExecute(context: CommandContext, args: StashDeleteCommandArgs = { confirm: true }) {
  20. if (isCommandViewContextWithCommit<GitStashCommit>(context)) {
  21. args = { ...args };
  22. args.stashItem = context.node.commit;
  23. return this.execute(args);
  24. }
  25. return this.execute(args);
  26. }
  27. async execute(args: StashDeleteCommandArgs = { confirm: true }) {
  28. args = { ...args };
  29. if (
  30. args.stashItem === undefined ||
  31. args.stashItem.stashName === undefined ||
  32. args.stashItem.repoPath === undefined
  33. ) {
  34. return undefined;
  35. }
  36. if (args.confirm === undefined) {
  37. args.confirm = true;
  38. }
  39. try {
  40. if (args.confirm) {
  41. const message =
  42. args.stashItem.message.length > 80
  43. ? `${args.stashItem.message.substring(0, 80)}${GlyphChars.Ellipsis}`
  44. : args.stashItem.message;
  45. const result = await window.showWarningMessage(
  46. `Delete stashed changes '${message}'?`,
  47. { title: 'Yes' } as MessageItem,
  48. { title: 'No', isCloseAffordance: true } as MessageItem
  49. );
  50. if (result === undefined || result.title !== 'Yes') {
  51. return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
  52. }
  53. }
  54. return await Container.git.stashDelete(args.stashItem.repoPath, args.stashItem.stashName);
  55. }
  56. catch (ex) {
  57. Logger.error(ex, 'StashDeleteCommand');
  58. return Messages.showGenericErrorMessage('Unable to delete stash');
  59. }
  60. }
  61. }