Skip to content

Commit 93d110a

Browse files
only21milclaudecodexmaria-rcks
authored
fix(server): treat a repository's only non-origin remote as its primary remote (#22119)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent f3ccba8 commit 93d110a

2 files changed

Lines changed: 28 additions & 21 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,22 +314,24 @@ it.effect.each(["root", "nested", "worktree"] as const)(
314314
}).pipe(Effect.provide(layerTest)),
315315
);
316316

317-
it.effect("invalidates origin remote cache when a driver mutation adds origin", () =>
318-
Effect.gen(function* () {
319-
const driver = yield* GitVcsDriver.GitVcsDriver;
320-
const cwd = yield* makeTmpDir();
321-
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
322-
yield* initRepoWithCommit(cwd);
323-
yield* git(remote, ["init", "--bare"]);
317+
it.effect.each(["origin", "github"] as const)(
318+
"recognizes %s as the primary remote after a driver mutation",
319+
(remoteName) =>
320+
Effect.gen(function* () {
321+
const driver = yield* GitVcsDriver.GitVcsDriver;
322+
const cwd = yield* makeTmpDir();
323+
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
324+
yield* initRepoWithCommit(cwd);
325+
yield* git(remote, ["init", "--bare"]);
324326

325-
const before = yield* driver.statusDetailsLocal(cwd);
326-
assert.equal(before.hasOriginRemote, false);
327+
assert.equal((yield* driver.statusDetailsLocal(cwd)).hasOriginRemote, false);
328+
assert.equal((yield* driver.listRefs({ cwd })).hasPrimaryRemote, false);
327329

328-
yield* driver.ensureRemote({ cwd, preferredName: "origin", url: remote });
330+
yield* driver.ensureRemote({ cwd, preferredName: remoteName, url: remote });
329331

330-
const after = yield* driver.statusDetailsLocal(cwd);
331-
assert.equal(after.hasOriginRemote, true);
332-
}).pipe(Effect.provide(layerTest)),
332+
assert.equal((yield* driver.statusDetailsLocal(cwd)).hasOriginRemote, true);
333+
assert.equal((yield* driver.listRefs({ cwd })).hasPrimaryRemote, true);
334+
}).pipe(Effect.provide(layerTest)),
333335
);
334336

335337
it.effect.each([

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,18 +1551,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
15511551
}),
15521552
},
15531553
);
1554-
const originExistsCache = yield* Cache.makeWith(
1554+
const primaryRemoteExistsCache = yield* Cache.makeWith(
15551555
(gitCommonDir: string) =>
15561556
Effect.gen(function* () {
15571557
const path = yield* Path.Path;
15581558
const fetchCwd =
15591559
path.basename(gitCommonDir) === ".git" ? path.dirname(gitCommonDir) : gitCommonDir;
15601560
return yield* executeGit(
1561-
"GitVcsDriver.statusDetails.originExists",
1561+
"GitVcsDriver.statusDetails.primaryRemoteExists",
15621562
fetchCwd,
1563-
["--git-dir", gitCommonDir, "remote", "get-url", "origin"],
1563+
["--git-dir", gitCommonDir, "remote"],
15641564
{ allowNonZeroExit: true },
1565-
).pipe(Effect.map((result) => result.exitCode === 0));
1565+
).pipe(Effect.map((result) => result.exitCode === 0 && result.stdout.trim().length > 0));
15661566
}),
15671567
{
15681568
capacity: 2_048,
@@ -1582,7 +1582,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
15821582
: gitCommonDir;
15831583
const cacheKey = commonDir ?? normalizeRepositoryPathsCacheKey(cwd);
15841584
yield* Cache.invalidate(defaultBranchCache, cacheKey);
1585-
yield* Cache.invalidate(originExistsCache, cacheKey);
1585+
yield* Cache.invalidate(primaryRemoteExistsCache, cacheKey);
15861586
},
15871587
);
15881588

@@ -2196,8 +2196,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
21962196
? Cache.get(defaultBranchCache, statusCacheKey).pipe(Effect.orElseSucceed(() => null))
21972197
: resolveDefaultBranchName(cwd, "origin").pipe(Effect.orElseSucceed(() => null)),
21982198
statusCacheKey
2199-
? Cache.get(originExistsCache, statusCacheKey).pipe(Effect.orElseSucceed(() => false))
2200-
: originRemoteExists(cwd).pipe(Effect.orElseSucceed(() => false)),
2199+
? Cache.get(primaryRemoteExistsCache, statusCacheKey).pipe(
2200+
Effect.orElseSucceed(() => false),
2201+
)
2202+
: listRemoteNames(cwd).pipe(
2203+
Effect.map((remoteNames) => remoteNames.length > 0),
2204+
Effect.orElseSucceed(() => false),
2205+
),
22012206
],
22022207
{ concurrency: "unbounded" },
22032208
);
@@ -3939,7 +3944,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
39393944
return {
39403945
localBranches: localBranches.toSorted(byRecencyThenName).map(({ ref }) => ref),
39413946
remoteBranches: remoteBranches.toSorted(byRecencyThenName).map(({ ref }) => ref),
3942-
hasPrimaryRemote: remoteNames.includes("origin"),
3947+
hasPrimaryRemote: remoteNames.length > 0,
39433948
} satisfies GitRefsSnapshot;
39443949
});
39453950

0 commit comments

Comments
 (0)