Enrich branches with worktree paths, fix toolbar display, and improve HMR config
- Add worktreePath to gitBranchSchema and populate from `git worktree list --porcelain` - Redirect to existing worktree when selecting a branch that's already checked out (instead of failing with "already used by worktree") - Distinguish main worktree (project cwd) from secondary worktrees in selection logic - Fix toolbar to show three states: Local, Worktree (existing), New worktree (pending) - Add explicit protocol/host to Vite HMR config for reliable Electron WebSocket - Auto-open DevTools in dev mode for HMR debugging Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
1 parent
807e3d18de
commit
8324949b54
5 files changed
+58
-12
No files matched your search
@@ -186,6 +186,7 @@ function createWindow(): BrowserWindow {
|
||||
|
||||
if (isDevelopment) {
|
||||
void window.loadURL(process.env.VITE_DEV_SERVER_URL as string);
|
||||
window.webContents.openDevTools({ mode: "detach" });
|
||||
} else {
|
||||
if (!fs.existsSync(WEB_ENTRY)) {
|
||||
throw new Error(`Web bundle missing at ${WEB_ENTRY}`);
|
||||
|
||||
+28
-6
@@ -123,19 +123,41 @@ export async function listGitBranches(input: GitListBranchesInput): Promise<GitL
|
||||
}
|
||||
|
||||
// Resolve the real default branch from the remote
|
||||
const defaultRef = await runGit(["symbolic-ref", "refs/remotes/origin/HEAD"], input.cwd, 5_000);
|
||||
const [defaultRef, worktreeList] = await Promise.all([
|
||||
runGit(["symbolic-ref", "refs/remotes/origin/HEAD"], input.cwd, 5_000),
|
||||
runGit(["worktree", "list", "--porcelain"], input.cwd, 5_000),
|
||||
]);
|
||||
const defaultBranch =
|
||||
defaultRef.code === 0 ? defaultRef.stdout.trim().replace(/^refs\/remotes\/origin\//, "") : null;
|
||||
|
||||
// Build branch-name → worktree-path map from porcelain output.
|
||||
const worktreeMap = new Map<string, string>();
|
||||
if (worktreeList.code === 0) {
|
||||
let currentPath: string | null = null;
|
||||
for (const line of worktreeList.stdout.split("\n")) {
|
||||
if (line.startsWith("worktree ")) {
|
||||
currentPath = line.slice("worktree ".length);
|
||||
} else if (line.startsWith("branch refs/heads/") && currentPath) {
|
||||
worktreeMap.set(line.slice("branch refs/heads/".length), currentPath);
|
||||
} else if (line === "") {
|
||||
currentPath = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const branches = result.stdout
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0)
|
||||
.map((line) => ({
|
||||
name: line.replace(/^[*+]\s+/, ""),
|
||||
current: line.startsWith("* "),
|
||||
isDefault: line.replace(/^[*+]\s+/, "") === defaultBranch,
|
||||
}))
|
||||
.map((line) => {
|
||||
const name = line.replace(/^[*+]\s+/, "");
|
||||
return {
|
||||
name,
|
||||
current: line.startsWith("* "),
|
||||
isDefault: name === defaultBranch,
|
||||
worktreePath: worktreeMap.get(name) ?? null,
|
||||
};
|
||||
})
|
||||
.toSorted((a, b) => {
|
||||
if (a.current !== b.current) return a.current ? -1 : 1;
|
||||
if (a.isDefault !== b.isDefault) return a.isDefault ? -1 : 1;
|
||||
|
||||
@@ -122,6 +122,17 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
return;
|
||||
}
|
||||
|
||||
// If the branch already lives in a secondary worktree, point the thread
|
||||
// there instead of trying to checkout (which git would reject).
|
||||
// Ignore the main worktree (project cwd) — that's just a normal local checkout.
|
||||
const isSecondaryWorktree = branch.worktreePath && branch.worktreePath !== activeProject?.cwd;
|
||||
if (isSecondaryWorktree) {
|
||||
setThreadError(null);
|
||||
setThreadBranch(branch.name, branch.worktreePath);
|
||||
setIsBranchMenuOpen(false);
|
||||
return;
|
||||
}
|
||||
|
||||
checkoutMutation.mutate(branch.name, {
|
||||
onSuccess: () => {
|
||||
setThreadError(null);
|
||||
@@ -150,9 +161,9 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-3xl items-center justify-between px-5 pb-3 pt-1">
|
||||
<div className="flex items-center gap-2">
|
||||
{envLocked ? (
|
||||
{envLocked || activeWorktreePath ? (
|
||||
<span className="inline-flex items-center gap-1.5 px-1 text-[12px] text-muted-foreground/55">
|
||||
{activeThread.worktreePath ? "Worktree" : "Local"}
|
||||
{activeWorktreePath ? "Worktree" : "Local"}
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
@@ -188,7 +199,7 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
>
|
||||
<span className="max-w-[240px] truncate font-mono">
|
||||
{activeThread.branch
|
||||
? envMode === "worktree" && !envLocked
|
||||
? envMode === "worktree" && !activeWorktreePath
|
||||
? `From ${activeThread.branch}`
|
||||
: activeThread.branch
|
||||
: "Select branch"}
|
||||
@@ -218,6 +229,8 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
<div className="max-h-64 overflow-y-auto">
|
||||
{branches.map((branch) => {
|
||||
const isSelected = branch.name === activeThread.branch;
|
||||
const hasSecondaryWorktree =
|
||||
branch.worktreePath && branch.worktreePath !== activeProject.cwd;
|
||||
return (
|
||||
<button
|
||||
key={branch.name}
|
||||
@@ -230,9 +243,9 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
onClick={() => selectBranch(branch)}
|
||||
>
|
||||
<span className="truncate">{branch.name}</span>
|
||||
{(branch.current || branch.isDefault) && (
|
||||
{(branch.current || branch.isDefault || hasSecondaryWorktree) && (
|
||||
<span className="shrink-0 text-[10px] text-muted-foreground/45">
|
||||
{branch.current ? "current" : "default"}
|
||||
{branch.current ? "current" : hasSecondaryWorktree ? "worktree" : "default"}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
|
||||
+10
-1
@@ -2,6 +2,8 @@ import tailwindcss from "@tailwindcss/vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { defineConfig } from "vite";
|
||||
|
||||
const port = Number(process.env.PORT ?? 5173);
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react({
|
||||
@@ -16,8 +18,15 @@ export default defineConfig({
|
||||
"import.meta.env.VITE_WS_URL": JSON.stringify(process.env.VITE_WS_URL ?? ""),
|
||||
},
|
||||
server: {
|
||||
port: Number(process.env.PORT ?? 5173),
|
||||
port,
|
||||
strictPort: true,
|
||||
hmr: {
|
||||
// Explicit config so Vite's HMR WebSocket connects reliably
|
||||
// inside Electron's BrowserWindow. Vite 8 uses console.debug for
|
||||
// connection logs — enable "Verbose" in DevTools to see them.
|
||||
protocol: "ws",
|
||||
host: "localhost",
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: "dist",
|
||||
|
||||
@@ -40,6 +40,7 @@ export const gitBranchSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
current: z.boolean(),
|
||||
isDefault: z.boolean(),
|
||||
worktreePath: z.string().min(1).nullable(),
|
||||
});
|
||||
|
||||
export const gitWorktreeSchema = z.object({
|
||||
|
||||
Reference in new issue
Block a user