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

Function commandCheckoutTo

extensions/github1s/src/commands/ref.ts:22–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21// check out to branch/tag/commit
22const commandCheckoutTo = async () => {
23 const routerParser = await router.resolveParser();
24 const routeState = await router.getState();
25 const quickPick = vscode.window.createQuickPick();
26
27 const loadMoreRefPickerItems = async () => {
28 quickPick.busy = true;
29 const scheme = adapterManager.getCurrentScheme();
30 const repository = Repository.getInstance(scheme, routeState.repo);
31 await Promise.all([repository.loadMoreBranches(), repository.loadMoreTags()]);
32 const [branchRefs, tagRefs] = await Promise.all([repository.getBranchList(), repository.getTagList()]);
33 const refPickerItems = [...branchRefs, ...tagRefs].map((ref) => ({
34 label: ref.name,
35 description: ref.description,
36 }));
37 const hasMore = (await Promise.all([repository.hasMoreBranches(), repository.hasMoreTags()])).some(Boolean);
38 quickPick.items = [...refPickerItems, hasMore ? loadMorePickerItem : null!, checkoutToItem].filter(Boolean);
39 quickPick.busy = false;
40 };
41
42 quickPick.placeholder = 'Input a ref to checkout';
43 quickPick.items = [checkoutToItem];
44 loadMoreRefPickerItems();
45 quickPick.show();
46
47 quickPick.onDidAccept(async () => {
48 const choice = quickPick.activeItems[0];
49 if (choice === loadMorePickerItem) {
50 return loadMoreRefPickerItems();
51 }
52 const selectedRef = choice === checkoutToItem ? quickPick.value : choice?.label;
53 const targetRef = selectedRef.toUpperCase() !== 'HEAD' ? selectedRef : undefined;
54 router.push(await routerParser.buildTreePath(routeState.repo, targetRef));
55 quickPick.hide();
56 });
57};
58
59export const registerRefCommands = (context: vscode.ExtensionContext) => {
60 return context.subscriptions.push(vscode.commands.registerCommand('github1s.commands.checkoutTo', commandCheckoutTo));

Callers

nothing calls this directly

Calls 7

loadMoreRefPickerItemsFunction · 0.85
resolveParserMethod · 0.80
getStateMethod · 0.80
pushMethod · 0.80
showMethod · 0.65
hideMethod · 0.65
buildTreePathMethod · 0.45

Tested by

no test coverage detected