| ... | ... | @@ -128,13 +128,14 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B |
| 128 | 128 | return; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | | // If the branch already lives in a secondary worktree, point the thread |
| 132 | | // there instead of trying to checkout (which git would reject). |
| 133 | | // Ignore the main worktree (project cwd) — that's just a normal local checkout. |
| 134 | | const isSecondaryWorktree = branch.worktreePath && branch.worktreePath !== activeProject?.cwd; |
| 135 | | if (isSecondaryWorktree) { |
| 131 | // If the branch already lives in a worktree, redirect there instead of |
| 132 | // trying to checkout (which git would reject with "already used by worktree"). |
| 133 | if (branch.worktreePath) { |
| 134 | const isMainWorktree = branch.worktreePath === activeProject?.cwd; |
| 136 | 135 | setThreadError(null); |
| 137 | | setThreadBranch(branch.name, branch.worktreePath); |
| 136 | // Main worktree → switch back to local (project cwd, worktreePath=null). |
| 137 | // Secondary worktree → point the thread at that worktree path. |
| 138 | setThreadBranch(branch.name, isMainWorktree ? null : branch.worktreePath); |
| 138 | 139 | setIsBranchMenuOpen(false); |
| 139 | 140 | return; |
| 140 | 141 | } |