Skip to content

Commit 7cb21db

Browse files
adambuchweitzclaude
andcommitted
fix(server): ignore local-path git remotes in repository identity
GitButler adds a gb-local remote pointing at '.', which became the canonical key for every repo without origin/upstream. Unrelated projects then shared one identity and were merged into one sidebar group under the wrong title. Local-path and file:// remotes are now skipped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 611132c commit 7cb21db

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
@@ -250,6 +250,33 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
250250
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
251251
);
252252

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

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

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

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

0 commit comments

Comments
 (0)