25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

  1. import { executeGitCommand } from '../commands';
  2. import type { Container } from '../container';
  3. import { SearchPattern } from '../git/search';
  4. import { SearchResultsNode } from '../views/nodes';
  5. import { Command, command, CommandContext, Commands, isCommandContextViewNodeHasRepository } from './common';
  6. export interface SearchCommitsCommandArgs {
  7. search?: Partial<SearchPattern>;
  8. repoPath?: string;
  9. prefillOnly?: boolean;
  10. showResultsInSideBar?: boolean;
  11. }
  12. @command()
  13. export class SearchCommitsCommand extends Command {
  14. constructor(private readonly container: Container) {
  15. super([Commands.SearchCommits, Commands.SearchCommitsInView]);
  16. }
  17. protected override preExecute(context: CommandContext, args?: SearchCommitsCommandArgs) {
  18. if (context.type === 'viewItem') {
  19. args = { ...args };
  20. args.showResultsInSideBar = true;
  21. if (context.node instanceof SearchResultsNode) {
  22. args.repoPath = context.node.repoPath;
  23. args.search = context.node.search;
  24. args.prefillOnly = true;
  25. }
  26. if (isCommandContextViewNodeHasRepository(context)) {
  27. args.repoPath = context.node.repo.path;
  28. }
  29. } else if (context.command === Commands.SearchCommitsInView) {
  30. args = { ...args };
  31. args.showResultsInSideBar = true;
  32. }
  33. return this.execute(args);
  34. }
  35. async execute(args?: SearchCommitsCommandArgs) {
  36. void (await executeGitCommand({
  37. command: 'search',
  38. prefillOnly: args?.prefillOnly,
  39. state: {
  40. repo: args?.repoPath,
  41. ...args?.search,
  42. showResultsInSideBar:
  43. this.container.config.gitCommands.search.showResultsInSideBar ?? args?.showResultsInSideBar,
  44. },
  45. }));
  46. }
  47. }