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
Binary file modified docs/design/mission/BranchModal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/design/mission/ContextMenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/design/mission/History.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/design/mission/Main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions docs/design/mission/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,10 @@ pre-ratification drawing:
iconography. An unpatched font shows fallback boxes there; accepted.
- The undo strip is one line ("Committed <when> · <summary>" clipped to the
sidebar, Undo chip right) instead of the boards' two-line strip.
- The main keybar lists the built action set (adds "enter diff" and
"u undo", names the adaptive segment key "f action", omits "? help").
- The main keybar lists the built action set (adds "enter diff",
"u undo", "S stash", and "h show stash", names the adaptive segment key
"f action", omits "? help"). The stash keys sit last, so a narrow
terminal clips them first.
Both tabs also add "⌃k menu" right after the tab-switch key, so it
survives a narrow terminal.
- The stash view is a third keybar mode, replacing the Changes keybar
Expand Down
Binary file modified docs/design/mission/Stash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/design/mission/WorktreeModal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions docs/design/mission/mission.pen
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"content": "Current Branch"
},
"kkLYY": {
"content": "rt-191-mission-tui"
"content": "mission-tui"
}
}
},
Expand Down Expand Up @@ -981,7 +981,7 @@
"id": "R3t4OL",
"name": "CommitLabel",
"fill": "#161224",
"content": "Commit 4 files to rt-191-mission-tui",
"content": "Commit 4 files to mission-tui",
"fontFamily": "$mono",
"fontSize": 12,
"fontWeight": "bold"
Expand Down Expand Up @@ -4297,7 +4297,7 @@
"id": "MU6ao",
"name": "V",
"fill": "$text",
"content": "rt-191-mission-tui",
"content": "mission-tui",
"fontFamily": "$mono",
"fontSize": 11,
"fontWeight": "bold"
Expand Down Expand Up @@ -4480,7 +4480,7 @@
{
"type": "frame",
"id": "RFwI4",
"name": "BR rt-191-mission-tui",
"name": "BR mission-tui",
"width": "fill_container",
"height": 24,
"gap": 8,
Expand Down Expand Up @@ -4517,7 +4517,7 @@
"fill": "$text-soft",
"textGrowth": "fixed-width",
"width": "fill_container",
"content": "rt-191-mission-tui",
"content": "mission-tui",
"fontFamily": "$mono",
"fontSize": 12,
"fontWeight": "normal"
Expand Down Expand Up @@ -4769,7 +4769,7 @@
"id": "jfp8z",
"name": "T",
"fill": "$lav",
"content": "New branch from rt-191-mission-tui…",
"content": "New branch from mission-tui…",
"fontFamily": "$mono",
"fontSize": 12,
"fontWeight": "bold"
Expand Down Expand Up @@ -5081,7 +5081,7 @@
"fill": "$dimmer",
"textGrowth": "fixed-width",
"width": "fill_container",
"content": "rt-191-mission-tui",
"content": "mission-tui",
"fontFamily": "$mono",
"fontSize": 11,
"fontWeight": "normal"
Expand Down Expand Up @@ -6048,7 +6048,7 @@
"content": "Current Branch"
},
"kkLYY": {
"content": "rt-191-mission-tui"
"content": "mission-tui"
}
}
},
Expand Down Expand Up @@ -9821,7 +9821,7 @@
"content": "Current Branch"
},
"kkLYY": {
"content": "rt-191-mission-tui"
"content": "mission-tui"
}
}
},
Expand Down Expand Up @@ -10653,7 +10653,7 @@
"id": "XgbQl",
"name": "CommitLabel",
"fill": "#161224",
"content": "Commit 4 files to rt-191-mission-tui",
"content": "Commit 4 files to mission-tui",
"fontFamily": "$mono",
"fontSize": 12,
"fontWeight": "bold"
Expand Down Expand Up @@ -16171,7 +16171,7 @@
"content": "Current Branch"
},
"kkLYY": {
"content": "rt-191-mission-tui"
"content": "mission-tui"
}
}
},
Expand Down Expand Up @@ -16765,7 +16765,7 @@
"id": "dKkp2",
"name": "CommitLabel",
"fill": "#161224",
"content": "Commit 2 files to rt-191-mission-tui",
"content": "Commit 2 files to mission-tui",
"fontFamily": "$mono",
"fontSize": 12,
"fontWeight": "bold"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestNamingEnterEmitsTypedName(t *testing.T) {
intent string
want string
}{
{"branch", "b", "mission:checkout", `{"new":true,"from":"rt-191-mission-tui","name":"my-feature"}`},
{"branch", "b", "mission:checkout", `{"new":true,"from":"mission-tui","name":"my-feature"}`},
{"worktree", "w", "mission:worktree", `{"new":true,"name":"my-feature"}`},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
46 changes: 45 additions & 1 deletion lib/daemon/__tests__/git-status-sweep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { openStateDb } from "../../state/db.ts";
import { createGitBadges } from "../git-badges-store.ts";
import { createGitStatusSweep, toBadge } from "../git-status-sweep.ts";
import { toBadge } from "../../git-badge.ts";
import { createGitStatusSweep } from "../git-status-sweep.ts";
import { makeSandbox } from "../../../packages/git-core/test-support/sandbox.ts";
import { createGitClient } from "../../../packages/git-core/src/index.ts";

Expand Down Expand Up @@ -161,6 +162,7 @@ describe("git status sweep", () => {
dir: "/whatever",
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => [{ name: "origin" }],
}) as any,
});
await sweep.sweepNow();
Expand All @@ -174,6 +176,7 @@ describe("git status sweep", () => {
const fakeClient = (dir: string) => ({
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => [{ name: "origin" }],
fetch: async (_remote: string | undefined, signal: AbortSignal) => {
expect(signal).toBeInstanceOf(AbortSignal);
fetched.push(dir);
Expand All @@ -198,6 +201,7 @@ describe("git status sweep", () => {
const fakeClient = (dir: string) => ({
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => [{ name: "origin" }],
fetch: async () => { fetched.push(dir); },
}) as any;
const sweep = sweepWith({
Expand All @@ -221,6 +225,7 @@ describe("git status sweep", () => {
const fakeClient = (dir: string) => ({
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => [{ name: "origin" }],
// A client whose fetch does not honor the abort signal at all: the
// in-flight guard can only clear once this promise itself settles,
// and it never does.
Expand Down Expand Up @@ -249,6 +254,7 @@ describe("git status sweep", () => {
const fakeClient = (dir: string) => ({
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => [{ name: "origin" }],
// Mirrors rawGit: an aborted signal rejects the fetch promptly, which
// is what lets fetchesInFlight clear before the next pass runs.
fetch: (_remote: string | undefined, signal: AbortSignal) => {
Expand All @@ -272,13 +278,51 @@ describe("git status sweep", () => {
}
});

test("a repo with no origin remote is never fetched", async () => {
const fetched: string[] = [];
const sweep = sweepWith({
repoIndex: () => ({ r: "/main" }),
readConfig: () => ({ sweep: true, sweepIntervalSec: 300, fetchIntervalSec: 900 }),
makeClient: ((dir: string) => ({
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => [{ name: "upstream" }],
fetch: async () => { fetched.push(dir); },
})) as any,
listWorktrees: async () => [{ path: "/main", branch: "main", headSha: null, isBare: false }],
});
const { changed } = await sweep.sweepNow();
expect(fetched).toEqual([]);
expect(changed).toEqual(["r"]);
});

test("a remotes lookup that fails skips the fetch and still snapshots", async () => {
const fetched: string[] = [];
const sweep = sweepWith({
repoIndex: () => ({ r: "/main" }),
readConfig: () => ({ sweep: true, sweepIntervalSec: 300, fetchIntervalSec: 900 }),
makeClient: ((dir: string) => ({
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => { throw new Error("git remote failed"); },
fetch: async () => { fetched.push(dir); },
})) as any,
listWorktrees: async () => [{ path: "/main", branch: "main", headSha: null, isBare: false }],
});
const { changed } = await sweep.sweepNow();
expect(fetched).toEqual([]);
expect(changed).toEqual(["r"]);
expect(sweep.errors().get("r")).toBeUndefined();
});

test("a fetch failure does not stop the snapshot", async () => {
const sweep = sweepWith({
repoIndex: () => ({ r: "/main" }),
readConfig: () => ({ sweep: true, sweepIntervalSec: 300, fetchIntervalSec: 900 }),
makeClient: ((dir: string) => ({
snapshot: async () => ({ branch: "main", detached: false, upstream: null, ahead: null, behind: null, files: [], clean: true }),
fetchState: async () => ({ lastFetchedAt: null }),
remotes: async () => [{ name: "origin" }],
fetch: async () => { throw new Error("network down"); },
})) as any,
listWorktrees: async () => [{ path: "/main", branch: "main", headSha: null, isBare: false }],
Expand Down
93 changes: 40 additions & 53 deletions lib/daemon/git-status-sweep.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Logger } from "pino";
import type { GitWorktreeBadge } from "../../packages/rt-client/src/commands.ts";
import type { FetchState, RepoSnapshot } from "../../packages/git-core/src/index.ts";
import { createGitClient } from "../../packages/git-core/src/index.ts";
import { createGitClient, type GitClient } from "../../packages/git-core/src/index.ts";
import { toBadge } from "../git-badge.ts";
import { listWorktreesAsync } from "../worktree/git-async.ts";
import { parseIdentity } from "../settings/identity.ts";
import type { RepoIndex } from "../repo-index.ts";
Expand Down Expand Up @@ -37,30 +37,6 @@ export interface GitStatusSweep {
errors(): Map<string, string>;
}

export function toBadge(
worktree: string,
snap: RepoSnapshot,
fetch: FetchState,
updatedAt: string,
): GitWorktreeBadge {
const files = snap.files;
return {
worktree,
branch: snap.branch,
detached: snap.detached,
staged: files.filter((f) => f.staged).length,
unstaged: files.filter((f) => f.unstaged && f.kind !== "untracked").length,
untracked: files.filter((f) => f.kind === "untracked").length,
conflicted: files.filter((f) => f.kind === "conflicted").length,
clean: snap.clean,
ahead: snap.ahead,
behind: snap.behind,
upstream: snap.upstream,
lastFetchedAt: fetch.lastFetchedAt,
updatedAt,
};
}

export function createGitStatusSweep(deps: GitStatusSweepDeps): GitStatusSweep {
const listWorktrees = deps.listWorktrees ?? listWorktreesAsync;
const makeClient = deps.makeClient ?? createGitClient;
Expand Down Expand Up @@ -90,33 +66,7 @@ export function createGitStatusSweep(deps: GitStatusSweepDeps): GitStatusSweep {
) {
// Stamped before the attempt: a hanging remote must not re-hang every pass.
fetchTimes.set(repo, now().getTime());
fetchesInFlight.add(repo);
const controller = new AbortController();
const fetchPromise = makeClient(mainPath).fetch(undefined, controller.signal);
// Settle-driven cleanup: the abort below makes a timed-out fetch's
// own child process die promptly, so this now fires close behind it
// rather than whenever some unrelated future settlement occurs.
fetchPromise.then(
() => { fetchesInFlight.delete(repo); },
() => { fetchesInFlight.delete(repo); },
);
let raceTimer: ReturnType<typeof setTimeout> | undefined;
try {
await Promise.race([
fetchPromise,
new Promise((_resolve, reject) => {
raceTimer = setTimeout(() => {
controller.abort();
reject(new Error("fetch timed out"));
}, 60_000);
raceTimer.unref?.();
}),
]);
} catch (err) {
deps.log.warn({ err, repo }, "background fetch failed; snapshotting with stale remote refs");
} finally {
clearTimeout(raceTimer);
}
await fetchOrigin(repo, makeClient(mainPath));
}
const trees = await listWorktrees(mainPath);
if (trees === null) {
Expand Down Expand Up @@ -144,6 +94,43 @@ export function createGitStatusSweep(deps: GitStatusSweepDeps): GitStatusSweep {
return { changed };
}

/**
* fetch() targets origin, and git empties FETCH_HEAD before it connects:
* fetching a repo with no origin would fail once per fetch cadence and
* leave a fresh, empty FETCH_HEAD behind. A failed remotes lookup skips
* the fetch rather than the snapshot.
*/
async function fetchOrigin(repo: string, client: GitClient): Promise<void> {
const hasOrigin = await client.remotes().then((remotes) => remotes.some((r) => r.name === "origin"), () => false);
if (!hasOrigin) return;
fetchesInFlight.add(repo);
const controller = new AbortController();
const fetchPromise = client.fetch(undefined, controller.signal);
// Settle-driven cleanup: the abort below kills a timed-out fetch's
// child process, so the in-flight mark clears promptly after a timeout.
fetchPromise.then(
() => { fetchesInFlight.delete(repo); },
() => { fetchesInFlight.delete(repo); },
);
let raceTimer: ReturnType<typeof setTimeout> | undefined;
try {
await Promise.race([
fetchPromise,
new Promise((_resolve, reject) => {
raceTimer = setTimeout(() => {
controller.abort();
reject(new Error("fetch timed out"));
}, 60_000);
raceTimer.unref?.();
}),
]);
} catch (err) {
deps.log.warn({ err, repo }, "background fetch failed; snapshotting with stale remote refs");
} finally {
clearTimeout(raceTimer);
}
}

function sweepNow(opts?: SweepOptions): Promise<{ changed: string[] }> {
if (inFlight) return inFlight;
inFlight = pass(opts).finally(() => { inFlight = null; });
Expand Down
27 changes: 27 additions & 0 deletions lib/git-badge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { GitWorktreeBadge } from "../packages/rt-client/src/commands.ts";
import type { FetchState, RepoSnapshot } from "../packages/git-core/src/index.ts";

/** One worktree's badge from a local git read: the daemon's sweep and glitter's live current-worktree row share it. */
export function toBadge(
worktree: string,
snap: RepoSnapshot,
fetch: FetchState,
updatedAt: string,
): GitWorktreeBadge {
const files = snap.files;
return {
worktree,
branch: snap.branch,
detached: snap.detached,
staged: files.filter((f) => f.staged).length,
unstaged: files.filter((f) => f.unstaged && f.kind !== "untracked").length,
untracked: files.filter((f) => f.kind === "untracked").length,
conflicted: files.filter((f) => f.kind === "conflicted").length,
clean: snap.clean,
ahead: snap.ahead,
behind: snap.behind,
upstream: snap.upstream,
lastFetchedAt: fetch.lastFetchedAt,
updatedAt,
};
}
Loading
Loading