Skip to content
TypeScript

fix(forgejo): publishing a repository with no commits no longer fails the fj login check (#26770)

Igor Makowski26af67426b6a
diff --git a/packages/source-control-forgejo/src/server/ForgejoCli.ts b/packages/source-control-forgejo/src/server/ForgejoCli.ts
index 2df2a8ab5b4..a2cd718b9d4 100644
--- a/packages/source-control-forgejo/src/server/ForgejoCli.ts
+++ b/packages/source-control-forgejo/src/server/ForgejoCli.ts
@@ -433,7 +433,12 @@ export const make = Effect.gen(function* () {
const now = yield* Clock.currentTimeMillis;
const cached = authenticated.get(login.url);
if (token && cached?.token === token && now - cached.time < 30_000) return token;
- yield* execute({ command: "fj", cwd, args: ["--host", login.url, "whoami"] });
+ // fj reads the cwd repository even with --host and fails on an unborn branch.
+ yield* execute({
+ command: "fj",
+ cwd: yield* HostProcess.HomeDirectory,
+ args: ["--host", login.url, "whoami"],
+ });
// fj owns OAuth renewal. Re-read the file after it has refreshed an expired token.
const refreshed = (yield* readKeys(cwd)).hosts[login.name]?.token;
if (!refreshed)
diff --git a/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts b/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
index 37098ec5281..aa9f1abe295 100644
--- a/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+++ b/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
@@ -12,6 +12,7 @@ import * as HttpClientRequest from "effect/http/HttpClientRequest";
import * as HttpClientResponse from "effect/http/HttpClientResponse";
import { VcsProcessSpawnError } from "@t3tools/contracts";
import { firstNonEmptyLine } from "@t3tools/source-control-core/server/discovery";
+import * as HostProcess from "@t3tools/shared/HostProcess";
import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
import * as ForgejoCli from "./ForgejoCli.ts";
@@ -1295,6 +1296,7 @@ it.effect("routes mounted Forgejo repositories without repeating the mount in AP
it.effect("prefers fj for HTTP and ported SSH aliases on root servers", () => {
const commands: string[] = [];
const requests: string[] = [];
+ let repositoryCwd = "";
return Effect.gen(function* () {
const cli = yield* ForgejoCli.make;
for (const remoteUrl of [
@@ -1392,7 +1394,8 @@ it.effect("prefers fj for HTTP and ported SSH aliases on root servers", () => {
process: {
run: (input) => {
commands.push(input.command);
- if (input.command === "git")
+ if (input.command === "git") {
+ repositoryCwd = input.cwd;
return Effect.succeed(
input.cwd === "/no-remotes"
? processOutput("", { exitCode: ChildProcessSpawner.ExitCode(2) })
@@ -1402,10 +1405,11 @@ it.effect("prefers fj for HTTP and ported SSH aliases on root servers", () => {
: "origin\thttp://forgejo.local:3000/maria/project.git (fetch)\nother\thttp://forgejo.local:3000/maria/other.git (fetch)\nunrelated\thttp://other.local:3000/maria/project.git (fetch)",
),
);
+ }
assert.strictEqual(input.command, "fj");
assert.deepStrictEqual(input.args, [
"--host",
- input.cwd === "/no-remotes"
+ repositoryCwd === "/no-remotes"
? "https://forgejo.local:3000"
: "http://forgejo.local:3000",
"whoami",
@@ -1519,11 +1523,13 @@ it.effect("loads later fj review pages when the server caps pages below the requ
}
assert.strictEqual(input.command, "fj");
assert.deepStrictEqual(input.args, ["--host", "https://forgejo.test", "whoami"]);
+ assert.strictEqual(input.cwd, "/home/maria");
return Effect.succeed(processOutput(""));
},
},
}),
),
+ Effect.provideService(HostProcess.HomeDirectory, "/home/maria"),
);
});
@@ -1680,6 +1686,7 @@ it.effect(
processOutput("http://forgejo.local:3000/maria/project.git\n"),
);
if (input.command === "fj") {
+ assert.strictEqual(input.cwd, "/home/maria");
if (scenario === "missing")
return Effect.fail(
new VcsProcessSpawnError({
@@ -1727,6 +1734,7 @@ it.effect(
}),
),
),
+ Effect.provideService(HostProcess.HomeDirectory, "/home/maria"),
);
}
}),
diff --git a/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts b/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts
index 3557a5c92eb..155d9734bb9 100644
--- a/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts
+++ b/packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts
@@ -4,6 +4,7 @@ import * as FileSystem from "effect/FileSystem";
import * as Schema from "effect/Schema";
import * as Result from "effect/Result";
import { SourceControlProviderError } from "@t3tools/contracts";
+import * as HostProcess from "@t3tools/shared/HostProcess";
import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
import * as ForgejoCli from "./ForgejoCli.ts";
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
@@ -94,7 +95,8 @@ export const makeDiscovery = Effect.gen(function* () {
logins.find((entry) => entry.default === "true") ||
logins[0];
const fj = yield* probeSourceControlProvider({
- cwd,
+ // fj reads the cwd repository even with --host and fails on an unborn branch.
+ cwd: yield* HostProcess.HomeDirectory,
process,
spec: {
...discovery,