Skip to content

Commit 9bf7dcd

Browse files
MarcoDotIOclaude
andauthored
fix(server): a branch tracking another local branch no longer shows that branch's PR (pingdotgg#30563)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 40d7d48 commit 9bf7dcd

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,6 +2574,62 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
25742574
}),
25752575
);
25762576

2577+
it.effect("branch PR lookup ignores the PR of a local branch the branch tracks", () =>
2578+
Effect.gen(function* () {
2579+
const repoDir = yield* makeTempDir("t3code-git-manager-");
2580+
yield* initRepo(repoDir);
2581+
const remoteDir = yield* createBareRemote();
2582+
yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
2583+
yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
2584+
yield* runGit(repoDir, ["remote", "set-head", "origin", "main"]);
2585+
yield* runGit(repoDir, ["checkout", "-b", "develop"]);
2586+
yield* runGit(repoDir, ["push", "-u", "origin", "develop"]);
2587+
// `--track` from a local branch, or `branch.autoSetupMerge=always`, records remote ".".
2588+
yield* runGit(repoDir, ["checkout", "-b", "feature/local-base", "--track", "develop"]);
2589+
2590+
const { manager, providerCalls } = yield* makeManager({
2591+
providerScenario: {
2592+
prListByHeadSelector: {
2593+
develop: [
2594+
{
2595+
number: 61,
2596+
title: "Release develop",
2597+
url: "https://github.com/pingdotgg/codething-mvp/pull/61",
2598+
baseRefName: "main",
2599+
headRefName: "develop",
2600+
state: "open",
2601+
updatedAt: "2026-05-01T10:00:00Z",
2602+
},
2603+
],
2604+
// Someone else's branch of the same name; this one was never pushed.
2605+
"feature/local-base": [
2606+
{
2607+
number: 62,
2608+
title: "Another local base",
2609+
url: "https://github.com/pingdotgg/codething-mvp/pull/62",
2610+
baseRefName: "main",
2611+
headRefName: "feature/local-base",
2612+
state: "open",
2613+
updatedAt: "2026-05-01T10:00:00Z",
2614+
},
2615+
],
2616+
},
2617+
},
2618+
});
2619+
2620+
const status = yield* manager.status({ cwd: repoDir });
2621+
expect(status.refName).toBe("feature/local-base");
2622+
expect(status.pr).toBeNull();
2623+
expect(listedSelectors(providerCalls).includes("develop")).toBe(false);
2624+
2625+
const branchPullRequest = yield* manager.branchPullRequest({
2626+
cwd: repoDir,
2627+
branch: "feature/local-base",
2628+
});
2629+
expect(branchPullRequest).toBeNull();
2630+
}),
2631+
);
2632+
25772633
it.effect("status finds a PR pushed under the branch's own name despite a default upstream", () =>
25782634
Effect.gen(function* () {
25792635
const repoDir = yield* makeTempDir("t3code-git-manager-");

‎apps/server/src/git/GitManager.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ function parseCustomCommitMessage(raw: string): { subject: string; body: string
558558
};
559559
}
560560

561+
// A branch remote of "." tracks another local branch, which no change request can have as its head.
562+
function publishedRemoteName(branchRemote: string | null): string | null {
563+
return branchRemote === "." ? null : branchRemote;
564+
}
565+
561566
function headBranchProbe(
562567
provider: SourceControlProvider.SourceControlProvider["Service"],
563568
headSelectors: ReadonlyArray<string>,
@@ -1238,7 +1243,7 @@ export const make = Effect.gen(function* () {
12381243
}
12391244
if (
12401245
details.localBranchExists &&
1241-
details.upstreamRef === null &&
1246+
(details.upstreamRef === null || headContext.remoteName === null) &&
12421247
(yield* isUnpublishedBranch(cwd, headContext))
12431248
) {
12441249
return { latest: null, headContext };
@@ -1557,12 +1562,14 @@ export const make = Effect.gen(function* () {
15571562
cwd: string,
15581563
details: { branch: string; upstreamRef: string | null; remoteName?: string },
15591564
) {
1560-
const remoteName =
1565+
const branchRemote =
15611566
details.remoteName ??
15621567
(yield* readConfigValueNullable(cwd, `branch.${details.branch}.remote`));
1563-
const headBranchFromUpstream = details.upstreamRef
1564-
? extractBranchNameFromRemoteRef(details.upstreamRef, { remoteName })
1565-
: "";
1568+
const remoteName = publishedRemoteName(branchRemote);
1569+
const headBranchFromUpstream =
1570+
details.upstreamRef && branchRemote !== "."
1571+
? extractBranchNameFromRemoteRef(details.upstreamRef, { remoteName })
1572+
: "";
15661573
const headBranch = headBranchFromUpstream.length > 0 ? headBranchFromUpstream : details.branch;
15671574
const shouldProbeLocalBranchSelector =
15681575
headBranchFromUpstream.length === 0 || headBranch === details.branch;
@@ -1843,7 +1850,7 @@ export const make = Effect.gen(function* () {
18431850
],
18441851
{ concurrency: "unbounded" },
18451852
);
1846-
if (configuredRemote !== null && configuredMerge !== null) {
1853+
if (configuredRemote !== null && configuredRemote !== "." && configuredMerge !== null) {
18471854
return false;
18481855
}
18491856

@@ -2494,7 +2501,9 @@ export const make = Effect.gen(function* () {
24942501
remoteUrl ? sourceControlDefinitions.repositoryKeyFromRemote(remoteUrl) : null,
24952502
),
24962503
);
2497-
const remoteName = remoteNameOverride ?? (yield* readConfig(`branch.${branch}.remote`));
2504+
const remoteName = publishedRemoteName(
2505+
remoteNameOverride ?? (yield* readConfig(`branch.${branch}.remote`)),
2506+
);
24982507
const [headRemoteUrlKey, targetRemoteUrlKey] =
24992508
remoteName === "origin"
25002509
? yield* readRemoteUrlKey("origin").pipe(Effect.map((key) => [key, key] as const))

0 commit comments

Comments
 (0)