Skip to content

Commit 83d473c

Browse files
committed
fix(forgejo): publishing a repository with no commits no longer fails the fj login check
fj reads the current directory's git repository even when --host names the server, and errors on an unborn branch. Run the host-only whoami check and the fj discovery probe from the home directory instead of the project folder.
1 parent 5eebf77 commit 83d473c

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎packages/source-control-forgejo/src/server/ForgejoCli.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,12 @@ export const make = Effect.gen(function* () {
433433
const now = yield* Clock.currentTimeMillis;
434434
const cached = authenticated.get(login.url);
435435
if (token && cached?.token === token && now - cached.time < 30_000) return token;
436-
yield* execute({ command: "fj", cwd, args: ["--host", login.url, "whoami"] });
436+
// fj reads the cwd repository even with --host and fails on an unborn branch.
437+
yield* execute({
438+
command: "fj",
439+
cwd: yield* HostProcess.HomeDirectory,
440+
args: ["--host", login.url, "whoami"],
441+
});
437442
// fj owns OAuth renewal. Re-read the file after it has refreshed an expired token.
438443
const refreshed = (yield* readKeys(cwd)).hosts[login.name]?.token;
439444
if (!refreshed)

‎packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as HttpClientRequest from "effect/http/HttpClientRequest";
1212
import * as HttpClientResponse from "effect/http/HttpClientResponse";
1313
import { VcsProcessSpawnError } from "@t3tools/contracts";
1414
import { firstNonEmptyLine } from "@t3tools/source-control-core/server/discovery";
15+
import * as HostProcess from "@t3tools/shared/HostProcess";
1516
import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
1617

1718
import * as ForgejoCli from "./ForgejoCli.ts";
@@ -1295,6 +1296,7 @@ it.effect("routes mounted Forgejo repositories without repeating the mount in AP
12951296
it.effect("prefers fj for HTTP and ported SSH aliases on root servers", () => {
12961297
const commands: string[] = [];
12971298
const requests: string[] = [];
1299+
let repositoryCwd = "";
12981300
return Effect.gen(function* () {
12991301
const cli = yield* ForgejoCli.make;
13001302
for (const remoteUrl of [
@@ -1392,7 +1394,8 @@ it.effect("prefers fj for HTTP and ported SSH aliases on root servers", () => {
13921394
process: {
13931395
run: (input) => {
13941396
commands.push(input.command);
1395-
if (input.command === "git")
1397+
if (input.command === "git") {
1398+
repositoryCwd = input.cwd;
13961399
return Effect.succeed(
13971400
input.cwd === "/no-remotes"
13981401
? processOutput("", { exitCode: ChildProcessSpawner.ExitCode(2) })
@@ -1402,10 +1405,11 @@ it.effect("prefers fj for HTTP and ported SSH aliases on root servers", () => {
14021405
: "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)",
14031406
),
14041407
);
1408+
}
14051409
assert.strictEqual(input.command, "fj");
14061410
assert.deepStrictEqual(input.args, [
14071411
"--host",
1408-
input.cwd === "/no-remotes"
1412+
repositoryCwd === "/no-remotes"
14091413
? "https://forgejo.local:3000"
14101414
: "http://forgejo.local:3000",
14111415
"whoami",
@@ -1519,11 +1523,13 @@ it.effect("loads later fj review pages when the server caps pages below the requ
15191523
}
15201524
assert.strictEqual(input.command, "fj");
15211525
assert.deepStrictEqual(input.args, ["--host", "https://forgejo.test", "whoami"]);
1526+
assert.strictEqual(input.cwd, "/home/maria");
15221527
return Effect.succeed(processOutput(""));
15231528
},
15241529
},
15251530
}),
15261531
),
1532+
Effect.provideService(HostProcess.HomeDirectory, "/home/maria"),
15271533
);
15281534
});
15291535

@@ -1680,6 +1686,7 @@ it.effect(
16801686
processOutput("http://forgejo.local:3000/maria/project.git\n"),
16811687
);
16821688
if (input.command === "fj") {
1689+
assert.strictEqual(input.cwd, "/home/maria");
16831690
if (scenario === "missing")
16841691
return Effect.fail(
16851692
new VcsProcessSpawnError({
@@ -1727,6 +1734,7 @@ it.effect(
17271734
}),
17281735
),
17291736
),
1737+
Effect.provideService(HostProcess.HomeDirectory, "/home/maria"),
17301738
);
17311739
}
17321740
}),

‎packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as FileSystem from "effect/FileSystem";
44
import * as Schema from "effect/Schema";
55
import * as Result from "effect/Result";
66
import { SourceControlProviderError } from "@t3tools/contracts";
7+
import * as HostProcess from "@t3tools/shared/HostProcess";
78
import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
89
import * as ForgejoCli from "./ForgejoCli.ts";
910
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
@@ -94,7 +95,8 @@ export const makeDiscovery = Effect.gen(function* () {
9495
logins.find((entry) => entry.default === "true") ||
9596
logins[0];
9697
const fj = yield* probeSourceControlProvider({
97-
cwd,
98+
// fj reads the cwd repository even with --host and fails on an unborn branch.
99+
cwd: yield* HostProcess.HomeDirectory,
98100
process,
99101
spec: {
100102
...discovery,

0 commit comments

Comments
 (0)