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

56 行
1.6 KiB

import { executeGitCommand } from '../commands';
import type { Container } from '../container';
import { SearchPattern } from '../git/search';
import { SearchResultsNode } from '../views/nodes';
import { Command, command, CommandContext, Commands, isCommandContextViewNodeHasRepository } from './common';
export interface SearchCommitsCommandArgs {
search?: Partial<SearchPattern>;
repoPath?: string;
prefillOnly?: boolean;
showResultsInSideBar?: boolean;
}
@command()
export class SearchCommitsCommand extends Command {
constructor(private readonly container: Container) {
super([Commands.SearchCommits, Commands.SearchCommitsInView]);
}
protected override preExecute(context: CommandContext, args?: SearchCommitsCommandArgs) {
if (context.type === 'viewItem') {
args = { ...args };
args.showResultsInSideBar = true;
if (context.node instanceof SearchResultsNode) {
args.repoPath = context.node.repoPath;
args.search = context.node.search;
args.prefillOnly = true;
}
if (isCommandContextViewNodeHasRepository(context)) {
args.repoPath = context.node.repo.path;
}
} else if (context.command === Commands.SearchCommitsInView) {
args = { ...args };
args.showResultsInSideBar = true;
}
return this.execute(args);
}
async execute(args?: SearchCommitsCommandArgs) {
void (await executeGitCommand({
command: 'search',
prefillOnly: args?.prefillOnly,
state: {
repo: args?.repoPath,
...args?.search,
showResultsInSideBar:
this.container.config.gitCommands.search.showResultsInSideBar ?? args?.showResultsInSideBar,
},
}));
}
}