fix(git): a long-lived branch stops showing an old merged PR once it moves on #16006
main fromfix/drop-terminal-pr-moved-branchopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/git/GitManager.ts lines 1192 to 1202OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1095,0 +1182,21 @@1182+ ],1183+ timeoutMs: 5_000,1184+ });1185+ const oidByRefName = new Map<string, string>();1186+ for (const line of result.stdout.split("\n")) {1187+ const [refName = "", objectName = ""] = line.trim().split("\u0000");1188+ if (refName.length > 0 && objectName.length > 0) {1189+ oidByRefName.set(refName, objectName);1190+ }1191+ }1192+ for (const localRef of localRefs) {1193+ const oid = oidByRefName.get(localRef);1194+ if (oid !== undefined) {1195+ return oid;1196+ }1197+ }1198+ for (const [refName, oid] of oidByRefName) {1199+ if (isRemoteTrackingRefFor(refName, headContext.headBranch, headContext.remoteName)) {1200+ return oid;1201+ }1202+ }
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/git/GitManager.ts line 2674OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2621,3 +2669,6 @@26212669 // The returned PR URL names the repository that actually owns it.26222670 repositoryKey: pullRequestRepositoryKey(latest.url),26232671 };2672+ // branchPullRequest confirms a terminal answer with fresh git state, so2673+ // this tip is never older than the branch's last move.2674+ if (branchMovedPastPullRequest(tipOid, latest)) {
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/git/GitManager.ts lines 1280 to 1284OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1261,3 +1271,14 @@12611271 }12621272 return lastKnown.pr;12631273 };1274+ /**1275+ * A reused branch (like `develop` after a release) has moved past a merged or1276+ * closed PR once its tip is no longer that PR's head commit. Comparing commits1277+ * rather than dates keeps squash and rebase merges working. Unknown when the1278+ * host reports no head commit or the branch has no local tip, so the PR stays.1279+ */1280+ const branchMovedPastPullRequest = (tipOid: string | null, pr: PullRequestInfo) => {1281+ const headSha = pr.headSha?.trim().toLowerCase() ?? "";1282+ const tip = tipOid?.trim().toLowerCase() ?? "";1283+ return pr.state !== "open" && headSha.length > 0 && tip.length > 0 && tip !== headSha;1284+ };
juliusmarminge assignedjuliusmarminge
- apps/server/src/git/GitManager.ts line 2705OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2614,0 +2685,21 @@2685+ saved.number !== pullRequest.number ||2686+ pullRequestRepositoryKey(saved.url) !== pullRequestRepositoryKey(pullRequest.url)2687+ ) {2688+ return false;2689+ }2690+ const remoteName = yield* gitCore.readConfigValue(cwd, `branch.${branch}.remote`);2691+ const mergeRef = yield* gitCore.readConfigValue(cwd, `branch.${branch}.merge`);2692+ const defaultBranch = yield* gitCore.resolveDefaultBranchName(cwd, remoteName ?? "origin");2693+ const { headContext, lookup } = yield* resolveLookupHeadContext(cwd, {2694+ branch,2695+ upstreamRef:2696+ remoteName !== null && mergeRef !== null2697+ ? `${remoteName}/${mergeRef.replace(/^refs\/heads\//, "")}`2698+ : null,2699+ defaultBranch,2700+ });2701+ const repositoryKey = headContext.targetRemoteUrlKey ?? headContext.headRemoteUrlKey;2702+ if (2703+ !lookup ||2704+ repositoryKey === null ||2705+ repositoryKey !== pullRequestRepositoryKey(saved.url) ||
- @@ -2614,0 +2672,21 @@2672+ : exit.value.state === "open"2673+ ? PR_LOOKUP_CACHE_TTL2674+ : PR_LOOKUP_NO_OPEN_PR_CACHE_TTL,2675+ },2676+ );2677+ const branchSupersededPullRequest: GitManager["Service"]["branchSupersededPullRequest"] =2678+ Effect.fn("branchSupersededPullRequest")(function* ({ cwd, branch, pullRequest }) {2679+ const cacheCwd = yield* normalizeStatusCacheKey(cwd);2680+ const saved = yield* detachStackFrame(2681+ Cache.get(savedPullRequestCache, `${cacheCwd}\u0000${pullRequest.url}`),2682+ );2683+ if (2684+ saved.state === "open" ||2685+ saved.number !== pullRequest.number ||2686+ pullRequestRepositoryKey(saved.url) !== pullRequestRepositoryKey(pullRequest.url)2687+ ) {2688+ return false;2689+ }2690+ const remoteName = yield* gitCore.readConfigValue(cwd, `branch.${branch}.remote`);2691+ const mergeRef = yield* gitCore.readConfigValue(cwd, `branch.${branch}.merge`);2692+ const defaultBranch = yield* gitCore.resolveDefaultBranchName(cwd, remoteName ?? "origin");
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:gate-failed
juliusmarminge closed this
juliusmarminge removed labelspr:gate-failed
Sign in to join this conversation.



Approvability#
Verdict: Approved at
a61d7dfMacroscope's review found this PR approvable — This is a localized, well-tested fix that hides an old merged or closed PR only after its exact head becomes an ancestor of later branch work. Existing open PRs, explicit links, and ambiguous or unverifiable Git states retain their prior behavior.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).6cc0f3e. Prior analysis still applies.