@devries-cameron20 / t3code-1 / commits / 92dee2053c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): Changes totals no longer diff against a guessed base after a branch rename (#26125)

Co-authored-by: maria-rcks <maria@kuuro.net>

Tristan Knight committed Nov 3, 2026 at 01:31 UTC 92dee2053c22bc7ef38e793617f359a9f47456ca
2 files changed +70 -1
apps/server/src/vcs/GitVcsDriverCore.test.ts
+64
@@ -2959,6 +2959,70 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
2959 }),
2960 );
2961
2962 + it.effect("does not guess a Changes base for a branch renamed during the status read", () =>
2963 + Effect.gen(function* () {
2964 + const cwd = yield* makeTmpDir();
2965 + const fork = yield* makeTmpDir();
2966 + const upstream = yield* makeTmpDir();
2967 + yield* initRepoWithCommit(cwd);
2968 + yield* git(cwd, ["branch", "-M", "main"]);
2969 + yield* git(fork, ["init", "--bare"]);
2970 + yield* git(upstream, ["init", "--bare"]);
2971 + yield* git(cwd, ["remote", "add", "origin", fork]);
2972 + yield* git(cwd, ["remote", "add", "upstream", upstream]);
2973 + yield* git(cwd, ["push", "origin", "main"]);
2974 + yield* writeTextFile(cwd, "upstream.txt", "work missing from the fork\n");
2975 + yield* git(cwd, ["add", "upstream.txt"]);
2976 + yield* git(cwd, ["commit", "-m", "upstream work"]);
2977 + yield* git(cwd, ["push", "upstream", "main"]);
2978 + yield* git(cwd, ["fetch", "origin"]);
2979 + yield* git(cwd, ["fetch", "upstream"]);
2980 + yield* git(cwd, ["checkout", "-b", "t3/temporary"]);
2981 + yield* git(cwd, ["config", "branch.t3/temporary.t3-merge-base", "main"]);
2982 + yield* git(cwd, [
2983 + "config",
2984 + "branch.t3/temporary.t3-merge-base-ref",
2985 + "refs/remotes/upstream/main",
2986 + ]);
2987 + yield* writeTextFile(cwd, "feature.txt", "thread work\n");
2988 +
2989 + const outer = yield* GitVcsDriver.GitVcsDriver;
2990 + const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
2991 + const renameClaimed = yield* Ref.make(false);
2992 + const renamed = yield* Deferred.make<void>();
2993 + // Rename after `git status` has read HEAD, as the thread launcher does after the first turn.
2994 + // Base config reads start only after status completes; hold every one until the rename lands.
2995 + const spawner = ChildProcessSpawner.make((command) =>
2996 + Effect.gen(function* () {
2997 + if (ChildProcess.isStandardCommand(command) && command.args[0] === "config") {
2998 + if (!(yield* Ref.getAndSet(renameClaimed, true))) {
2999 + yield* git(cwd, ["branch", "-m", "t3/temporary", "feature/named"]).pipe(
3000 + Effect.provideService(GitVcsDriver.GitVcsDriver, outer),
3001 + Effect.orDie,
3002 + );
3003 + yield* Deferred.succeed(renamed, undefined);
3004 + }
3005 + yield* Deferred.await(renamed);
3006 + }
3007 + return yield* delegate.spawn(command);
3008 + }),
3009 + );
3010 + const driver = yield* makeGitVcsDriverCore().pipe(
3011 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
3012 + Effect.provide(layerServerConfig),
3013 + );
3014 +
3015 + const status = yield* driver.statusDetailsLocal(cwd, { includeBranchChanges: true });
3016 +
3017 + assert.strictEqual(status.branch, "t3/temporary");
3018 + assert.deepStrictEqual(status.branchChanges, {
3019 + baseRef: null,
3020 + insertions: 1,
3021 + deletions: 0,
3022 + });
3023 + }),
3024 + );
3025 +
3026 it.effect("keeps local branch bases consistent when tags share their names", () =>
3027 Effect.gen(function* () {
3028 const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+6 -1
@@ -3144,12 +3144,17 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3144 readonly untrackedRoots: ReadonlyArray<string>;
3145 },
3146 ) {
3147 - const { baseRef, mergeBase } = yield* resolveReviewMergeBase(
3147 + const resolved = yield* resolveReviewMergeBase(
3148 cwd,
3149 branch,
3150 undefined,
3151 options?.knownOriginDefaultBranch ?? null,
3152 );
3153 + // A rename after `git status` read HEAD moves the base config away, so the base was guessed.
3154 + const { baseRef, mergeBase } =
3155 + branch === null || (yield* branchExists(cwd, branch))
3156 + ? resolved
3157 + : { baseRef: null, mergeBase: "HEAD" };
3158 const roots = options?.untrackedRoots ?? [];
3159 // Bound pathspec matching work and stay below Windows' command-line limit.
3160 const pathspecs =