2code icon indicating copy to clipboard operation
2code copied to clipboard

Delete Worktree from the right-click menu hangs on "Checking this worktree's Git status…"

Open cahva opened this issue 2 weeks ago • 0 comments

What happens

Right-click a worktree in the sidebar and choose Delete Worktree. The dialog shows "Checking this worktree's Git status…" forever and Delete stays disabled. Herdr app on Linux, 2code at 3be336e.

Cause

Menu.pick() calls deleteProfile(), which opens the dialog with openOverlay, and then closes the menu popup. The dialog's init runs inside that openOverlay call, so the git status it starts is counted as one of the popup's pending host calls. Herdr cancels a copy's pending calls when it closes, and the cancelled exec promise never settles. The check never finishes, so ready stays false.

Two things support this:

  • A trace in DeleteProfile.init showed a timer created there kept firing, while the first git() call never returned. The step stayed on status for as long as the dialog was open.
  • The same part opened as a tab (herdr-app do tab.new '{"mod":"2code","props":{"part":"deleteProfile",...}}') finished the check in about 80 ms and enabled Delete.

RemoveProject has the same pattern (repoOf() in init) and is opened from the same menu.

Fix

Start overlay parts from the overlay's own timer, so their calls belong to the overlay. In main.js:

if (p.overlay) {
  this.ready = false;
  cx.timer.after(0, (cx) => { this.part.init?.(p, cx); this.ready = true; cx.notify(); });
} else {
  this.ready = true;
  this.part.init?.(p, cx);
}

and if (!this.ready) return div(); at the top of render.

Related: sidebar stops refreshing when a space's folder is gone

If a terminal is still inside a worktree folder that gets removed, its cwd reads as /path (deleted). exec then throws "cannot run git: No such file or directory" from repoOf(). Sidebar.refresh() catches it with an empty catch {}, which skips the rest of the refresh. From then on no project's worktree list updates. The same throw also leaves DeleteProfile stuck on "Checking…", because its init task has no error handling.

Fix: make git() in lib/git.js return a failed result instead of throwing:

let r;
try { r = await exec("git", args, { cwd, on, ...(timeout ? { timeout } : {}) }); }
catch (e) { return { ok: false, out: "", err: String(e?.message ?? e) }; }

The sidebar's fallback then adds the (deleted) path as a new project. That part isn't fixed here.

cahva avatar Nov 18 '26 09:11 cahva