(commitItemOrSha?: string | CommitTreeItem)
| 26 | }; |
| 27 | |
| 28 | const 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 | |
| 85 | const commandDiffCommitFile = async (commitItem: CommitTreeItem) => { |
nothing calls this directly
no test coverage detected