Skip to content
TypeScript

fix(server): a branch tracking another local branch no longer shows that branch's PR (#30563)

MarcoDotIO9bf7dcd92d93
diff --git a/apps/server/src/git/GitManager.test.ts b/apps/server/src/git/GitManager.test.ts
index f3cc738e419..634898612b0 100644
--- a/apps/server/src/git/GitManager.test.ts
+++ b/apps/server/src/git/GitManager.test.ts
@@ -2574,6 +2574,62 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
}),
);
+ it.effect("branch PR lookup ignores the PR of a local branch the branch tracks", () =>
+ Effect.gen(function* () {
+ const repoDir = yield* makeTempDir("t3code-git-manager-");
+ yield* initRepo(repoDir);
+ const remoteDir = yield* createBareRemote();
+ yield* runGit(repoDir, ["remote", "add", "origin", remoteDir]);
+ yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
+ yield* runGit(repoDir, ["remote", "set-head", "origin", "main"]);
+ yield* runGit(repoDir, ["checkout", "-b", "develop"]);
+ yield* runGit(repoDir, ["push", "-u", "origin", "develop"]);
+ // `--track` from a local branch, or `branch.autoSetupMerge=always`, records remote ".".
+ yield* runGit(repoDir, ["checkout", "-b", "feature/local-base", "--track", "develop"]);
+
+ const { manager, providerCalls } = yield* makeManager({
+ providerScenario: {
+ prListByHeadSelector: {
+ develop: [
+ {
+ number: 61,
+ title: "Release develop",
+ url: "https://github.com/pingdotgg/codething-mvp/pull/61",
+ baseRefName: "main",
+ headRefName: "develop",
+ state: "open",
+ updatedAt: "2026-05-01T10:00:00Z",
+ },
+ ],
+ // Someone else's branch of the same name; this one was never pushed.
+ "feature/local-base": [
+ {
+ number: 62,
+ title: "Another local base",
+ url: "https://github.com/pingdotgg/codething-mvp/pull/62",
+ baseRefName: "main",
+ headRefName: "feature/local-base",
+ state: "open",
+ updatedAt: "2026-05-01T10:00:00Z",
+ },
+ ],
+ },
+ },
+ });
+
+ const status = yield* manager.status({ cwd: repoDir });
+ expect(status.refName).toBe("feature/local-base");
+ expect(status.pr).toBeNull();
+ expect(listedSelectors(providerCalls).includes("develop")).toBe(false);
+
+ const branchPullRequest = yield* manager.branchPullRequest({
+ cwd: repoDir,
+ branch: "feature/local-base",
+ });
+ expect(branchPullRequest).toBeNull();
+ }),
+ );
+
it.effect("status finds a PR pushed under the branch's own name despite a default upstream", () =>
Effect.gen(function* () {
const repoDir = yield* makeTempDir("t3code-git-manager-");
diff --git a/apps/server/src/git/GitManager.ts b/apps/server/src/git/GitManager.ts
index e8c2acbce48..a944922d530 100644
--- a/apps/server/src/git/GitManager.ts
+++ b/apps/server/src/git/GitManager.ts
@@ -558,6 +558,11 @@ function parseCustomCommitMessage(raw: string): { subject: string; body: string
};
}
+// A branch remote of "." tracks another local branch, which no change request can have as its head.
+function publishedRemoteName(branchRemote: string | null): string | null {
+ return branchRemote === "." ? null : branchRemote;
+}
+
function headBranchProbe(
provider: SourceControlProvider.SourceControlProvider["Service"],
headSelectors: ReadonlyArray<string>,
@@ -1238,7 +1243,7 @@ export const make = Effect.gen(function* () {
}
if (
details.localBranchExists &&
- details.upstreamRef === null &&
+ (details.upstreamRef === null || headContext.remoteName === null) &&
(yield* isUnpublishedBranch(cwd, headContext))
) {
return { latest: null, headContext };
@@ -1557,12 +1562,14 @@ export const make = Effect.gen(function* () {
cwd: string,
details: { branch: string; upstreamRef: string | null; remoteName?: string },
) {
- const remoteName =
+ const branchRemote =
details.remoteName ??
(yield* readConfigValueNullable(cwd, `branch.${details.branch}.remote`));
- const headBranchFromUpstream = details.upstreamRef
- ? extractBranchNameFromRemoteRef(details.upstreamRef, { remoteName })
- : "";
+ const remoteName = publishedRemoteName(branchRemote);
+ const headBranchFromUpstream =
+ details.upstreamRef && branchRemote !== "."
+ ? extractBranchNameFromRemoteRef(details.upstreamRef, { remoteName })
+ : "";
const headBranch = headBranchFromUpstream.length > 0 ? headBranchFromUpstream : details.branch;
const shouldProbeLocalBranchSelector =
headBranchFromUpstream.length === 0 || headBranch === details.branch;
@@ -1843,7 +1850,7 @@ export const make = Effect.gen(function* () {
],
{ concurrency: "unbounded" },
);
- if (configuredRemote !== null && configuredMerge !== null) {
+ if (configuredRemote !== null && configuredRemote !== "." && configuredMerge !== null) {
return false;
}
@@ -2494,7 +2501,9 @@ export const make = Effect.gen(function* () {
remoteUrl ? sourceControlDefinitions.repositoryKeyFromRemote(remoteUrl) : null,
),
);
- const remoteName = remoteNameOverride ?? (yield* readConfig(`branch.${branch}.remote`));
+ const remoteName = publishedRemoteName(
+ remoteNameOverride ?? (yield* readConfig(`branch.${branch}.remote`)),
+ );
const [headRemoteUrlKey, targetRemoteUrlKey] =
remoteName === "origin"
? yield* readRemoteUrlKey("origin").pipe(Effect.map((key) => [key, key] as const))