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