Repository navigation
fix(web): threads whose worktree was removed can move to another checkout #38993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9914160
6d07c6a
4b7f252
0ccd617
ed3fd3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { isThreadCheckoutMissing } from "@t3tools/client-runtime/thread-checkout"; | ||
| import { thrownErrorMessage } from "@t3tools/client-runtime/errors"; | ||
| import { ThreadDetailsControl } from "./chat/ThreadDetailsControl"; | ||
| import { ComposerContextLabel } from "./ComposerContextLabel"; | ||
|
|
@@ -174,7 +175,7 @@ export function BranchToolbarBranchSelector({ | |
| ? serverThread.worktreePath | ||
| : (draftThread?.worktreePath ?? null); | ||
| const activeProjectCwd = activeProject?.workspaceRoot ?? null; | ||
| const branchCwd = activeWorktreePath ?? activeProjectCwd; | ||
| const statusCwd = activeWorktreePath ?? activeProjectCwd; | ||
| const hasServerThread = serverThread !== null; | ||
| const canUpdateThreadBranch = !hasServerThread || canOperateThread; | ||
| const canChangeThreadBranch = canWriteSourceControl && canUpdateThreadBranch; | ||
|
|
@@ -258,18 +259,27 @@ export function BranchToolbarBranchSelector({ | |
| const [branchQuery, setBranchQuery] = useState(""); | ||
|
|
||
| const branchStatusQuery = useEnvironmentQuery( | ||
| branchCwd === null | ||
| statusCwd === null | ||
| ? null | ||
| : vcsEnvironment.status({ | ||
| environmentId, | ||
| input: { cwd: branchCwd }, | ||
| input: { cwd: statusCwd }, | ||
| }), | ||
| ); | ||
| const projectStatusQuery = useEnvironmentQuery( | ||
| activeProjectCwd === null | ||
| ? null | ||
| : vcsEnvironment.status({ environmentId, input: { cwd: activeProjectCwd } }), | ||
| ); | ||
| const checkoutMissing = isThreadCheckoutMissing({ | ||
| worktreePath: activeWorktreePath, | ||
| worktreeIsRepo: branchStatusQuery.data?.isRepo, | ||
| projectIsRepo: projectStatusQuery.data?.isRepo, | ||
| }); | ||
| const branchCwd = checkoutMissing ? activeProjectCwd : statusCwd; | ||
| // Refs resolve against the checkout the thread can move to, not one that is gone. | ||
| const selectableWorktreePath = (worktreePath: string | null) => | ||
| checkoutMissing ? null : worktreePath; | ||
| const activeProjectCheckoutRoot = projectStatusQuery.data?.workingTree.rootPath; | ||
| const trimmedBranchQuery = branchQuery.trim(); | ||
| const branchRefState = usePaginatedBranches( | ||
|
|
@@ -298,7 +308,7 @@ export function BranchToolbarBranchSelector({ | |
| : resolveBranchSelectionTarget({ | ||
| activeProjectCwd, | ||
| activeProjectCheckoutRoot, | ||
| activeWorktreePath, | ||
| activeWorktreePath: selectableWorktreePath(activeWorktreePath), | ||
| refName, | ||
| }).nextWorktreePath, | ||
| }); | ||
|
|
@@ -482,7 +492,7 @@ export function BranchToolbarBranchSelector({ | |
| const selectionTarget = resolveBranchSelectionTarget({ | ||
| activeProjectCwd, | ||
| activeProjectCheckoutRoot, | ||
| activeWorktreePath: latest.worktreePath, | ||
| activeWorktreePath: selectableWorktreePath(latest.worktreePath), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Limit the missing-checkout normalization to the path that was missing when the selection started.
Suggested fix
|
||
| refName, | ||
| }); | ||
|
|
||
|
|
@@ -571,6 +581,20 @@ export function BranchToolbarBranchSelector({ | |
| if (!canChangeThreadBranch) return; | ||
| const name = sanitizeNewRefName(rawName); | ||
| if (!branchCwd || !name || isBranchActionPending) return; | ||
| const latest = readLatestThreadState(); | ||
| // Refuse before switching the checkout, or a running thread stays bound to the missing one. | ||
| if ( | ||
| isWorktreeChangeBlocked({ | ||
| runtime: latest.runtime, | ||
| currentWorktreePath: latest.worktreePath, | ||
| nextWorktreePath: selectableWorktreePath(activeWorktreePath), | ||
| }) | ||
| ) { | ||
| toastManager.add( | ||
| stackedThreadToast({ type: "warning", title: messages(WORKTREE_CHANGE_BLOCKED_MESSAGE) }), | ||
| ); | ||
| return; | ||
| } | ||
| latestSelectionIdRef.current++; | ||
|
|
||
| setIsBranchMenuOpen(false); | ||
|
|
@@ -589,7 +613,7 @@ export function BranchToolbarBranchSelector({ | |
| }); | ||
| if (createBranchResult._tag === "Success") { | ||
| const nextBranchName = createBranchResult.value.refName; | ||
| const applied = setThreadBranch(nextBranchName, activeWorktreePath); | ||
| const applied = setThreadBranch(nextBranchName, selectableWorktreePath(activeWorktreePath)); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| if (applied) { | ||
| setBranchHold({ | ||
| branch: nextBranchName, | ||
|
|
@@ -794,7 +818,7 @@ export function BranchToolbarBranchSelector({ | |
| !resolveBranchSelectionTarget({ | ||
| activeProjectCwd, | ||
| activeProjectCheckoutRoot, | ||
| activeWorktreePath, | ||
| activeWorktreePath: selectableWorktreePath(activeWorktreePath), | ||
| refName, | ||
| }).reuseExistingWorktree)) || | ||
| isWorktreeChangeBlockedForRef(refName) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block commit and other checkout-changing overview actions until the user selects a recovery checkout.
When the thread checkout is missing,
selectedThreadCwdfalls back to the project root. The overview still builds its menu from that root's status, so the Commit item is enabled. Submitting it runsrunStackedActionin the project root. The thread keeps its removed worktree path, because the metadata update runs only when a branch is created. The result is a commit in a checkout that the thread is not bound to, and the user does not choose that checkout.While
checkoutMissingis true, disable the commit and other checkout-changing items insheetMenuItems. Keep the Branches & worktrees row enabled, because it is the recovery path. Blocking the mutation inrunSelectedThreadGitMutationalone is not enough, because the overview would still open the commit sheet.