您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

87 行
2.1 KiB

  1. import { TextEditor, Uri } from 'vscode';
  2. import type { Container } from '../container';
  3. import { Logger } from '../logger';
  4. import { Messages } from '../messages';
  5. import {
  6. ActiveEditorCommand,
  7. command,
  8. CommandContext,
  9. Commands,
  10. getCommandUri,
  11. getRepoPathOrActiveOrPrompt,
  12. } from './common';
  13. export interface CompareWithCommandArgs {
  14. ref1?: string;
  15. ref2?: string;
  16. }
  17. @command()
  18. export class CompareWithCommand extends ActiveEditorCommand {
  19. constructor(private readonly container: Container) {
  20. super([
  21. Commands.CompareWith,
  22. Commands.CompareHeadWith,
  23. Commands.CompareWorkingWith,
  24. Commands.Deprecated_DiffHeadWith,
  25. Commands.Deprecated_DiffWorkingWith,
  26. ]);
  27. }
  28. protected override preExecute(context: CommandContext, args?: CompareWithCommandArgs) {
  29. switch (context.command) {
  30. case Commands.CompareWith:
  31. args = { ...args };
  32. break;
  33. case Commands.CompareHeadWith:
  34. case Commands.Deprecated_DiffHeadWith:
  35. args = { ...args };
  36. args.ref1 = 'HEAD';
  37. break;
  38. case Commands.CompareWorkingWith:
  39. case Commands.Deprecated_DiffWorkingWith:
  40. args = { ...args };
  41. args.ref1 = '';
  42. break;
  43. }
  44. return this.execute(context.editor, context.uri, args);
  45. }
  46. async execute(editor?: TextEditor, uri?: Uri, args?: CompareWithCommandArgs) {
  47. uri = getCommandUri(uri, editor);
  48. args = { ...args };
  49. try {
  50. let title;
  51. switch (args.ref1) {
  52. case null:
  53. title = 'Compare';
  54. break;
  55. case '':
  56. title = 'Compare Working Tree with';
  57. break;
  58. case 'HEAD':
  59. title = 'Compare HEAD with';
  60. break;
  61. default:
  62. title = `Compare ${args.ref1} with`;
  63. break;
  64. }
  65. const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, title);
  66. if (!repoPath) return;
  67. if (args.ref1 != null && args.ref2 != null) {
  68. void (await this.container.searchAndCompareView.compare(repoPath, args.ref1, args.ref2));
  69. } else {
  70. this.container.searchAndCompareView.selectForCompare(repoPath, args.ref1, { prompt: true });
  71. }
  72. } catch (ex) {
  73. Logger.error(ex, 'CompareWithCommmand');
  74. void Messages.showGenericErrorMessage('Unable to open comparison');
  75. }
  76. }
  77. }