From 2dbdaa9c7427cf1efd98e05c55d443260cd055a8 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Wed, 22 Apr 2026 23:29:36 +0800 Subject: [PATCH] feat(branch-dropdown): add switch-to-branch entry for local and remote branches --- src/components/layout/branch-dropdown.tsx | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/components/layout/branch-dropdown.tsx b/src/components/layout/branch-dropdown.tsx index a951977..032f4c6 100644 --- a/src/components/layout/branch-dropdown.tsx +++ b/src/components/layout/branch-dropdown.tsx @@ -68,6 +68,7 @@ import { gitFetch, gitNewBranch, gitWorktreeAdd, + gitCheckout, gitListAllBranches, gitMerge, gitRebase, @@ -293,6 +294,21 @@ export function BranchDropdown() { } } + async function handleCheckout(branchName: string) { + setDropdownOpen(false) + await runGitTask(t("tasks.checkoutTo", { branchName }), () => + gitCheckout(folderPath, branchName) + ) + } + + async function handleCheckoutRemote(remoteBranch: string) { + const localName = remoteBranch.replace(/^[^/]+\//, "") + setDropdownOpen(false) + await runGitTask(t("tasks.checkoutTo", { branchName: localName }), () => + gitCheckout(folderPath, localName) + ) + } + async function handleNewBranch() { const name = newBranchName.trim() if (!name) return @@ -492,6 +508,18 @@ export function BranchDropdown() { {label} + { + if (isRemote) { + void handleCheckoutRemote(b) + } else { + void handleCheckout(b) + } + }} + > + + {t("switchToBranch")} + { setDropdownOpen(false)