Skip to content

Commit 92dee20

Browse files
tris203maria-rcks
andauthored
fix(server): Changes totals no longer diff against a guessed base after a branch rename (#26125)
Co-authored-by: maria-rcks <[email protected]>
1 parent 2d2299a commit 92dee20

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,70 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
29592959
}),
29602960
);
29612961

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+
29623026
it.effect("keeps local branch bases consistent when tags share their names", () =>
29633027
Effect.gen(function* () {
29643028
const cwd = yield* makeTmpDir();

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3144,12 +3144,17 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
31443144
readonly untrackedRoots: ReadonlyArray<string>;
31453145
},
31463146
) {
3147-
const { baseRef, mergeBase } = yield* resolveReviewMergeBase(
3147+
const resolved = yield* resolveReviewMergeBase(
31483148
cwd,
31493149
branch,
31503150
undefined,
31513151
options?.knownOriginDefaultBranch ?? null,
31523152
);
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" };
31533158
const roots = options?.untrackedRoots ?? [];
31543159
// Bound pathspec matching work and stay below Windows' command-line limit.
31553160
const pathspecs =

0 commit comments

Comments
 (0)