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.

57 lines
2.0 KiB

  1. 'use strict';
  2. import { InputBoxOptions, Uri, window } from 'vscode';
  3. import { GitService } from '../gitService';
  4. import { CommandContext } from '../commands';
  5. import { Command, Commands } from './common';
  6. import { Logger } from '../logger';
  7. import { CommandQuickPickItem } from '../quickPicks';
  8. export interface StashSaveCommandArgs {
  9. message?: string;
  10. uris?: Uri[];
  11. goBackCommand?: CommandQuickPickItem;
  12. }
  13. export class StashSaveCommand extends Command {
  14. constructor(private git: GitService) {
  15. super(Commands.StashSave);
  16. }
  17. protected async preExecute(context: CommandContext, args: StashSaveCommandArgs = {}): Promise<any> {
  18. if (context.type === 'scm-states') {
  19. args = { ...args };
  20. args.uris = context.scmResourceStates.map(s => s.resourceUri);
  21. return this.execute(args);
  22. }
  23. if (context.type === 'scm-groups') {
  24. args = { ...args };
  25. args.uris = context.scmResourceGroups.reduce<Uri[]>((a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)), []);
  26. return this.execute(args);
  27. }
  28. return this.execute(args);
  29. }
  30. async execute(args: StashSaveCommandArgs = {}) {
  31. if (!this.git.repoPath) return undefined;
  32. try {
  33. if (args.message == null) {
  34. args = { ...args };
  35. args.message = await window.showInputBox({
  36. prompt: `Please provide a stash message`,
  37. placeHolder: `Stash message`
  38. } as InputBoxOptions);
  39. if (args.message === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
  40. }
  41. return await this.git.stashSave(this.git.repoPath, args.message, args.uris);
  42. }
  43. catch (ex) {
  44. Logger.error(ex, 'StashSaveCommand');
  45. return window.showErrorMessage(`Unable to save stash. See output channel for more details`);
  46. }
  47. }
  48. }