iterate.com / git

git clone https://git.iterate.com/repos/git

A Branches tab

The branches that could be proposed were a section of the pulls page.
They have a page of their own now, /repos/<name>/branches, and a tab:
main first, then every other branch with the pull that it is, or the
page that compares it with main. The pulls page lists pulls alone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Misha Kaletsky, 2026-11-24 22:43 UTC · e5677190cbf2b15aaf5f312b6786d0cef89e9aec · parent d76ec5f

4 files changed

M app.ts
@@ -6,8 +6,9 @@
 //   GET  /repos/<name>/tree/main/<path>      a folder of it, or a file
 //   GET  /repos/<name>/commits               its newest commits
 //   GET  /repos/<name>/commit/<oid>          one commit: what it changed
-//   GET  /repos/<name>/pulls                 its pulls, and the branches that have none
+//   GET  /repos/<name>/branches              its branches, each with its pull or a compare link
 //   GET  /repos/<name>/compare/<branch>      a branch against main, and the box that opens a pull
+//   GET  /repos/<name>/pulls                 its pulls
 //   GET  /repos/<name>/pull/<number>         one pull: its conversation and what it changes
 //
 //   GET  /repos/<name>/info/refs?service=git-upload-pack | git-receive-pack
@@ -39,6 +40,7 @@
 import { openFile } from "../stdlib/open-files.ts";
 import theme from "../stdlib/theme.css";
 import {
+  branchesPage,
   codePage,
   commitPage,
   commitsPage,
@@ -132,6 +134,7 @@
         const handle = itx.repos.get(repo);
         if (match[2] === "commits") return await commitsPage(view, handle);
         if (match[2] === "commit") return await commitPage(view, handle, itx, rest);
+        if (match[2] === "branches") return await branchesPage(view, handle, itx);
         if (match[2] === "pulls") return await pullsPage(view, handle, itx);
         if (match[2] === "pull") return await pullPage(view, handle, itx, rest);
         if (match[2] === "compare") return await comparePage(view, handle, itx, rest);
M pages.ts
@@ -28,7 +28,7 @@
 
 /** A repo's pages: its name, then what of it. */
 export const PAGE_PATH =
-  /^\/repos\/([A-Za-z0-9._-]+)(?:\/(tree|commits|commit|pulls|pull|compare)(?:\/(.*))?)?$/;
+  /^\/repos\/([A-Za-z0-9._-]+)(?:\/(tree|commits|commit|branches|pulls|pull|compare)(?:\/(.*))?)?$/;
 
 /** How many commits the list shows, and how far back a short oid is looked for. */
 const COMMITS_SHOWN = 100;
@@ -266,8 +266,7 @@
 
 // ── PULLS ──
 
-/** The repo's pulls: the open ones, then the branches that could be proposed, then the pulls
- *  that are merged or closed. */
+/** The repo's pulls: the open ones, then the ones that are merged or closed. */
 export async function pullsPage(view: View, handle: Repo, itx: Itx) {
   const { repo } = view;
   const pulls = (await pullsIn(itx, repo)).toReversed();
@@ -279,28 +278,49 @@
   };
   const open = pulls.filter((pull) => pull.status === "open");
   const done = pulls.filter((pull) => pull.status !== "open");
-  // A branch is offered for a pull unless its newest pull is open, or merged: a squashed branch
-  // is done, and what it had is on main under another commit.
-  const newest = new Map(pulls.toReversed().map((pull) => [pull.branch, pull.status]));
-  const loose = (await handle.branches()).filter(
-    ({ name }) => name !== "main" && (!newest.has(name) || newest.get(name) === "closed"),
-  );
-  const looseRows = loose.map(
-    ({ name }) =>
-      `<li><a href="${compareHref(repo, name)}"><code>${esc(name)}</code></a> <span class="by">no pull yet: compare it with main</span></li>`,
-  );
   const main = [
     `<h1>Pulls</h1>`,
     open.length ? `<ul class="pulls">${open.map(row).join("")}</ul>` : note("No pull is open."),
-    loose.length ? `<h2>Branches</h2><ul class="pulls">${looseRows.join("")}</ul>` : "",
     done.length
       ? `<details class="done"><summary>Merged and closed (${done.length})</summary><ul class="pulls">${done.map(row).join("")}</ul></details>`
       : "",
-    `<p class="note">To propose a change: push a branch, then open <code>${esc(view.url.origin + repo)}/compare/&lt;branch&gt;</code>.</p>`,
+    `<p class="note">To propose a change: push a branch, then open it from <a href="${esc(repo)}/branches">Branches</a>.</p>`,
   ].join("");
   return page(view, 200, "pulls", `Pulls · ${nameOf(repo)}`, main, {});
 }
 
