@devries-cameron20 / t3code Mirror · read-only / commits / ea68f2a667
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 05:45 UTC

fix(web): picking a branch in a subfolder project keeps the thread in the project folder (#29908)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Maria <maria-rcks@users.noreply.github.com>

Alex Southwell committed Nov 3, 2026 at 18:43 UTC ea68f2a66759fcef6b1673891ece4577ed97bed9
3 files changed +53 -15
apps/web/src/components/BranchToolbar.logic.test.ts
+37 -14
@@ -160,6 +160,18 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
160
161 describe("resolveBranchSelectionTarget", () => {
162 it("reuses an existing secondary worktree for the selected ref", () => {
163 + expect(
164 + resolveBranchSelectionTarget({
165 + activeProjectCwd: "/repo/nested-checkout/packages/app",
166 + activeProjectCheckoutRoot: "/repo/nested-checkout",
167 + activeWorktreePath: null,
168 + refName: { isDefault: true, worktreePath: "/repo" },
169 + }),
170 + ).toEqual({
171 + checkoutCwd: "/repo",
172 + nextWorktreePath: "/repo",
173 + reuseExistingWorktree: true,
174 + });
175 expect(
176 resolveBranchSelectionTarget({
177 activeProjectCwd: "/repo",
@@ -177,20 +189,31 @@ describe("resolveBranchSelectionTarget", () => {
189 });
190
191 it("switches back to the main repo when the ref already lives there", () => {
180 - expect(
181 - resolveBranchSelectionTarget({
182 - activeProjectCwd: "/repo",
183 - activeWorktreePath: "/repo/.t3/worktrees/feature-a",
184 - refName: {
185 - isDefault: true,
186 - worktreePath: "/repo",
187 - },
188 - }),
189 - ).toEqual({
190 - checkoutCwd: "/repo",
191 - nextWorktreePath: null,
192 - reuseExistingWorktree: true,
193 - });
192 + // A subdirectory project's own checkout is reported at the repository root.
193 + // The checkout root is undefined until the project's status loads.
194 + for (const [activeProjectCwd, activeWorktreePath, activeProjectCheckoutRoot] of [
195 + ["/repo", "/repo/.t3/worktrees/feature-a", "/repo"],
196 + ["/repo/packages/app", "/repo/.t3/worktrees/feature-a", "/repo"],
197 + ["/repo/packages/app", null, "/repo"],
198 + ["/repo/packages/app", "/repo/.t3/worktrees/feature-a", undefined],
199 + ["/repo/packages/app", null, undefined],
200 + ] as const) {
201 + expect(
202 + resolveBranchSelectionTarget({
203 + activeProjectCwd,
204 + activeProjectCheckoutRoot,
205 + activeWorktreePath,
206 + refName: {
207 + isDefault: true,
208 + worktreePath: "/repo",
209 + },
210 + }),
211 + ).toEqual({
212 + checkoutCwd: "/repo",
213 + nextWorktreePath: null,
214 + reuseExistingWorktree: true,
215 + });
216 + }
217 });
218
219 it("keeps checkout in the current worktree for non-default refs", () => {
apps/web/src/components/BranchToolbar.logic.ts
+8 -1
@@ -7,6 +7,7 @@ import type {
7 } from "@t3tools/contracts";
8 import * as Schema from "effect/Schema";
9 import { sanitizeNewRefName } from "@t3tools/shared/git";
10 +import { workspaceRelativeFilePath } from "@t3tools/shared/path";
11 import { toSortableTimestamp } from "@t3tools/client-runtime/state/thread-sort";
12 export { deriveLocalBranchNameFromRemoteRef, sanitizeNewRefName } from "@t3tools/shared/git";
13
@@ -247,6 +248,7 @@ export function resolveLocalCheckoutBranchMismatch(input: {
248
249 export function resolveBranchSelectionTarget(input: {
250 activeProjectCwd: string;
251 + activeProjectCheckoutRoot?: string | undefined;
252 activeWorktreePath: string | null;
253 refName: Pick<VcsRef, "isDefault" | "worktreePath">;
254 }): {
@@ -257,9 +259,14 @@ export function resolveBranchSelectionTarget(input: {
259 const { activeProjectCwd, activeWorktreePath, refName } = input;
260
261 if (refName.worktreePath) {
262 + // Until the project's checkout root loads, a checkout containing the project counts as its own.
263 + const isProjectCheckout =
264 + input.activeProjectCheckoutRoot === undefined
265 + ? workspaceRelativeFilePath(activeProjectCwd, refName.worktreePath) !== null
266 + : workspaceRelativeFilePath(input.activeProjectCheckoutRoot, refName.worktreePath) === ".";
267 return {
268 checkoutCwd: refName.worktreePath,
262 - nextWorktreePath: refName.worktreePath === activeProjectCwd ? null : refName.worktreePath,
269 + nextWorktreePath: isProjectCheckout ? null : refName.worktreePath,
270 reuseExistingWorktree: true,
271 };
272 }
apps/web/src/components/BranchToolbarBranchSelector.tsx
+8
@@ -224,6 +224,12 @@ export function BranchToolbarBranchSelector({
224 input: { cwd: branchCwd },
225 }),
226 );
227 + const projectStatusQuery = useEnvironmentQuery(
228 + activeProjectCwd === null
229 + ? null
230 + : vcsEnvironment.status({ environmentId, input: { cwd: activeProjectCwd } }),
231 + );
232 + const activeProjectCheckoutRoot = projectStatusQuery.data?.workingTree.rootPath;
233 const trimmedBranchQuery = branchQuery.trim();
234 const branchRefState = usePaginatedBranches({
235 environmentId,
@@ -389,6 +395,7 @@ export function BranchToolbarBranchSelector({
395
396 const selectionTarget = resolveBranchSelectionTarget({
397 activeProjectCwd,
398 + activeProjectCheckoutRoot,
399 activeWorktreePath,
400 refName,
401 });
@@ -631,6 +638,7 @@ export function BranchToolbarBranchSelector({
638 (!activeProjectCwd ||
639 !resolveBranchSelectionTarget({
640 activeProjectCwd,
641 + activeProjectCheckoutRoot,
642 activeWorktreePath,
643 refName,
644 }).reuseExistingWorktree))