forked from gitkraken/vscode-gitlens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchCommits.ts
62 lines (53 loc) · 1.82 KB
/
searchCommits.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Commands } from '../constants';
import type { Container } from '../container';
import { executeGitCommand } from '../git/actions';
import type { SearchQuery } from '../git/search';
import { command } from '../system/command';
import { configuration } from '../system/configuration';
import { SearchResultsNode } from '../views/nodes/searchResultsNode';
import type { CommandContext } from './base';
import { Command, isCommandContextViewNodeHasRepository } from './base';
export interface SearchCommitsCommandArgs {
search?: Partial<SearchQuery>;
repoPath?: string;
prefillOnly?: boolean;
openPickInView?: 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.command === Commands.SearchCommitsInView) {
args = { ...args };
args.showResultsInSideBar = true;
} else 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;
}
}
return this.execute(args);
}
async execute(args?: SearchCommitsCommandArgs) {
await executeGitCommand({
command: 'search',
prefillOnly: args?.prefillOnly,
state: {
repo: args?.repoPath,
...args?.search,
showResultsInSideBar:
configuration.get('gitCommands.search.showResultsInSideBar') ?? args?.showResultsInSideBar,
openPickInView: args?.openPickInView ?? false,
},
});
}
}