+/** The repo's branches, main first. Main is what the mind runs. Any other is somebody's
+ *  proposal: its row has the pull that it is, or the page that compares it with main. */
+export async function branchesPage(view: View, handle: Repo, itx: Itx) {
+  const { repo } = view;
+  const branches = await handle.branches();
+  // the newest pull of each branch: a later one of the same branch takes the earlier one's place
+  const pullOf = new Map((await pullsIn(itx, repo)).map((pull) => [pull.branch, pull]));
+  const row = ({ name, commitOid }: { name: string; commitOid: string }) => {
+    const pull = pullOf.get(name);
+    const tip = `<a href="${esc(repo)}/commit/${commitOid}"><code>${commitOid.slice(0, 7)}</code></a>`;
+    // A closed pull leaves its branch free to be proposed again. A merged one does not: what
+    // the branch had is on main, under another commit.
+    const what =
+      name === "main"
+        ? "what the mind runs"
+        : pull && pull.status !== "closed"
+          ? `${pull.status} as <a href="${esc(repo)}/pull/${pull.number}">#${pull.number} ${esc(pull.title)}</a>`
+          : `<a href="${compareHref(repo, name)}">compare with main</a>`;
+    return `<li><code>${esc(name)}</code> <span class="by">at ${tip}, ${what}</span></li>`;
+  };
+  const rows = [
+    ...branches.filter(({ name }) => name === "main"),
+    ...branches.filter(({ name }) => name !== "main"),
+  ].map(row);
+  const main = [
+    `<h1>Branches</h1>`,
+    rows.length ? `<ul class="branches">${rows.join("")}</ul>` : note("No branch yet."),
+    `<p class="note">A push to main is what the mind runs a few seconds later. A push to any other branch changes nothing that runs.</p>`,
+  ].join("");
+  return page(view, 200, "branches", `Branches · ${nameOf(repo)}`, main, {});
+}
+
 /** A branch against main, before it is a pull: its commits and what it changes, and for a member
  *  the box that opens the pull. A branch that has an open pull goes to the pull's page. */
 export async function comparePage(view: View, handle: Repo, itx: Itx, rest: string) {
@@ -319,7 +339,7 @@
         ? `${branch} has nothing that main has not.`
         : null;
   if (missing || !stand.head)
-    return page(view, stand.head ? 200 : 404, "pulls", "Compare", note(missing || ""), {});
+    return page(view, stand.head ? 200 : 404, "branches", "Compare", note(missing || ""), {});
   const changes = await keptChanges(view, handle, itx, stand.base, stand.head);
   // the branch's first commit names the pull, as a start
   const [subject, ...body] = stand.own.at(-1)!.message.trim().split("\n");
@@ -337,7 +357,7 @@
     compare: { branch, title: subject || branch, body: body.join("\n").trim() },
     diffs: diffsOf(changes),
   };
-  return page(view, 200, "pulls", `${branch} · ${nameOf(repo)}`, main, data);
+  return page(view, 200, "branches", `${branch} · ${nameOf(repo)}`, main, data);
 }
 
 /** One pull: what it asks, its conversation, its commits and what it changes, with the comments
@@ -522,7 +542,7 @@
 export function page(
   view: { url: URL; repo: string | null; isPublic: boolean; me: string | null },
   status: number,
-  tab: "code" | "commits" | "pulls" | null,
+  tab: "code" | "commits" | "branches" | "pulls" | null,
   title: string,
   main: string,
   data: Record<string, unknown>,
@@ -536,6 +556,7 @@
         view.isPublic ? "" : ` <span class="tag">private</span>`,
         `</p><nav><a href="${esc(repo)}"${current("code")}>Code</a>`,
         `<a href="${esc(repo)}/commits"${current("commits")}>Commits</a>`,
+        `<a href="${esc(repo)}/branches"${current("branches")}>Branches</a>`,
         `<a href="${esc(repo)}/pulls"${current("pulls")}>Pulls</a></nav>`,
         `<code class="clone">git clone ${esc(url.origin + repo)}</code>`,
       ].join("")
M public/page.css
@@ -65,7 +65,7 @@
 /* ── pulls ── */
 h2 { margin: 1.5rem 0 0.5rem; font-size: 0.9375rem; font-weight: 600; }
 main > h2, main > details { margin-left: 1rem; margin-right: 1rem; }
-.pulls li { padding: 0.25rem 0; }
+.pulls li, .branches li { padding: 0.25rem 0; }
 .done { margin-top: 1.25rem; }
 .done summary { cursor: pointer; color: var(--muted-foreground); }
 .pull { margin: 1rem 1rem 3rem; }
M tests/pulls.test.mjs
@@ -142,8 +142,10 @@
     ["#diff-1", "note.txt"],
   ]);
   assert.equal(dataOf(merged).mergeable, false);
