From 1bbe210f4fd614e24c12defab8dd0907beb07e0f Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Tue, 14 Oct 2025 20:55:03 -0500 Subject: [PATCH] fix: Check git status directly when creating branch Updated handleCreateBranch to check git status matrix directly instead of relying on potentially stale gitStatus hook data. This ensures accurate detection of uncommitted changes at the time of branch creation. The branch will now properly auto-switch when there are no uncommitted changes, and stay on the current branch only when changes exist. --- src/components/git/BranchManager.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/git/BranchManager.tsx b/src/components/git/BranchManager.tsx index 8050047f..15fee5ef 100644 --- a/src/components/git/BranchManager.tsx +++ b/src/components/git/BranchManager.tsx @@ -188,8 +188,20 @@ export function BranchManager({ projectId, currentBranch, onBranchChange }: Bran object: currentRef, }); - // Check if we can automatically switch to the new branch - const hasUncommittedChanges = gitStatus?.hasUncommittedChanges ?? false; + // Check if we have uncommitted changes by getting status directly + const statusMatrix = await git.statusMatrix({ + dir: projectPath, + }); + + // Check if any files have changes (modified, added, deleted, or untracked) + const hasUncommittedChanges = statusMatrix.some(([, headStatus, workdirStatus, stageStatus]) => { + // No changes if all statuses match and file exists in HEAD + if (headStatus === workdirStatus && workdirStatus === stageStatus) { + return false; + } + // File has changes + return true; + }); if (!hasUncommittedChanges) { // No uncommitted changes, automatically switch to the new branch