Skip to content
TypeScript

fix(server): status no longer fetches a remote named after a local tracked branch (#29670)

Alex Southwell8ee7cf9a324e
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index 7c9e764f441..80d89ca19d4 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -1516,6 +1516,36 @@ it.effect("retries a fetch that lost a ref update to another Git process", () =>
),
);
+it.effect("does not fetch for status when the branch tracks a local branch", () =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
+ const fetches: Array<ReadonlyArray<string>> = [];
+ const spawner = ChildProcessSpawner.make((command) => {
+ if (ChildProcess.isStandardCommand(command) && command.args.includes("fetch")) {
+ fetches.push(command.args.map(String));
+ }
+ return delegate.spawn(command);
+ });
+ const driver = yield* makeGitVcsDriverCore().pipe(
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
+ );
+ const cwd = yield* makeTmpDir();
+ const remote = yield* makeTmpDir("git-vcs-driver-remote-");
+ yield* initRepoWithCommit(cwd);
+ yield* git(remote, ["init", "--bare"]);
+ yield* git(cwd, ["remote", "add", "feature", remote]);
+ yield* git(cwd, ["branch", "feature/base"]);
+ yield* git(cwd, ["checkout", "-b", "stacked", "--track", "feature/base"]);
+
+ const status = yield* driver.statusDetailsRemote(cwd);
+
+ assert.equal(status.upstreamRef, "feature/base");
+ assert.deepStrictEqual(fetches, []);
+ }),
+ ).pipe(Effect.provide(layerTest)),
+);
+
it.effect("lets a worktree checkout that is still working run past five minutes", () =>
Effect.gen(function* () {
const checkoutStarted = yield* Deferred.make<void>();
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index f8b59f38956..a1fd6e235cc 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -1652,15 +1652,25 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const refreshStatusUpstreamIfStale = Effect.fn("refreshStatusUpstreamIfStale")(function* (
cwd: string,
) {
- const upstream = yield* resolveCurrentUpstream(cwd);
- if (!upstream) return;
+ const headRef = yield* runGitStdout(
+ "GitVcsDriver.refreshStatusUpstreamIfStale.headRef",
+ cwd,
+ ["symbolic-ref", "--quiet", "HEAD"],
+ true,
+ ).pipe(Effect.map((stdout) => stdout.trim()));
+ if (headRef.length === 0) return;
+ const remoteName = yield* runGitStdout(
+ "GitVcsDriver.refreshStatusUpstreamIfStale.upstreamRemote",
+ cwd,
+ ["for-each-ref", "--format=%(upstream:remotename)", headRef],
+ true,
+ ).pipe(Effect.map((stdout) => stdout.trim()));
+ // Empty means no upstream; `.` means the upstream is a local branch.
+ if (remoteName.length === 0 || remoteName === ".") return;
const gitCommonDir = yield* resolveGitCommonDir(cwd);
yield* Cache.get(
statusRemoteRefreshCache,
- new StatusRemoteRefreshCacheKey({
- gitCommonDir,
- remoteName: upstream.remoteName,
- }),
+ new StatusRemoteRefreshCacheKey({ gitCommonDir, remoteName }),
).pipe(Effect.ignore);
});