MCPcopy
hub / github.com/conwnet/github1s / commandSwitchToCommit

Function commandSwitchToCommit

extensions/github1s/src/commands/commit.ts:28–83  ·  view source on GitHub ↗
(commitItemOrSha?: string | CommitTreeItem)

Source from the content-addressed store, hash-verified

26};
27
28const commandSwitchToCommit = async (commitItemOrSha?: string | CommitTreeItem) => {
29 let commitSha: string | undefined = commitItemOrSha
30 ? typeof commitItemOrSha === 'string'
31 ? commitItemOrSha
32 : commitItemOrSha.commit.sha
33 : '';
34 const adapter = adapterManager.getCurrentAdapter();
35 const { repo } = await router.getState();
36 const repository = Repository.getInstance(adapter.scheme, repo);
37
38 // if the a commitSha isn't provided, use quickInput
39 if (!commitSha) {
40 // manual input a commit sha
41 const inputCommitShaItem: vscode.QuickPickItem = {
42 label: '$(git-commit) Manual input the commit sha',
43 alwaysShow: true,
44 };
45 // use the commit list as the candidates
46 const commits = await repository.getCommitList();
47 const commitItems: vscode.QuickPickItem[] = commits.map((commit) => ({
48 commitSha: commit.sha,
49 label: commit.message,
50 description: getCommitTreeItemDescription(commit),
51 }));
52
53 const quickPick = vscode.window.createQuickPick<vscode.QuickPickItem>();
54 quickPick.matchOnDescription = true;
55 quickPick.items = [inputCommitShaItem, ...commitItems];
56 quickPick.show();
57
58 const choice = (await new Promise<vscode.QuickPickItem | undefined>((resolve) =>
59 quickPick.onDidAccept(() => resolve(quickPick.activeItems[0])),
60 )) as vscode.QuickPickItem & { commitSha?: string };
61 quickPick.hide();
62
63 // select nothing
64 if (!choice) {
65 return;
66 }
67
68 // select `manual input the commit sha`
69 if (choice === inputCommitShaItem) {
70 commitSha = await vscode.window.showInputBox({
71 placeHolder: 'Please input the commit sha',
72 });
73 } else {
74 // select a commit sha
75 commitSha = choice.commitSha;
76 }
77 }
78
79 const routerParser = await router.resolveParser();
80 if (await checkCommitExists(repo, commitSha!)) {
81 router.replace(await routerParser.buildCommitPath(repo, commitSha!));
82 }
83};
84
85const commandDiffCommitFile = async (commitItem: CommitTreeItem) => {

Callers

nothing calls this directly

Calls 11

checkCommitExistsFunction · 0.85
getCurrentAdapterMethod · 0.80
getStateMethod · 0.80
getCommitListMethod · 0.80
resolveParserMethod · 0.80
replaceMethod · 0.80
showMethod · 0.65
hideMethod · 0.65
getInstanceMethod · 0.45
buildCommitPathMethod · 0.45

Tested by

no test coverage detected