tenseleyflow/shithub / 6a4cb28

Browse files

Backfill relative GitHub submodules

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
6a4cb28f46b240e1d5cf4690603c3bbcff93cd19
Parents
42a4b83
Tree
6ee993c

3 changed files

StatusFile+-
M docs/internal/code-tab.md 11 11
M internal/web/handlers/repo/code_tree_rows_test.go 20 3
M internal/web/handlers/repo/submodule_links.go 13 5
docs/internal/code-tab.mdmodified
@@ -73,17 +73,17 @@ on the rendered ref, the Code tab parses it once, matches entries by
7373
 submodule path, and links GitHub or configured shithub clone remotes to
7474
 the local `/{owner}/{repo}/tree/{gitlink-oid}` route when the target
7575
 repo has that commit. If the target repo exists locally but does not
76
-have the pinned commit object, and `.gitmodules` points at GitHub, the
77
-handler performs a bounded, non-forced fetch of heads/tags from that
78
-GitHub remote, re-checks the object, and then links to the exact
79
-detached-commit tree when it arrived. Successful backfills update the
80
-target repo's default-branch OID when that ref moved, then enqueue the
81
-same code-index and size-recalc maintenance used after pushes. Diverged
82
-local refs are never force-updated; on fetch failure or still-missing
83
-objects, the row links to the target repo's default Code tab so
84
-independently-created mirrors don't produce dead links. Unknown,
85
-external, absent, or malformed remotes stay as plain `name @ shortsha`
86
-rows.
76
+have the pinned commit object, and `.gitmodules` points at GitHub or a
77
+relative sibling repo, the handler performs a bounded, non-forced fetch
78
+of heads/tags from the corresponding GitHub remote, re-checks the
79
+object, and then links to the exact detached-commit tree when it
80
+arrived. Successful backfills update the target repo's default-branch
81
+OID when that ref moved, then enqueue the same code-index and
82
+size-recalc maintenance used after pushes. Diverged local refs are
83
+never force-updated; on fetch failure or still-missing objects, the row
84
+links to the target repo's default Code tab so independently-created
85
+mirrors don't produce dead links. Unknown, external, absent, or
86
+malformed remotes stay as plain `name @ shortsha` rows.
8787
 
8888
 The S17 ship excludes the htmx-driven "last commit per entry" column
8989
 that the spec describes — an extra round-trip we can add later without
internal/web/handlers/repo/code_tree_rows_test.gomodified
@@ -127,6 +127,12 @@ func TestSubmoduleRouteURL_UnsupportedRemotesStayPlain(t *testing.T) {
127127
 
128128
 func TestGitHubSubmoduleFetchURL_CanonicalizesSupportedRemotes(t *testing.T) {
129129
 	t.Parallel()
130
+	cfg := submoduleRouteConfig{
131
+		owner:    "FortranGoingOnForty",
132
+		repoName: "lib-modules",
133
+		baseURL:  "https://shithub.sh",
134
+		sshHost:  "git@shithub.sh",
135
+	}
130136
 
131137
 	for _, tt := range []struct {
132138
 		name   string
@@ -148,11 +154,21 @@ func TestGitHubSubmoduleFetchURL_CanonicalizesSupportedRemotes(t *testing.T) {
148154
 			remote: "ssh://git@github.com/FortranGoingOnForty/afs-ld.git",
149155
 			want:   "https://github.com/FortranGoingOnForty/afs-ld.git",
150156
 		},
157
+		{
158
+			name:   "relative sibling without suffix",
159
+			remote: "../fgof-process",
160
+			want:   "https://github.com/FortranGoingOnForty/fgof-process.git",
161
+		},
162
+		{
163
+			name:   "relative sibling with suffix",
164
+			remote: "../fgof-fs.git",
165
+			want:   "https://github.com/FortranGoingOnForty/fgof-fs.git",
166
+		},
151167
 	} {
152168
 		tt := tt
153169
 		t.Run(tt.name, func(t *testing.T) {
154170
 			t.Parallel()
155
-			got, ok := githubSubmoduleFetchURL(tt.remote)
171
+			got, ok := githubSubmoduleFetchURL(cfg, tt.remote)
156172
 			if !ok {
157173
 				t.Fatalf("githubSubmoduleFetchURL(%q) ok = false", tt.remote)
158174
 			}
@@ -165,10 +181,11 @@ func TestGitHubSubmoduleFetchURL_CanonicalizesSupportedRemotes(t *testing.T) {
165181
 
166182
 func TestGitHubSubmoduleFetchURL_RejectsUnsupportedRemotes(t *testing.T) {
167183
 	t.Parallel()
184
+	cfg := submoduleRouteConfig{owner: "octo", repoName: "super", baseURL: "https://shithub.sh", sshHost: "git@shithub.sh"}
168185
 
169186
 	for _, remote := range []string{
170187
 		"https://shithub.sh/tenseleyFlow/bencch.git",
171
-		"../afs-ld.git",
188
+		"../../../afs-ld.git",
172189
 		"https://example.com/octo/lib.git",
173190
 		"https://github.com/octo/nested/lib.git",
174191
 		"https://github.com/%2F/lib.git",
@@ -178,7 +195,7 @@ func TestGitHubSubmoduleFetchURL_RejectsUnsupportedRemotes(t *testing.T) {
178195
 		remote := remote
179196
 		t.Run(remote, func(t *testing.T) {
180197
 			t.Parallel()
181
-			if got, ok := githubSubmoduleFetchURL(remote); ok || got != "" {
198
+			if got, ok := githubSubmoduleFetchURL(cfg, remote); ok || got != "" {
182199
 				t.Fatalf("githubSubmoduleFetchURL(%q) = %q, %v; want empty, false", remote, got, ok)
183200
 			}
184201
 		})