Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 

56 righe
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,
},
}));
}
}