Skip to content
TypeScript

fix(server): stop grouping unrelated repos that only have a local git remote (#13129)

Adam Buchweitz19f3f6d9fbf9
diff --git a/apps/server/src/project/RepositoryIdentityResolver.test.ts b/apps/server/src/project/RepositoryIdentityResolver.test.ts
index 426eda6ec06..5f4e60f0130 100644
--- a/apps/server/src/project/RepositoryIdentityResolver.test.ts
+++ b/apps/server/src/project/RepositoryIdentityResolver.test.ts
@@ -251,6 +251,33 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
);
+ it.effect("ignores local-path remotes such as GitButler's gb-local", () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const localOnlyDir = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-repository-identity-local-remote-",
+ });
+ const mixedDir = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-repository-identity-mixed-remote-",
+ });
+
+ yield* git(localOnlyDir, ["init"]);
+ yield* git(localOnlyDir, ["remote", "add", "gb-local", "."]);
+ yield* git(localOnlyDir, ["remote", "add", "backup", "/srv/git/repo.git"]);
+ yield* git(localOnlyDir, ["remote", "add", "archive", "file:///srv/git/repo.git"]);
+ yield* git(mixedDir, ["init"]);
+ yield* git(mixedDir, ["remote", "add", "gb-local", "."]);
+ yield* git(mixedDir, ["remote", "add", "mirror", "[email protected]:T3Tools/t3code.git"]);
+
+ const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
+ expect(yield* resolver.resolve(localOnlyDir)).toBeNull();
+
+ const mixedIdentity = yield* resolver.resolve(mixedDir);
+ expect(mixedIdentity?.locator.remoteName).toBe("mirror");
+ expect(mixedIdentity?.canonicalKey).toBe("github.com/t3tools/t3code");
+ }).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
+ );
+
it.effect.each(["add", "replace"] as const)(
"refreshes the primary upstream after %s before cache expiry",
(change) =>
diff --git a/apps/server/src/project/RepositoryIdentityResolver.ts b/apps/server/src/project/RepositoryIdentityResolver.ts
index 2b7dc209771..80d5b39823a 100644
--- a/apps/server/src/project/RepositoryIdentityResolver.ts
+++ b/apps/server/src/project/RepositoryIdentityResolver.ts
@@ -41,6 +41,18 @@ export class RepositoryIdentityResolver extends Context.Service<
}
>()("t3/project/RepositoryIdentityResolver") {}
+// Local remotes (GitButler's `gb-local` is `.`) name a path on this machine,
+// not a repository, so unrelated repos would share one identity.
+function isLocalRemoteUrl(url: string): boolean {
+ if (/^file:/i.test(url)) return true;
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(url)) return false;
+ if (/^[a-z]:[\\/]/i.test(url)) return true;
+ // Git treats `host:path` as scp-style only when the colon precedes any slash.
+ const colonIndex = url.indexOf(":");
+ const slashIndex = url.search(/[\\/]/);
+ return colonIndex === -1 || (slashIndex !== -1 && slashIndex < colonIndex);
+}
+
function parseRemoteFetchUrls(stdout: string): Map<string, string> {
const remotes = new Map<string, string>();
for (const line of stdout.split("\n")) {
@@ -49,7 +61,12 @@ function parseRemoteFetchUrls(stdout: string): Map<string, string> {
const match = /^(\S+)\s+(\S+)\s+\((fetch|push)\)$/.exec(trimmed);
if (!match) continue;
const [, remoteName = "", remoteUrl = "", direction = ""] = match;
- if (direction !== "fetch" || remoteName.length === 0 || remoteUrl.length === 0) {
+ if (
+ direction !== "fetch" ||
+ remoteName.length === 0 ||
+ remoteUrl.length === 0 ||
+ isLocalRemoteUrl(remoteUrl)
+ ) {
continue;
}
remotes.set(remoteName, remoteUrl);