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.

40 lines
1.6 KiB

  1. 'use strict';
  2. import { TextEditor, Uri, window } from 'vscode';
  3. import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
  4. import { GitService } from '../gitService';
  5. import { Logger } from '../logger';
  6. import { Messages } from '../messages';
  7. import { CommandQuickPickItem, RepoStatusQuickPick } from '../quickPicks';
  8. export interface ShowQuickRepoStatusCommandArgs {
  9. goBackCommand?: CommandQuickPickItem;
  10. }
  11. export class ShowQuickRepoStatusCommand extends ActiveEditorCachedCommand {
  12. constructor(private git: GitService) {
  13. super(Commands.ShowQuickRepoStatus);
  14. }
  15. async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickRepoStatusCommandArgs = {}) {
  16. uri = getCommandUri(uri, editor);
  17. try {
  18. const repoPath = await this.git.getRepoPathFromUri(uri);
  19. if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show repository status`);
  20. const status = await this.git.getStatusForRepo(repoPath);
  21. if (status === undefined) return window.showWarningMessage(`Unable to show repository status`);
  22. const pick = await RepoStatusQuickPick.show(status, args.goBackCommand);
  23. if (pick === undefined) return undefined;
  24. if (pick instanceof CommandQuickPickItem) return pick.execute();
  25. return undefined;
  26. }
  27. catch (ex) {
  28. Logger.error(ex, 'ShowQuickRepoStatusCommand');
  29. return window.showErrorMessage(`Unable to show repository status. See output channel for more details`);
  30. }
  31. }
  32. }