-  // the branch is done: the list of pulls no longer offers it for a pull
-  assert.ok(!(await read("/repos/site/pulls")).includes("/repos/site/compare/red-header"));
+  // the branch is done: the branches page names the pull it became, and offers no compare
+  const branches = await read("/repos/site/branches");
+  assert.ok(branches.includes(`merged as <a href="/repos/site/pull/1">#1 Make the header red</a>`));
+  assert.ok(!branches.includes("/repos/site/compare/red-header"));
   // and it is merged once: a second try is refused in words
   await assert.rejects(mergePull(mind.getItx(), repo, 1), /#1 is merged already/);
 });
@@ -270,37 +272,48 @@
   assert.deepEqual(baseOf(main, [commit("x1")]), { base: null, own: [commit("x1")], upToDate: false });
 });
 
-test("the pulls page lists the open pulls, the branches that have none, and the pulls that are done; a branch with an open pull goes to its pull", async () => {
+test("the pulls page lists the open pulls and then the ones that are done; the branches page lists every branch, with its pull or the page that compares it with main", async () => {
   using site = repoWith([
     { message: "Start", files: { "a.txt": "a\n" } },
     { on: "one", message: "One", files: { "one.txt": "1\n" } },
     { on: "two", message: "Two", files: { "two.txt": "2\n" } },
     { on: "three", message: "Three", files: { "three.txt": "3\n" } },
   ]);
+  const [start, one, two, three] = site.commits;
   const repo = "/repos/site";
   const mind = localMind({ folders: { [repo]: site.folder }, member: null });
   const git = gitApp({ public: [repo], ...look });
+  // anyone reads a public repo's pulls and branches
+  const read = (path) => git.fetch(new Request(`https://git.example.com${path}`), mind);
   const ada = mind.as("ada@example.com").cd(repo);
   await ada.append({ type: "pull/opened", payload: { branch: "one", title: "The first", body: "" } });
   await ada.append({ type: "pull/opened", payload: { branch: "two", title: "The second", body: "" } });
   await ada.append({ type: "pull/commented", payload: { pull: 2, body: "Hm.", replyTo: null, at: null } });
   await ada.append({ type: "pull/closed", payload: { pull: 1 } });
 
-  // anyone reads a public repo's pulls
-  const answer = await git.fetch(new Request("https://git.example.com/repos/site/pulls"), mind);
-  const html = await answer.text();
-  const [open, loose, done] = html.split(`<ul class="pulls">`).slice(1);
-
-  assert.equal(answer.status, 200);
+  const [open, done] = (await (await read("/repos/site/pulls")).text()).split(`<ul class="pulls">`).slice(1);
   assert.ok(open.startsWith(`<li><a href="/repos/site/pull/2">The second</a> <span class="by">#2, <code>two</code>, ada, 2026-11-24 12:02 UTC, 1 comment</span></li></ul>`));
-  // `one` is here too: its pull was closed, so the branch can be proposed again
+  assert.ok(done.startsWith(`<li><a href="/repos/site/pull/1">The first</a> <span class="by">#1, closed, <code>one</code>`));
+
+  const branches = await (await read("/repos/site/branches")).text();
   assert.deepEqual(
-    [...loose.split("</ul>")[0].matchAll(/href="([^"]*)"/g)].map(([, href]) => href),
-    ["/repos/site/compare/one", "/repos/site/compare/three"],
+    branches.split(`<ul class="branches">`)[1].split("</ul>")[0].split("</li>").filter(Boolean).map((row) => row.replace(/<[^>]+>/g, "")),
+    [
+      `main at ${start.slice(0, 7)}, what the mind runs`,
+      // its pull was closed, so the branch can be proposed again
+      `one at ${one.slice(0, 7)}, compare with main`,
+      `three at ${three.slice(0, 7)}, compare with main`,
+      `two at ${two.slice(0, 7)}, open as #2 The second`,
+    ],
   );
-  assert.ok(done.startsWith(`<li><a href="/repos/site/pull/1">The first</a> <span class="by">#1, closed, <code>one</code>`));
+  assert.deepEqual(linksIn(branches, "branches").filter(([href]) => !href.includes("/commit/")), [
+    ["/repos/site/compare/one", "compare with main"],
+    ["/repos/site/compare/three", "compare with main"],
+    ["/repos/site/pull/2", "#2 The second"],
+  ]);
 
-  const compared = await git.fetch(new Request("https://git.example.com/repos/site/compare/two"), mind);
+  // a branch that has an open pull goes to its pull
+  const compared = await read("/repos/site/compare/two");
   assert.equal(compared.status, 302);
   assert.equal(compared.headers.get("location"), "https://git.example.com/repos/site/pull/2");
 });