From 2ecb67e08293bfa2007ff1e54eaac4bd35609c1d Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Tue, 14 Oct 2025 21:04:05 -0500 Subject: [PATCH] fix: Always switch to new branch after creation Removed the uncommitted changes check - now always attempts to checkout the new branch immediately after creation. If checkout fails, shows an error message with the reason. This ensures users are always switched to their newly created branch. --- src/components/git/BranchManager.tsx | 31 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/components/git/BranchManager.tsx b/src/components/git/BranchManager.tsx index 15fee5ef..005051ec 100644 --- a/src/components/git/BranchManager.tsx +++ b/src/components/git/BranchManager.tsx @@ -203,30 +203,29 @@ export function BranchManager({ projectId, currentBranch, onBranchChange }: Bran return true; }); - if (!hasUncommittedChanges) { - // No uncommitted changes, automatically switch to the new branch - try { - await git.checkout({ - dir: projectPath, - ref: branchName, - }); + // Always try to switch to the new branch + try { + await git.checkout({ + dir: projectPath, + ref: branchName, + }); + if (hasUncommittedChanges) { + toast({ + title: 'Branch created and switched', + description: `Switched to "${branchName}" with uncommitted changes`, + }); + } else { toast({ title: 'Branch created and switched', description: `Created and switched to branch "${branchName}"`, }); - } catch (checkoutError) { - // Branch created but checkout failed - toast({ - title: 'Branch created', - description: `Created branch "${branchName}" but failed to switch to it`, - }); } - } else { - // Has uncommitted changes, don't switch automatically + } catch (checkoutError) { + // Branch created but checkout failed toast({ title: 'Branch created', - description: `Created branch "${branchName}". Commit your changes to switch to it.`, + description: `Created "${branchName}" but could not switch: ${checkoutError instanceof Error ? checkoutError.message : 'Unknown error'}`, }); }