Skip to content

Commit b8c74f5

Browse files
fix(server): gh default remote lookup ignores an inherited GIT_DIR (pingdotgg#35764)
1 parent 8b9f8ca commit b8c74f5

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎apps/server/src/project/RepositoryIdentityResolver.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { expect, it } from "@effect/vitest";
55
import * as Effect from "effect/Effect";
66
import * as FileSystem from "effect/FileSystem";
77
import * as Path from "effect/Path";
8+
import { vi } from "vite-plus/test";
89

910
import * as ProcessRunner from "../processRunner.ts";
1011
import * as RepositoryIdentityResolver from "./RepositoryIdentityResolver.ts";
@@ -343,6 +344,35 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
343344
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
344345
);
345346

347+
it.effect("reads the project's gh default when the server inherited GIT_DIR", () =>
348+
Effect.gen(function* () {
349+
const fileSystem = yield* FileSystem.FileSystem;
350+
const path = yield* Path.Path;
351+
const cwd = yield* fileSystem.makeTempDirectoryScoped({
352+
prefix: "t3-repository-identity-gh-default-git-dir-",
353+
});
354+
const other = yield* fileSystem.makeTempDirectoryScoped({
355+
prefix: "t3-repository-identity-inherited-git-dir-",
356+
});
357+
358+
yield* git(cwd, ["init"]);
359+
yield* git(cwd, ["remote", "add", "origin", "[email protected]:julius/t3code-fork.git"]);
360+
yield* git(cwd, ["remote", "add", "upstream", "[email protected]:T3Tools/t3code.git"]);
361+
yield* git(cwd, ["config", "remote.origin.gh-resolved", "base"]);
362+
yield* git(other, ["init"]);
363+
yield* git(other, ["config", "remote.upstream.gh-resolved", "base"]);
364+
365+
vi.stubEnv("GIT_DIR", path.join(other, ".git"));
366+
yield* Effect.addFinalizer(() => Effect.sync(() => vi.unstubAllEnvs()));
367+
368+
const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
369+
const identity = yield* resolver.resolve(cwd);
370+
371+
expect(identity?.canonicalKey).toBe("github.com/julius/t3code-fork");
372+
expect(identity?.locator.remoteName).toBe("origin");
373+
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
374+
);
375+
346376
it.effect("uses the last remote path segment as the repository name for nested groups", () =>
347377
Effect.gen(function* () {
348378
const fileSystem = yield* FileSystem.FileSystem;

‎apps/server/src/project/RepositoryIdentityResolver.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,12 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
241241
cacheKey: RepositoryIdentityCacheKey,
242242
): Effect.fn.Return<RepositoryIdentity | null, never, ProcessRunner.ProcessRunner> {
243243
const processRunner = yield* ProcessRunner.ProcessRunner;
244+
const env = gitEnv(yield* HostProcess.Platform);
244245
const remoteResult = yield* processRunner
245246
.run({
246247
command: "git",
247248
args: ["-C", cacheKey.rootPath, ...(cacheKey.isBare ? ["--git-dir=."] : []), "remote", "-v"],
248-
env: gitEnv(yield* HostProcess.Platform),
249+
env,
249250
timeoutBehavior: "timedOutResult",
250251
})
251252
.pipe(Effect.option);
@@ -264,7 +265,7 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
264265
"--get-regexp",
265266
"^remote\\..*\\.gh-resolved$",
266267
],
267-
env: explicitBareRepositoryEnv(process.env, yield* HostProcess.Platform),
268+
env,
268269
timeoutBehavior: "timedOutResult",
269270
})
270271
.pipe(Effect.option);

0 commit comments

Comments
 (0)