Skip to content

Commit 32900d3

Browse files
saphidclaude
authored andcommitted
fix(server): an upstream shadowed by a local origin/<branch> branch keeps its real remote
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a852de0 commit 32900d3

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3025,16 +3025,24 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
30253025
});
30263026

30273027
describe("repository status", () => {
3028-
it.effect("reads the current branch by name when a tag shares it", () =>
3028+
it.effect("reads the current branch and upstream by name when other refs share them", () =>
30293029
Effect.gen(function* () {
30303030
const cwd = yield* makeTmpDir();
3031+
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
30313032
yield* initRepoWithCommit(cwd);
3033+
yield* git(remote, ["init", "--bare"]);
3034+
yield* git(cwd, ["remote", "add", "origin", remote]);
30323035
yield* git(cwd, ["checkout", "-b", "release"]);
3036+
yield* git(cwd, ["push", "-u", "origin", "release"]);
3037+
yield* git(cwd, ["commit", "--allow-empty", "-m", "unpushed"]);
3038+
yield* git(cwd, ["branch", "origin/release"]);
30333039
yield* git(cwd, ["tag", "release"]);
30343040
const driver = yield* GitVcsDriver.GitVcsDriver;
30353041

30363042
const remoteStatus = yield* driver.statusDetailsRemote(cwd, { refreshUpstream: false });
30373043
assert.equal(remoteStatus.branch, "release");
3044+
assert.equal(remoteStatus.upstreamRef, "origin/release");
3045+
assert.equal(remoteStatus.aheadCount, 1);
30383046
const preview = yield* driver.getReviewDiffPreview({ cwd });
30393047
const branchRange = preview.sources.find((source) => source.kind === "branch-range");
30403048
assert.equal(branchRange?.headRef, "release");

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,13 +1293,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
12931293
});
12941294
});
12951295

1296+
// `--abbrev-ref` prints `remotes/origin/<name>` when a local `origin/<name>` branch exists.
12961297
const readCurrentUpstreamRef = Effect.fn("readCurrentUpstreamRef")(function* (cwd: string) {
12971298
const upstreamRef = yield* runGitStdout(
12981299
"GitVcsDriver.resolveCurrentUpstream",
12991300
cwd,
1300-
["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"],
1301+
["rev-parse", "--symbolic-full-name", "@{upstream}"],
13011302
true,
1302-
).pipe(Effect.map((stdout) => stdout.trim()));
1303+
).pipe(Effect.map((stdout) => stdout.trim().replace(/^refs\/(?:remotes|heads)\//, "")));
13031304

13041305
if (upstreamRef.length === 0 || upstreamRef === "@{upstream}") {
13051306
return null;
@@ -2032,7 +2033,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
20322033
const divergence = yield* executeGit(
20332034
"GitVcsDriver.statusDetailsRemote.divergence",
20342035
cwd,
2035-
["rev-list", "--left-right", "--count", `HEAD...${upstreamRef}`],
2036+
["rev-list", "--left-right", "--count", "HEAD...@{upstream}"],
20362037
{ allowNonZeroExit: true },
20372038
);
20382039
if (divergence.exitCode === 0) {

0 commit comments

Comments
 (0)