feat(branch-dropdown): add switch-to-branch entry for local and remote branches

This commit is contained in:
xintaofei
2026-04-22 23:29:36 +08:00
parent 3030bb7981
commit 2dbdaa9c74

View File

@@ -68,6 +68,7 @@ import {
gitFetch, gitFetch,
gitNewBranch, gitNewBranch,
gitWorktreeAdd, gitWorktreeAdd,
gitCheckout,
gitListAllBranches, gitListAllBranches,
gitMerge, gitMerge,
gitRebase, 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() { async function handleNewBranch() {
const name = newBranchName.trim() const name = newBranchName.trim()
if (!name) return if (!name) return
@@ -492,6 +508,18 @@ export function BranchDropdown() {
{label} {label}
</DropdownMenuSubTrigger> </DropdownMenuSubTrigger>
<DropdownMenuSubContent> <DropdownMenuSubContent>
<DropdownMenuItem
onSelect={() => {
if (isRemote) {
void handleCheckoutRemote(b)
} else {
void handleCheckout(b)
}
}}
>
<GitBranch className="h-3.5 w-3.5" />
{t("switchToBranch")}
</DropdownMenuItem>
<DropdownMenuItem <DropdownMenuItem
onSelect={() => { onSelect={() => {
setDropdownOpen(false) setDropdownOpen(false)