Show worktree name in thread delete confirmation

- Format orphaned worktree paths to display only the final segment
- Apply formatting in Sidebar delete prompt for cleaner UX
- Add tests for Unix, Windows, trailing slash, and fallback cases
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-02-12 22:57:56 -08:00
1 parent b6523a15dc
commit 4f5eb3be4d
3 files changed
+44 -3

No files matched your search

+5 -2
View File
@@ -12,7 +12,7 @@ import {
type Thread,
} from "../types";
import { useNativeApi } from "../hooks/useNativeApi";
import { getOrphanedWorktreePathForThread } from "../worktreeCleanup";
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
const THEME_CYCLE = { system: "light", light: "dark", dark: "system" } as const;
function formatRelativeTime(iso: string): string {
@@ -265,12 +265,15 @@ export default function Sidebar() {
if (!thread) return;
const threadProject = state.projects.find((project) => project.id === thread.projectId);
const orphanedWorktreePath = getOrphanedWorktreePathForThread(state.threads, threadId);
const displayWorktreePath = orphanedWorktreePath
? formatWorktreePathForDisplay(orphanedWorktreePath)
: null;
const shouldDeleteWorktree =
orphanedWorktreePath !== null &&
(await api.dialogs.confirm(
[
"This thread is the only one linked to this worktree:",
orphanedWorktreePath,
displayWorktreePath ?? orphanedWorktreePath,
"",
"Delete the worktree too?",
].join("\n"),
+27 -1
View File
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_THREAD_TERMINAL_HEIGHT, DEFAULT_THREAD_TERMINAL_ID, type Thread } from "./types";
import { getOrphanedWorktreePathForThread } from "./worktreeCleanup";
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "./worktreeCleanup";
function makeThread(overrides: Partial<Thread> = {}): Thread {
return {
@@ -69,3 +69,29 @@ describe("getOrphanedWorktreePathForThread", () => {
expect(result).toBe("/tmp/repo/worktrees/feature-a");
});
});
describe("formatWorktreePathForDisplay", () => {
it("shows only the last path segment for unix-like paths", () => {
const result = formatWorktreePathForDisplay(
"/Users/julius/.t3/worktrees/codething-mvp/codething-4e609bb8",
);
expect(result).toBe("codething-4e609bb8");
});
it("normalizes windows separators before selecting the final segment", () => {
const result = formatWorktreePathForDisplay(
"C:\\Users\\julius\\.t3\\worktrees\\codething-mvp\\codething-4e609bb8",
);
expect(result).toBe("codething-4e609bb8");
});
it("uses the final segment even when outside ~/.t3/worktrees", () => {
const result = formatWorktreePathForDisplay("/tmp/custom-worktrees/my-worktree");
expect(result).toBe("my-worktree");
});
it("ignores trailing slashes", () => {
const result = formatWorktreePathForDisplay("/tmp/custom-worktrees/my-worktree/");
expect(result).toBe("my-worktree");
});
});
+12
View File
@@ -31,3 +31,15 @@ export function getOrphanedWorktreePathForThread(
return isShared ? null : targetWorktreePath;
}
export function formatWorktreePathForDisplay(worktreePath: string): string {
const trimmed = worktreePath.trim();
if (!trimmed) {
return worktreePath;
}
const normalized = trimmed.replace(/\\/g, "/").replace(/\/+$/, "");
const parts = normalized.split("/");
const lastPart = parts[parts.length - 1]?.trim() ?? "";
return lastPart.length > 0 ? lastPart : trimmed;
}