Skip to content

Commit 5ae9b6b

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 f193a68 commit 5ae9b6b

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
@@ -246,6 +246,33 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
246246
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
247247
);
248248

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

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

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

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

0 commit comments

Comments
 (0)