Skip to content

Commit 19f3f6d

Browse files
fix(server): stop grouping unrelated repos that only have a local git remote (pingdotgg#13129)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4d4297c commit 19f3f6d

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,33 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
251251
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
252252
);
253253

254+
it.effect("ignores local-path remotes such as GitButler's gb-local", () =>
255+
Effect.gen(function* () {
256+
const fileSystem = yield* FileSystem.FileSystem;
257+
const localOnlyDir = yield* fileSystem.makeTempDirectoryScoped({
258+
prefix: "t3-repository-identity-local-remote-",
259+
});
260+
const mixedDir = yield* fileSystem.makeTempDirectoryScoped({
261+
prefix: "t3-repository-identity-mixed-remote-",
262+
});
263+
264+
yield* git(localOnlyDir, ["init"]);
265+
yield* git(localOnlyDir, ["remote", "add", "gb-local", "."]);
266+
yield* git(localOnlyDir, ["remote", "add", "backup", "/srv/git/repo.git"]);
267+
yield* git(localOnlyDir, ["remote", "add", "archive", "file:///srv/git/repo.git"]);
268+
yield* git(mixedDir, ["init"]);
269+
yield* git(mixedDir, ["remote", "add", "gb-local", "."]);
270+
yield* git(mixedDir, ["remote", "add", "mirror", "[email protected]:T3Tools/t3code.git"]);
271+
272+
const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
273+
expect(yield* resolver.resolve(localOnlyDir)).toBeNull();
274+
275+
const mixedIdentity = yield* resolver.resolve(mixedDir);
276+
expect(mixedIdentity?.locator.remoteName).toBe("mirror");
277+
expect(mixedIdentity?.canonicalKey).toBe("github.com/t3tools/t3code");
278+
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
279+
);
280+
254281
it.effect.each(["add", "replace"] as const)(
255282
"refreshes the primary upstream after %s before cache expiry",
256283
(change) =>

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ export class RepositoryIdentityResolver extends Context.Service<
4141
}
4242
>()("t3/project/RepositoryIdentityResolver") {}
4343

44+
// Local remotes (GitButler's `gb-local` is `.`) name a path on this machine,
45+
// not a repository, so unrelated repos would share one identity.
46+
function isLocalRemoteUrl(url: string): boolean {
47+
if (/^file:/i.test(url)) return true;
48+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(url)) return false;
49+
if (/^[a-z]:[\\/]/i.test(url)) return true;
50+
// Git treats `host:path` as scp-style only when the colon precedes any slash.
51+
const colonIndex = url.indexOf(":");
52+
const slashIndex = url.search(/[\\/]/);
53+
return colonIndex === -1 || (slashIndex !== -1 && slashIndex < colonIndex);
54+
}
55+
4456
function parseRemoteFetchUrls(stdout: string): Map<string, string> {
4557
const remotes = new Map<string, string>();
4658
for (const line of stdout.split("\n")) {
@@ -49,7 +61,12 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> {
4961
const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)$/.exec(trimmed);
5062
if (!match) continue;
5163
const [, remoteName = "", remoteUrl = "", direction = ""] = match;
52-
if (direction !== "fetch" || remoteName.length === 0 || remoteUrl.length === 0) {
64+
if (
65+
direction !== "fetch" ||
66+
remoteName.length === 0 ||
67+
remoteUrl.length === 0 ||
68+
isLocalRemoteUrl(remoteUrl)
69+
) {
5370
continue;
5471
}
5572
remotes.set(remoteName, remoteUrl);

0 commit comments

Comments
 (0)