Skip to content

Commit 35a947d

Browse files
saphidclaude
andcommitted
fix(server): a republished branch keeps its literal name and skips local upstreams
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 744e092 commit 35a947d

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5729,6 +5729,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
57295729
const fork = yield* makeTmpDir("git-fork-");
57305730
yield* git(fork, ["init", "--bare"]);
57315731
yield* git(cwd, ["remote", "add", "fork", fork]);
5732+
yield* git(cwd, ["remote", "add", "feature", fork]);
57325733
yield* git(cwd, ["push", "-u", "fork", "feature/push"]);
57335734
yield* git(cwd, ["push", "fork", "--delete", "feature/push"]);
57345735
yield* writeTextFile(cwd, "fork.txt", "fork\n");
@@ -5743,6 +5744,17 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
57435744
yield* git(fork, ["--git-dir=.", "rev-parse", "refs/heads/feature/push"]),
57445745
yield* git(cwd, ["rev-parse", "HEAD"]),
57455746
);
5747+
5748+
yield* git(cwd, ["config", "branch.feature/push.remote", "."]);
5749+
yield* git(cwd, ["config", "branch.feature/push.merge", "refs/heads/push"]);
5750+
yield* writeTextFile(cwd, "local.txt", "local\n");
5751+
yield* git(cwd, ["add", "-A"]);
5752+
yield* (yield* GitVcsDriver.GitVcsDriver).commit(cwd, "Add local change", "");
5753+
const localUpstreamGone = yield* (yield* GitVcsDriver.GitVcsDriver).pushCurrentBranch(
5754+
cwd,
5755+
null,
5756+
);
5757+
assert.deepInclude(localUpstreamGone, { upstreamBranch: "origin/push" });
57465758
}),
57475759
);
57485760

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,12 +2669,20 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26692669
}
26702670

26712671
// A deleted upstream keeps its config; republish to its remote when it was this branch's own.
2672-
let goneUpstreamRemoteName: string | null = null;
2672+
let goneUpstream: { remoteName: string; branchName: string } | null = null;
26732673
if (!details.hasUpstream) {
2674-
const publishBranch = yield* resolvePublishBranchName(cwd, branch);
26752674
const mergeRef = yield* readConfigValue(cwd, `branch.${branch}.merge`);
2676-
if (mergeRef === `refs/heads/${publishBranch}`) {
2677-
goneUpstreamRemoteName = yield* readConfigValue(cwd, `branch.${branch}.remote`);
2675+
const mergeBranch = mergeRef?.startsWith("refs/heads/")
2676+
? mergeRef.slice("refs/heads/".length)
2677+
: null;
2678+
const remoteName = yield* readConfigValue(cwd, `branch.${branch}.remote`);
2679+
if (
2680+
mergeBranch &&
2681+
remoteName &&
2682+
remoteName !== "." &&
2683+
(mergeBranch === branch || mergeBranch === (yield* resolvePublishBranchName(cwd, branch)))
2684+
) {
2685+
goneUpstream = { remoteName, branchName: mergeBranch };
26782686
}
26792687
}
26802688

@@ -2695,7 +2703,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
26952703
const publishRemoteName = yield* resolvePushRemoteName(
26962704
cwd,
26972705
branch,
2698-
goneUpstreamRemoteName,
2706+
goneUpstream?.remoteName,
26992707
).pipe(Effect.orElseSucceed(() => null));
27002708
if (!publishRemoteName) {
27012709
return {
@@ -2704,7 +2712,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27042712
};
27052713
}
27062714

2707-
const publishBranch = yield* resolvePublishBranchName(cwd, branch);
2715+
const publishBranch =
2716+
goneUpstream?.branchName ?? (yield* resolvePublishBranchName(cwd, branch));
27082717
// The configured diff base can contain HEAD while the publish branch is still behind.
27092718
const publishContainsHead = yield* executeGit(
27102719
"GitVcsDriver.pushCurrentBranch.publishContainsHead",
@@ -2730,7 +2739,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27302739
}
27312740

27322741
if (!details.hasUpstream) {
2733-
const publishRemoteName = yield* resolvePushRemoteName(cwd, branch, goneUpstreamRemoteName);
2742+
const publishRemoteName = yield* resolvePushRemoteName(cwd, branch, goneUpstream?.remoteName);
27342743
if (!publishRemoteName) {
27352744
return yield* new GitCommandError({
27362745
...gitCommandContext({
@@ -2741,7 +2750,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
27412750
detail: "Cannot push because no git remote is configured for this repository.",
27422751
});
27432752
}
2744-
const publishBranch = yield* resolvePublishBranchName(cwd, branch);
2753+
const publishBranch =
2754+
goneUpstream?.branchName ?? (yield* resolvePublishBranchName(cwd, branch));
27452755
yield* runGit(
27462756
"GitVcsDriver.pushCurrentBranch.pushWithUpstream",
27472757
cwd,

0 commit comments

Comments
 (0)