diff --git a/apps/web/src/components/settings/WorktreeManager.tsx b/apps/web/src/components/settings/WorktreeManager.tsx index 76b177a763d81..6acc46e31395a 100644 --- a/apps/web/src/components/settings/WorktreeManager.tsx +++ b/apps/web/src/components/settings/WorktreeManager.tsx @@ -1,6 +1,14 @@ import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; import type { VcsListedWorktree } from "@t3tools/contracts"; -import { FolderGit2Icon, GitBranchIcon, PlusIcon, RefreshCwIcon, Trash2Icon } from "lucide-react"; +import { + FolderGit2Icon, + FolderIcon, + GitBranchIcon, + MessageSquareIcon, + PlusIcon, + RefreshCwIcon, + Trash2Icon, +} from "lucide-react"; import { useState, type FormEvent } from "react"; import { useProjects, useThreadShells } from "../../state/entities"; @@ -179,6 +187,9 @@ export function WorktreeManager() { const [selectedMemberKey, setSelectedMemberKey] = useState(null); const [creating, setCreating] = useState(false); const [deleting, setDeleting] = useState(null); + // Keep the target through the close animation. + const [shownDeleting, setShownDeleting] = useState(deleting); + if (deleting !== null && deleting !== shownDeleting) setShownDeleting(deleting); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const threads = useThreadShells(); @@ -207,8 +218,10 @@ export function WorktreeManager() { ? worktreeThreads(threads, projects, member.environmentId) : null; const associatedThreads = (tree: VcsListedWorktree) => threadsByWorktree?.get(tree.path) ?? []; - const deletingThreads = deleting - ? (worktreeThreads(threads, projects, deleting.environmentId).get(deleting.worktree.path) ?? []) + const deletingThreads = shownDeleting + ? (worktreeThreads(threads, projects, shownDeleting.environmentId).get( + shownDeleting.worktree.path, + ) ?? []) : []; const deletionBlocked = deleting ? worktreeDeletionBlockReason(deleting, member, deletingThreads) @@ -387,15 +400,50 @@ export function WorktreeManager() { Delete worktree? - {deleting?.worktree.prunable - ? `This removes the stale Git worktree record for ${deleting.worktree.path}.` - : `This permanently removes the working copy at ${deleting?.worktree.path}. Uncommitted and untracked changes are discarded.`}{" "} - Its branch, commits, and {deletingThreads.length} associated{" "} - {deletingThreads.length === 1 ? "thread" : "threads"} are kept. + {shownDeleting?.worktree.prunable + ? "Its folder is already missing. This removes the stale Git worktree record." + : "This permanently deletes the working copy and everything inside it."} + {shownDeleting && ( +
    +
  • + + + {shownDeleting.worktree.path} + +
  • +
  • + + {shownDeleting.worktree.branch ? ( + + The {shownDeleting.worktree.branch} branch + and its commits are kept. + + ) : ( + + Detached at{" "} + + {shownDeleting.worktree.head.slice(0, 7)} + + . Commits that aren't on a branch can be lost. + + )} +
  • + {deletingThreads.length > 0 && ( +
  • + + + {deletingThreads.length === 1 + ? "Its thread is kept." + : `Its ${deletingThreads.length} threads are kept.`} + +
  • + )} +
+ )} {(error || deletionBlocked) && ( -

+

{deletionBlocked ?? error}

)} diff --git a/apps/web/src/components/settings/worktreeManager.logic.test.ts b/apps/web/src/components/settings/worktreeManager.logic.test.ts index e7f688a316a07..9e7eb6285d5bf 100644 --- a/apps/web/src/components/settings/worktreeManager.logic.test.ts +++ b/apps/web/src/components/settings/worktreeManager.logic.test.ts @@ -68,6 +68,11 @@ describe("worktree deletion", () => { expect(worktreeDeletionBlockReason(target, null, [])).not.toBeNull(); }); + it("allows deleting a detached worktree", () => { + const detached = { ...target, worktree: { ...target.worktree, branch: null } }; + expect(worktreeDeletionBlockReason(detached, member, [idle])).toBeNull(); + }); + it("rechecks activity for an already selected deletion target", () => { expect(worktreeDeletionBlockReason(target, member, [idle])).toBeNull(); expect( diff --git a/apps/web/src/components/settings/worktreeManager.logic.ts b/apps/web/src/components/settings/worktreeManager.logic.ts index bd4ce88b3a420..794edb77cffae 100644 --- a/apps/web/src/components/settings/worktreeManager.logic.ts +++ b/apps/web/src/components/settings/worktreeManager.logic.ts @@ -54,7 +54,6 @@ export function worktreeDeletionBlockReason( const tree = target.worktree; if (tree.locked) return "Locked in Git"; if (tree.isMain || tree.path === target.cwd) return "Selected project checkout"; - if (!tree.branch) return "Detached worktree"; if ( threads.some( (thread) =>