From d6ecf1580510cd7f156dbe831c68f357fe162210 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Feb 2026 15:36:11 -0800 Subject: [PATCH] =?UTF-8?q?Fix=20worktree=E2=86=92local=20branch=20switch?= =?UTF-8?q?=20causing=20'already=20used=20by=20worktree'=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When in a secondary worktree and selecting a branch checked out in the main worktree (e.g. main), the code skipped the worktree redirect (because worktreePath === project.cwd) and tried git checkout, which git rejected. Now any branch with a worktreePath is handled as a redirect — main worktree redirects to local (worktreePath=null), secondary worktrees redirect to their path. Co-Authored-By: Claude Opus 4.6 --- apps/web/src/components/BranchToolbar.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsx index bc14843cf4c46180b6755a2fb00ab95a4668c21f..9fd8774d0fe31c00efe0c696ed378bffc3843d6f 100644 --- a/apps/web/src/components/BranchToolbar.tsx +++ b/apps/web/src/components/BranchToolbar.tsx @@ -128,13 +128,14 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B return; } - // If the branch already lives in a secondary worktree, point the thread - // there instead of trying to checkout (which git would reject). - // Ignore the main worktree (project cwd) — that's just a normal local checkout. - const isSecondaryWorktree = branch.worktreePath && branch.worktreePath !== activeProject?.cwd; - if (isSecondaryWorktree) { + // If the branch already lives in a worktree, redirect there instead of + // trying to checkout (which git would reject with "already used by worktree"). + if (branch.worktreePath) { + const isMainWorktree = branch.worktreePath === activeProject?.cwd; setThreadError(null); - setThreadBranch(branch.name, branch.worktreePath); + // Main worktree → switch back to local (project cwd, worktreePath=null). + // Secondary worktree → point the thread at that worktree path. + setThreadBranch(branch.name, isMainWorktree ? null : branch.worktreePath); setIsBranchMenuOpen(false); return; } -- 2.54.0