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.
This commit is contained in:
shakespeare.diy committed 2025-10-14 20:55:03 -05:00
1 parent 4ad315f964
commit 1bbe210f4f
1 file changed
+14 -2
+14 -2
View File
@@ -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