Skip to content
TypeScript

fix(server): treat a repository's only non-origin remote as its primary remote (#22119)

Victor Vogel93d110abd111
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index 29d67323426..be0b8d6b7a3 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -314,22 +314,24 @@ it.effect.each(["root", "nested", "worktree"] as const)(
}).pipe(Effect.provide(layerTest)),
);
-it.effect("invalidates origin remote cache when a driver mutation adds origin", () =>
- Effect.gen(function* () {
- const driver = yield* GitVcsDriver.GitVcsDriver;
- const cwd = yield* makeTmpDir();
- const remote = yield* makeTmpDir("git-vcs-driver-remote-");
- yield* initRepoWithCommit(cwd);
- yield* git(remote, ["init", "--bare"]);
+it.effect.each(["origin", "github"] as const)(
+ "recognizes %s as the primary remote after a driver mutation",
+ (remoteName) =>
+ Effect.gen(function* () {
+ const driver = yield* GitVcsDriver.GitVcsDriver;
+ const cwd = yield* makeTmpDir();
+ const remote = yield* makeTmpDir("git-vcs-driver-remote-");
+ yield* initRepoWithCommit(cwd);
+ yield* git(remote, ["init", "--bare"]);
- const before = yield* driver.statusDetailsLocal(cwd);
- assert.equal(before.hasOriginRemote, false);
+ assert.equal((yield* driver.statusDetailsLocal(cwd)).hasOriginRemote, false);
+ assert.equal((yield* driver.listRefs({ cwd })).hasPrimaryRemote, false);
- yield* driver.ensureRemote({ cwd, preferredName: "origin", url: remote });
+ yield* driver.ensureRemote({ cwd, preferredName: remoteName, url: remote });
- const after = yield* driver.statusDetailsLocal(cwd);
- assert.equal(after.hasOriginRemote, true);
- }).pipe(Effect.provide(layerTest)),
+ assert.equal((yield* driver.statusDetailsLocal(cwd)).hasOriginRemote, true);
+ assert.equal((yield* driver.listRefs({ cwd })).hasPrimaryRemote, true);
+ }).pipe(Effect.provide(layerTest)),
);
it.effect.each([
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index 9c482a8f7f2..c29cb973db9 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -1551,18 +1551,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
}),
},
);
- const originExistsCache = yield* Cache.makeWith(
+ const primaryRemoteExistsCache = yield* Cache.makeWith(
(gitCommonDir: string) =>
Effect.gen(function* () {
const path = yield* Path.Path;
const fetchCwd =
path.basename(gitCommonDir) === ".git" ? path.dirname(gitCommonDir) : gitCommonDir;
return yield* executeGit(
- "GitVcsDriver.statusDetails.originExists",
+ "GitVcsDriver.statusDetails.primaryRemoteExists",
fetchCwd,
- ["--git-dir", gitCommonDir, "remote", "get-url", "origin"],
+ ["--git-dir", gitCommonDir, "remote"],
{ allowNonZeroExit: true },
- ).pipe(Effect.map((result) => result.exitCode === 0));
+ ).pipe(Effect.map((result) => result.exitCode === 0 && result.stdout.trim().length > 0));
}),
{
capacity: 2_048,
@@ -1582,7 +1582,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
: gitCommonDir;
const cacheKey = commonDir ?? normalizeRepositoryPathsCacheKey(cwd);
yield* Cache.invalidate(defaultBranchCache, cacheKey);
- yield* Cache.invalidate(originExistsCache, cacheKey);
+ yield* Cache.invalidate(primaryRemoteExistsCache, cacheKey);
},
);
@@ -2196,8 +2196,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
? Cache.get(defaultBranchCache, statusCacheKey).pipe(Effect.orElseSucceed(() => null))
: resolveDefaultBranchName(cwd, "origin").pipe(Effect.orElseSucceed(() => null)),
statusCacheKey
- ? Cache.get(originExistsCache, statusCacheKey).pipe(Effect.orElseSucceed(() => false))
- : originRemoteExists(cwd).pipe(Effect.orElseSucceed(() => false)),
+ ? Cache.get(primaryRemoteExistsCache, statusCacheKey).pipe(
+ Effect.orElseSucceed(() => false),
+ )
+ : listRemoteNames(cwd).pipe(
+ Effect.map((remoteNames) => remoteNames.length > 0),
+ Effect.orElseSucceed(() => false),
+ ),
],
{ concurrency: "unbounded" },
);
@@ -3939,7 +3944,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
return {
localBranches: localBranches.toSorted(byRecencyThenName).map(({ ref }) => ref),
remoteBranches: remoteBranches.toSorted(byRecencyThenName).map(({ ref }) => ref),
- hasPrimaryRemote: remoteNames.includes("origin"),
+ hasPrimaryRemote: remoteNames.length > 0,
} satisfies GitRefsSnapshot;
});