Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

Serve repositories from the root of the URL space

ed03b3d1fa16ef6b55e2773aaf10e3be13282c3a · Keenan Nemetz · 9h ago · parent d37d301f

Serve repositories from the root of the URL space

A repository is now /<name> and its Git transport /<name>.git, so the URL a
person opens, the URL a clone uses, and the Go module path are the same name.
The forge's own pages moved under /-/ (admin, accounts, the directory, the
feed, sign-in, assets), a prefix no repository name can start with: names are
[a-z0-9...] and cannot begin with "-". That leaves the router with two disjoint
spaces and removes the /r/ and /git/ prefixes, which existed only to keep
repositories away from the forge's own paths.

Routes: repoRoutes lose /r/; global, auth and admin routes gain /-/; assets
move to /-/static/ because a subtree pattern like /static/ cannot coexist with
one-segment-wildcard repo routes — Go's mux reports them as conflicting
neither-more-specific patterns. The catch-all still renders the styled 404.

Transport: githttp.Route parses /<name>.git/<rest> instead of a /git/ prefix,
and forgepaths.go hands such requests to the proxy before the mux, because a
wildcard fills a whole segment and cannot match "<name>.git". LFS stays on the
mux (<name>.git/info/lfs/...), and the Go module discovery probe moves to the
same pre-router so a package path under a public repository is answered even
when its first segments name a page tab.

Names: repo.ValidateName now refuses the four root paths the forge must keep —
static, robots.txt, sitemap.xml, sitemap-pages.xml. Everything else is an
ordinary repository name, including admin, u, and activity.

Docs and the packaged URLs follow the new layout; robots.txt, the sitemaps and
the instance activity feed point at the new paths. No aliases: the old /r/ and
/git/ URLs are gone.

Verified with ./vole workflow check and ./vole workflow run verify.

server/urllayout_test.go +102

@@ -0,0 +1,102 @@
1 package server_test
2
3 // A repository owns the root of the URL space: /<name> is its page and
4 // /<name>.git is its Git transport. The forge's own pages live under /-/, a
5 // prefix no repository name can start with, so the two never compete.
6
7 import (
8 "net/http"
9 "strings"
10 "testing"
11
12 "rodent.software/vole/forge/config"
13 )
14
15 func TestRepositoryOwnsTheRootOfTheURLSpace(t *testing.T) {
16 t.Parallel()
17 f := newFixture(t)
18 f.publish(f.repo)
19
20 code, body := f.get("/" + f.repo)
21 if code != http.StatusOK {
22 t.Fatalf("/%s = %d", f.repo, code)
23 }
24 if !strings.Contains(body, f.repo) || !strings.Contains(body, `class="repohead"`) {
25 t.Fatalf("/%s is not the repository page:\n%s", f.repo, body)
26 }
27
28 // The transport is the same name with .git, so the page a person opens and
29 // the URL a clone uses agree.
30 code, _ = f.get("/" + f.repo + ".git/info/refs?service=git-upload-pack")
31 if code != http.StatusOK {
32 t.Fatalf("/%s.git/info/refs = %d, want a clone advertisement", f.repo, code)
33 }
34 // A bare .git names no repository and is not a page either.
35 if code, _ := f.get("/" + f.repo + ".git"); code != http.StatusNotFound {
36 t.Fatalf("/%s.git = %d, want 404", f.repo, code)
37 }
38
39 // The forge's own pages answer under /-/.
40 if code, _ := f.get("/-/healthz"); code != http.StatusOK {
41 t.Fatalf("/-/healthz = %d", code)
42 }
43 if code, _ := f.get("/-/static/vole.css"); code != http.StatusOK {
44 t.Fatalf("/-/static/vole.css = %d", code)
45 }
46
47 // The paths this layout replaced are gone rather than aliased.
48 for _, path := range []string{
49 "/r/" + f.repo,
50 "/git/" + f.repo + ".git/info/refs?service=git-upload-pack",
51 "/static/vole.css",
52 "/u/" + f.ownerID,
53 "/login",
54 } {
55 if code, _ := f.get(path); code != http.StatusNotFound {
56 t.Fatalf("%s = %d, want 404", path, code)
57 }
58 }
59 }
60
61 // A repository named like a forge page is an ordinary repository: nothing has to
62 // avoid the forge's vocabulary, only the four root paths the forge keeps.
63 func TestRepositoryNameNeedNotAvoidTheForge(t *testing.T) {
64 t.Parallel()
65 f := newFixture(t)
66 m, err := f.srv.Repos.Create("admin", f.ownerID, "an ordinary repository")
67 if err != nil {
68 t.Fatal(err)
69 }
70 if err := f.srv.Index.Upsert(m); err != nil {
71 t.Fatal(err)
72 }
73 f.publish("admin")
74
75 code, body := f.get("/admin")
76 if code != http.StatusOK {
77 t.Fatalf("/admin = %d, want the repository page", code)
78 }
79 if !strings.Contains(body, "an ordinary repository") {
80 t.Fatalf("/admin is not the repository:\n%s", body)
81 }
82 // The forge's own surface is still its own URL.
83 if code, _ := f.get("/-/u/" + f.ownerID); code != http.StatusOK {
84 t.Fatalf("/-/u/%s = %d", f.ownerID, code)
85 }
86 }
87
88 // With the anonymous transport off, <name>.git is not a transport at all; the
89 // path falls through to the router and answers like any unknown URL.
90 func TestGitTransportIsAbsentWhenGitHTTPIsOff(t *testing.T) {
91 t.Parallel()
92 f := newFixtureWith(t, func(c *config.Config) { c.GitHTTP = false })
93 f.publish(f.repo)
94 for _, path := range []string{
95 "/" + f.repo + ".git/info/refs?service=git-upload-pack",
96 "/" + f.repo + ".git/git-upload-pack",
97 } {
98 if code, _ := f.get(path); code != http.StatusNotFound {
99 t.Fatalf("%s = %d, want 404", path, code)
100 }
101 }
102 }