The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 19:45 UTC
fix(server): project identity follows gh repo set-default (#35005)
Julius Marminge committed
Nov 12, 2026 at 02:28 UTC
3126806749f82b60a2e5dfab7ed6ccbf390e324d
2 files changed
+53
-2
apps/server/src/project/RepositoryIdentityResolver.test.ts
+20
@@ -303,6 +303,26 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
303
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
304
);
305
306
+ it.effect("uses the fork as the identity when gh repo set-default points at it", () =>
307
+ Effect.gen(function* () {
308
+ const fileSystem = yield* FileSystem.FileSystem;
309
+ const cwd = yield* fileSystem.makeTempDirectoryScoped({
310
+ prefix: "t3-repository-identity-gh-default-test-",
311
+ });
312
+
313
+ yield* git(cwd, ["init"]);
314
+ yield* git(cwd, ["remote", "add", "origin", "git@github.com:julius/t3code-fork.git"]);
315
+ yield* git(cwd, ["remote", "add", "upstream", "git@github.com:T3Tools/t3code.git"]);
316
+ yield* git(cwd, ["config", "remote.origin.gh-resolved", "base"]);
317
+
318
+ const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
319
+ const identity = yield* resolver.resolve(cwd);
320
+
321
+ expect(identity?.canonicalKey).toBe("github.com/julius/t3code-fork");
322
+ expect(identity?.locator.remoteName).toBe("origin");
323
+ }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
324
+ );
325
+
326
it.effect("uses the last remote path segment as the repository name for nested groups", () =>
327
Effect.gen(function* () {
328
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/project/RepositoryIdentityResolver.ts
+33
-2
@@ -70,10 +70,21 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> {
70
return remotes;
71
}
72
73
+// `gh repo set-default` marks the chosen remote with `remote.<name>.gh-resolved base`.
74
+function parseGhDefaultRemoteName(stdout: string): string | null {
75
+ const marked = stdout
76
+ .split("\n")
77
+ .map((line) => /^remote\.(.+)\.gh-resolved\s+base$/.exec(line.trim())?.[1])
78
+ .filter((name): name is string => name !== undefined);
79
+ return marked.length === 1 ? marked[0]! : null;
80
+}
81
+
82
function pickPrimaryRemote(
83
remotes: ReadonlyMap<string, string>,
84
+ ghDefaultRemoteName: string | null,
85
): { readonly remoteName: string; readonly remoteUrl: string } | null {
76
- for (const preferredRemoteName of ["upstream", "origin"] as const) {
86
+ for (const preferredRemoteName of [ghDefaultRemoteName, "upstream", "origin"]) {
87
+ if (preferredRemoteName === null) continue;
88
const remoteUrl = remotes.get(preferredRemoteName);
89
if (remoteUrl) {
90
return { remoteName: preferredRemoteName, remoteUrl };
@@ -239,8 +250,28 @@ const resolveRepositoryIdentityFromCacheKey = Effect.fn(
250
return null;
251
}
252
253
+ const ghResolvedResult = yield* processRunner
254
+ .run({
255
+ command: "git",
256
+ args: [
257
+ "-C",
258
+ cacheKey.rootPath,
259
+ ...(cacheKey.isBare ? ["--git-dir=."] : []),
260
+ "config",
261
+ "--get-regexp",
262
+ "^remote\\..*\\.gh-resolved$",
263
+ ],
264
+ env: explicitBareRepositoryEnv(process.env, yield* HostProcess.Platform),
265
+ timeoutBehavior: "timedOutResult",
266
+ })
267
+ .pipe(Effect.option);
268
+ const ghDefaultRemoteName =
269
+ ghResolvedResult._tag === "Some" && ghResolvedResult.value.code === 0
270
+ ? parseGhDefaultRemoteName(ghResolvedResult.value.stdout)
271
+ : null;
272
+
273
const remotes = parseRemoteFetchUrls(remoteResult.value.stdout);
243
- const remote = pickPrimaryRemote(remotes);
274
+ const remote = pickPrimaryRemote(remotes, ghDefaultRemoteName);
275
return remote
276
? buildRepositoryIdentity({
277
...remote,