From 048590358459204643836dfbe7fd41e932abbc71 Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:18:02 +1100 Subject: [PATCH 1/3] fix(web): picking a branch in a subfolder project keeps the thread in the project folder Co-Authored-By: Claude Opus 5.5 --- .../components/BranchToolbar.logic.test.ts | 35 +++++++++++-------- .../web/src/components/BranchToolbar.logic.ts | 6 +++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts index 08e6f7633dee3..50632d7d7cef6 100644 --- a/apps/web/src/components/BranchToolbar.logic.test.ts +++ b/apps/web/src/components/BranchToolbar.logic.test.ts @@ -177,20 +177,27 @@ describe("resolveBranchSelectionTarget", () => { }); it("switches back to the main repo when the ref already lives there", () => { - expect( - resolveBranchSelectionTarget({ - activeProjectCwd: "/repo", - activeWorktreePath: "/repo/.t3/worktrees/feature-a", - refName: { - isDefault: true, - worktreePath: "/repo", - }, - }), - ).toEqual({ - checkoutCwd: "/repo", - nextWorktreePath: null, - reuseExistingWorktree: true, - }); + // A subdirectory project's own checkout is reported at the repository root. + for (const [activeProjectCwd, activeWorktreePath] of [ + ["/repo", "/repo/.t3/worktrees/feature-a"], + ["/repo/packages/app", "/repo/.t3/worktrees/feature-a"], + ["/repo/packages/app", null], + ] as const) { + expect( + resolveBranchSelectionTarget({ + activeProjectCwd, + activeWorktreePath, + refName: { + isDefault: true, + worktreePath: "/repo", + }, + }), + ).toEqual({ + checkoutCwd: "/repo", + nextWorktreePath: null, + reuseExistingWorktree: true, + }); + } }); it("keeps checkout in the current worktree for non-default refs", () => { diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts index e22dcfaddedeb..a8b77206c78a4 100644 --- a/apps/web/src/components/BranchToolbar.logic.ts +++ b/apps/web/src/components/BranchToolbar.logic.ts @@ -7,6 +7,7 @@ import type { } from "@t3tools/contracts"; import * as Schema from "effect/Schema"; import { sanitizeNewRefName } from "@t3tools/shared/git"; +import { workspaceRelativeFilePath } from "@t3tools/shared/path"; import { toSortableTimestamp } from "@t3tools/client-runtime/state/thread-sort"; export { deriveLocalBranchNameFromRemoteRef, sanitizeNewRefName } from "@t3tools/shared/git"; @@ -257,9 +258,12 @@ export function resolveBranchSelectionTarget(input: { const { activeProjectCwd, activeWorktreePath, refName } = input; if (refName.worktreePath) { + // A project in a repository subdirectory sits inside its checkout's root. + const isProjectCheckout = + workspaceRelativeFilePath(activeProjectCwd, refName.worktreePath) !== null; return { checkoutCwd: refName.worktreePath, - nextWorktreePath: refName.worktreePath === activeProjectCwd ? null : refName.worktreePath, + nextWorktreePath: isProjectCheckout ? null : refName.worktreePath, reuseExistingWorktree: true, }; } From 5648f0cfe4a7ebf27af7cb50285471f3ae942e5e Mon Sep 17 00:00:00 2001 From: Maria Date: Tue, 3 Nov 2026 05:57:52 +0000 Subject: [PATCH 2/3] fix(web): identify the project checkout when selecting branches --- apps/web/src/components/BranchToolbar.logic.test.ts | 13 +++++++++++++ apps/web/src/components/BranchToolbar.logic.ts | 7 +++++-- .../src/components/BranchToolbarBranchSelector.tsx | 8 ++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts index 50632d7d7cef6..4d803bcceebac 100644 --- a/apps/web/src/components/BranchToolbar.logic.test.ts +++ b/apps/web/src/components/BranchToolbar.logic.test.ts @@ -160,6 +160,18 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => { describe("resolveBranchSelectionTarget", () => { it("reuses an existing secondary worktree for the selected ref", () => { + expect( + resolveBranchSelectionTarget({ + activeProjectCwd: "/repo/nested-checkout/packages/app", + activeProjectCheckoutRoot: "/repo/nested-checkout", + activeWorktreePath: null, + refName: { isDefault: true, worktreePath: "/repo" }, + }), + ).toEqual({ + checkoutCwd: "/repo", + nextWorktreePath: "/repo", + reuseExistingWorktree: true, + }); expect( resolveBranchSelectionTarget({ activeProjectCwd: "/repo", @@ -186,6 +198,7 @@ describe("resolveBranchSelectionTarget", () => { expect( resolveBranchSelectionTarget({ activeProjectCwd, + activeProjectCheckoutRoot: "/repo", activeWorktreePath, refName: { isDefault: true, diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts index a8b77206c78a4..8582c41a3cfdc 100644 --- a/apps/web/src/components/BranchToolbar.logic.ts +++ b/apps/web/src/components/BranchToolbar.logic.ts @@ -248,6 +248,7 @@ export function resolveLocalCheckoutBranchMismatch(input: { export function resolveBranchSelectionTarget(input: { activeProjectCwd: string; + activeProjectCheckoutRoot?: string | undefined; activeWorktreePath: string | null; refName: Pick; }): { @@ -258,9 +259,11 @@ export function resolveBranchSelectionTarget(input: { const { activeProjectCwd, activeWorktreePath, refName } = input; if (refName.worktreePath) { - // A project in a repository subdirectory sits inside its checkout's root. const isProjectCheckout = - workspaceRelativeFilePath(activeProjectCwd, refName.worktreePath) !== null; + workspaceRelativeFilePath( + input.activeProjectCheckoutRoot ?? activeProjectCwd, + refName.worktreePath, + ) === "."; return { checkoutCwd: refName.worktreePath, nextWorktreePath: isProjectCheckout ? null : refName.worktreePath, diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index fab250f6adaf8..9782f258afe19 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -224,6 +224,12 @@ export function BranchToolbarBranchSelector({ input: { cwd: branchCwd }, }), ); + const projectStatusQuery = useEnvironmentQuery( + activeProjectCwd === null + ? null + : vcsEnvironment.status({ environmentId, input: { cwd: activeProjectCwd } }), + ); + const activeProjectCheckoutRoot = projectStatusQuery.data?.workingTree.rootPath; const trimmedBranchQuery = branchQuery.trim(); const branchRefState = usePaginatedBranches({ environmentId, @@ -389,6 +395,7 @@ export function BranchToolbarBranchSelector({ const selectionTarget = resolveBranchSelectionTarget({ activeProjectCwd, + activeProjectCheckoutRoot, activeWorktreePath, refName, }); @@ -631,6 +638,7 @@ export function BranchToolbarBranchSelector({ (!activeProjectCwd || !resolveBranchSelectionTarget({ activeProjectCwd, + activeProjectCheckoutRoot, activeWorktreePath, refName, }).reuseExistingWorktree)) From b73107cab375eac8892cd7b0d4b6426ddae11c14 Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 17:39:02 +1100 Subject: [PATCH 3/3] fix(web): branch picks before the checkout root loads stay in the project Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/BranchToolbar.logic.test.ts | 13 ++++++++----- apps/web/src/components/BranchToolbar.logic.ts | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts index 4d803bcceebac..903a20066b39e 100644 --- a/apps/web/src/components/BranchToolbar.logic.test.ts +++ b/apps/web/src/components/BranchToolbar.logic.test.ts @@ -190,15 +190,18 @@ describe("resolveBranchSelectionTarget", () => { it("switches back to the main repo when the ref already lives there", () => { // A subdirectory project's own checkout is reported at the repository root. - for (const [activeProjectCwd, activeWorktreePath] of [ - ["/repo", "/repo/.t3/worktrees/feature-a"], - ["/repo/packages/app", "/repo/.t3/worktrees/feature-a"], - ["/repo/packages/app", null], + // The checkout root is undefined until the project's status loads. + for (const [activeProjectCwd, activeWorktreePath, activeProjectCheckoutRoot] of [ + ["/repo", "/repo/.t3/worktrees/feature-a", "/repo"], + ["/repo/packages/app", "/repo/.t3/worktrees/feature-a", "/repo"], + ["/repo/packages/app", null, "/repo"], + ["/repo/packages/app", "/repo/.t3/worktrees/feature-a", undefined], + ["/repo/packages/app", null, undefined], ] as const) { expect( resolveBranchSelectionTarget({ activeProjectCwd, - activeProjectCheckoutRoot: "/repo", + activeProjectCheckoutRoot, activeWorktreePath, refName: { isDefault: true, diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts index 8582c41a3cfdc..a967c3171fbd1 100644 --- a/apps/web/src/components/BranchToolbar.logic.ts +++ b/apps/web/src/components/BranchToolbar.logic.ts @@ -259,11 +259,11 @@ export function resolveBranchSelectionTarget(input: { const { activeProjectCwd, activeWorktreePath, refName } = input; if (refName.worktreePath) { + // Until the project's checkout root loads, a checkout containing the project counts as its own. const isProjectCheckout = - workspaceRelativeFilePath( - input.activeProjectCheckoutRoot ?? activeProjectCwd, - refName.worktreePath, - ) === "."; + input.activeProjectCheckoutRoot === undefined + ? workspaceRelativeFilePath(activeProjectCwd, refName.worktreePath) !== null + : workspaceRelativeFilePath(input.activeProjectCheckoutRoot, refName.worktreePath) === "."; return { checkoutCwd: refName.worktreePath, nextWorktreePath: isProjectCheckout ? null : refName.worktreePath,