git.<domain>/ lists the repos that anyone may clone
Misha Kaletsky, 2026-11-24 18:36 UTC · 12510272f8096d7e423c58b54c26d4728ccecdba · parent 05cc9eb
2 files changed
M app.ts
@@ -7,6 +7,8 @@ // POST /repos/<name>/git-upload-pack clone, fetch // POST /repos/<name>/git-receive-pack push // +// GET / the repos that anyone may clone, as text +// // It adds two things. The address is the mind's own. And a repo that worker.ts lists as public is // read with no credential: the app adds a read token of its own, minted once and kept while it // lasts. Every other request needs the caller's own Artifacts token, as git's password (any @@ -56,6 +58,14 @@ host: Pick<IterateConfigEntrypoint, "getItx">, ): Promise<Response> { const url = new URL(request.url); + // The app's own address, in a browser: the repos that anyone may clone, each as a command. + if (url.pathname === "/") { + const lines = publicRepos.map((repo) => ` git clone ${url.origin}${repo}`); + return new Response( + ["The repos of this mind that anyone may clone:", "", ...lines, ""].join("\n"), + { headers: { "content-type": "text/plain; charset=utf-8" } }, + ); + } const match = GIT_PATH.exec(url.pathname); if (!match) return new Response("git: clone or push at /repos/<name>\n", { status: 404 }); // `/repos/<name>.git` is the same repo: a person may write the address either way
M tests/app.test.mjs
@@ -146,12 +146,35 @@ assert.deepEqual(mind.remotesAsked, ["/repos/kernel"]); }); +test("the app's own address lists the repos that anyone may clone, each as the command that clones it", async () => { + await using remote = await artifactsRemote(); + const mind = fakeMind(remote); + const git = gitApp({ public: ["/repos/kernel", "/repos/stdlib"] }); + + const index = await git.fetch(new Request("https://git.example.com/"), mind); + + assert.equal(index.status, 200); + assert.equal( + await index.text(), + [ + "The repos of this mind that anyone may clone:", + "", + " git clone https://git.example.com/repos/kernel", + " git clone https://git.example.com/repos/stdlib", + "", + ].join("\n"), + ); + // a list of names from the config: the mind is asked nothing + assert.deepEqual(remote.requests, []); + assert.deepEqual(mind.minted, []); +}); + test("what is no git request is refused before the mind is asked anything", async () => { await using remote = await artifactsRemote(); const mind = fakeMind(remote); const git = gitApp({ public: ["/repos/kernel"] }); - const page = await git.fetch(new Request("https://git.example.com/"), mind); + const page = await git.fetch(new Request("https://git.example.com/about"), mind); assert.equal(page.status, 404); // git's older "dumb" protocol asks for info/refs with no service const dumb = await git.fetch(