Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/desktop/src/main/services/ipc/registerIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
BatchAssessmentResult,
AttachLaneArgs,
AdoptAttachedLaneArgs,
UnregisteredLaneCandidate,
AppInfo,
ClearLocalAdeDataArgs,
ClearLocalAdeDataResult,
Expand Down Expand Up @@ -3307,6 +3308,11 @@ export function registerIpc({
return lane;
});

ipcMain.handle(IPC.lanesListUnregisteredWorktrees, async (): Promise<UnregisteredLaneCandidate[]> => {
const ctx = getCtx();
return ctx.laneService.listUnregisteredWorktrees();
});

ipcMain.handle(IPC.lanesAdoptAttached, async (_event, arg: AdoptAttachedLaneArgs): Promise<LaneSummary> => {
const ctx = getCtx();
const lane = await ctx.laneService.adoptAttached(arg);
Expand Down
37 changes: 37 additions & 0 deletions apps/desktop/src/main/services/lanes/laneService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type {
RebasePushArgs,
PushMode,
StackChainItem,
UnregisteredLaneCandidate,
UpdateLaneAppearanceArgs
} from "../../../shared/types";
import { resolveAdeLayout } from "../../../shared/adeLayout";
Expand Down Expand Up @@ -1128,6 +1129,42 @@ export function createLaneService({
return await listLanes(args);
},

async listUnregisteredWorktrees(): Promise<UnregisteredLaneCandidate[]> {
const stdout = await runGitOrThrow(
["worktree", "list", "--porcelain"],
{ cwd: projectRoot, timeoutMs: 15_000 }
);

const blocks = stdout.split(/\n\n+/).filter(Boolean);
const worktrees: UnregisteredLaneCandidate[] = [];

for (const block of blocks) {
const lines = block.split(/\r?\n/);
let wtPath = "";
let branch = "";
let isBare = false;
for (const line of lines) {
if (line.startsWith("worktree ")) wtPath = line.slice("worktree ".length).trim();
if (line.startsWith("branch ")) branch = line.slice("branch ".length).trim().replace(/^refs\/heads\//, "");
if (line === "bare") isBare = true;
}
if (!wtPath || isBare) continue;
worktrees.push({ path: normAbs(wtPath), branch });
}

// Filter out primary worktree and worktrees already tracked as lanes
const registeredPaths = new Set(
db.all<{ worktree_path: string }>(
"select worktree_path from lanes where project_id = ?",
[projectId]
).map((row) => normAbs(row.worktree_path))
);

return worktrees.filter(
(wt) => wt.path !== normalizedProjectRoot && !registeredPaths.has(wt.path)
);
},

getStateSnapshot(laneId: string): LaneStateSnapshotSummary | null {
const row = db.get<LaneStateSnapshotRow>(
`
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/preload/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ApplyConflictProposalArgs,
AttachLaneArgs,
AdoptAttachedLaneArgs,
UnregisteredLaneCandidate,
AppInfo,
AutoUpdateSnapshot,
ClearLocalAdeDataArgs,
Expand Down Expand Up @@ -762,6 +763,7 @@ declare global {
createFromUnstaged: (args: CreateLaneFromUnstagedArgs) => Promise<LaneSummary>;
importBranch: (args: ImportBranchLaneArgs) => Promise<LaneSummary>;
attach: (args: AttachLaneArgs) => Promise<LaneSummary>;
listUnregisteredWorktrees: () => Promise<UnregisteredLaneCandidate[]>;
adoptAttached: (args: AdoptAttachedLaneArgs) => Promise<LaneSummary>;
rename: (args: RenameLaneArgs) => Promise<void>;
reparent: (args: ReparentLaneArgs) => Promise<ReparentLaneResult>;
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ApplyConflictProposalArgs,
AttachLaneArgs,
AdoptAttachedLaneArgs,
UnregisteredLaneCandidate,
AppInfo,
AutoUpdateSnapshot,
ClearLocalAdeDataArgs,
Expand Down Expand Up @@ -972,6 +973,8 @@ contextBridge.exposeInMainWorld("ade", {
ipcRenderer.invoke(IPC.lanesCreateFromUnstaged, args),
importBranch: async (args: ImportBranchLaneArgs): Promise<LaneSummary> => ipcRenderer.invoke(IPC.lanesImportBranch, args),
attach: async (args: AttachLaneArgs): Promise<LaneSummary> => ipcRenderer.invoke(IPC.lanesAttach, args),
listUnregisteredWorktrees: async (): Promise<UnregisteredLaneCandidate[]> =>
ipcRenderer.invoke(IPC.lanesListUnregisteredWorktrees),
adoptAttached: async (args: AdoptAttachedLaneArgs): Promise<LaneSummary> => ipcRenderer.invoke(IPC.lanesAdoptAttached, args),
rename: async (args: RenameLaneArgs): Promise<void> => ipcRenderer.invoke(IPC.lanesRename, args),
reparent: async (args: ReparentLaneArgs): Promise<ReparentLaneResult> => ipcRenderer.invoke(IPC.lanesReparent, args),
Expand Down
29 changes: 22 additions & 7 deletions apps/desktop/src/renderer/components/lanes/LanesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { LaneDiffPane } from "./LaneDiffPane";
import { LaneWorkPane } from "./LaneWorkPane";
import { CreateLaneDialog, type CreateLaneMode } from "./CreateLaneDialog";
import { AttachLaneDialog } from "./AttachLaneDialog";
import { MultiAttachWorktreeDialog } from "./MultiAttachWorktreeDialog";
import { ManageLaneDialog } from "./ManageLaneDialog";
import { LaneContextMenu } from "./LaneContextMenu";
import { LaneRebaseBanner } from "./LaneRebaseBanner";
Expand Down Expand Up @@ -140,6 +141,7 @@ export function LanesPage() {
const createBaseBranchUserPickedRef = useRef(false);
const [templates, setTemplates] = useState<LaneTemplate[]>([]);
const [selectedTemplateId, setSelectedTemplateId] = useState("");
const [multiAttachOpen, setMultiAttachOpen] = useState(false);
const [attachOpen, setAttachOpen] = useState(false);
const [attachName, setAttachName] = useState("");
const [attachPath, setAttachPath] = useState("");
Expand Down Expand Up @@ -1524,19 +1526,15 @@ export function LanesPage() {
className="flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-sm text-muted-fg transition-colors hover:bg-white/[0.04] hover:text-fg"
onClick={() => {
setAddLaneDropdownOpen(false);
setAttachName("");
setAttachPath("");
setAttachBusy(false);
setAttachError(null);
setAttachOpen(true);
setMultiAttachOpen(true);
}}
>
<span className="inline-flex h-8 w-8 items-center justify-center rounded-lg border border-white/[0.06] bg-white/[0.03] text-info">
<Link size={14} />
</span>
<span>
<span className="block font-medium">Add existing worktree as lane</span>
<span className="block text-xs text-muted-fg/70">Track a worktree that already exists on disk.</span>
<span className="block font-medium">Add existing worktrees as lanes</span>
<span className="block text-xs text-muted-fg/70">Select from worktrees that already exist on disk.</span>
</span>
</button>
</div>
Expand Down Expand Up @@ -2034,6 +2032,23 @@ export function LanesPage() {
onSubmit={handleAttachSubmit}
/>

<MultiAttachWorktreeDialog
open={multiAttachOpen}
onOpenChange={setMultiAttachOpen}
onFallbackToManual={() => {
setMultiAttachOpen(false);
setAttachName("");
setAttachPath("");
setAttachDescription("");
setAttachBusy(false);
setAttachError(null);
setAttachOpen(true);
}}
onComplete={() => {
refreshLanes();
}}
/>

{adoptConfirmOpen ? (
<div className="fixed inset-0 z-[120] flex items-center justify-center p-4" style={{ background: "rgba(0,0,0,0.55)" }}>
<div style={{ width: "min(620px, 100%)", background: COLORS.cardBgSolid, backdropFilter: "blur(20px)", WebkitBackdropFilter: "blur(20px)", border: `1px solid ${COLORS.outlineBorder}`, borderRadius: 16, padding: 20 }}>
Expand Down
Loading
Loading