@devries-cameron20 / t3code Mirror · read-only / commits / eb8185560f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 17:15 UTC

fix(server): branches in a fork checkout no longer show the fork main's PR (#36309)

Julius Marminge committed Nov 13, 2026 at 12:25 UTC eb8185560f389243fc42f80d87fcbabb84f67888
2 files changed +96 -1
apps/server/src/git/GitManager.test.ts
+85
@@ -2606,6 +2606,91 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
2606 }),
2607 );
2608
2609 + it.effect("branch PR lookup in a fork checkout follows the branch's own published ref", () =>
2610 + Effect.gen(function* () {
2611 + const repoDir = yield* makeTempDir("t3code-git-manager-");
2612 + yield* initRepo(repoDir);
2613 + const forkDir = yield* createBareRemote();
2614 + yield* runGit(repoDir, ["remote", "add", "origin", forkDir]);
2615 + yield* runGit(repoDir, [
2616 + "remote",
2617 + "add",
2618 + "upstream",
2619 + "git@github.com:pingdotgg/codething-mvp.git",
2620 + ]);
2621 + yield* runGit(repoDir, ["push", "-u", "origin", "main"]);
2622 + yield* runGit(repoDir, ["remote", "set-head", "origin", "main"]);
2623 + // What a new worktree thread gets: its start point as upstream, nothing published.
2624 + yield* runGit(repoDir, ["branch", "--track", "t3code/new-thread", "origin/main"]);
2625 + yield* runGit(repoDir, ["branch", "--track", "feature/published", "origin/main"]);
2626 + yield* runGit(repoDir, ["branch", "--track", "t3code/pr-300/main", "origin/main"]);
2627 + yield* runGit(repoDir, ["push", "origin", "feature/published"]);
2628 + yield* configureVisibleRemoteUrlWithLocalRewrite(
2629 + repoDir,
2630 + "origin",
2631 + "git@github.com:contributor/codething-mvp.git",
2632 + forkDir,
2633 + );
2634 +
2635 + const forkPullRequest = {
2636 + baseRefName: "main",
2637 + isCrossRepository: true,
2638 + headRepositoryNameWithOwner: "contributor/codething-mvp",
2639 + headRepositoryOwnerLogin: "contributor",
2640 + } as const;
2641 + const { service, calls } = createFakeSourceControlProvider({
2642 + prListByHeadSelector: {
2643 + "contributor:main": [
2644 + {
2645 + ...forkPullRequest,
2646 + number: 300,
2647 + title: "Fork main",
2648 + url: "https://github.com/pingdotgg/codething-mvp/pull/300",
2649 + headRefName: "main",
2650 + state: "merged",
2651 + },
2652 + ],
2653 + "feature/published": [
2654 + {
2655 + ...forkPullRequest,
2656 + number: 224,
2657 + title: "Fork feature",
2658 + url: "https://github.com/pingdotgg/codething-mvp/pull/224",
2659 + headRefName: "feature/published",
2660 + state: "open",
2661 + },
2662 + ],
2663 + },
2664 + });
2665 + const { manager } = yield* makeManager({
2666 + sourceControlProvider: {
2667 + ...service,
2668 + createsChangeRequestsIn: ({ repository }) =>
2669 + Effect.succeed(repository === "pingdotgg/codething-mvp"),
2670 + },
2671 + });
2672 +
2673 + const unpublished = yield* manager.branchPullRequest({
2674 + cwd: repoDir,
2675 + branch: "t3code/new-thread",
2676 + });
2677 + expect(unpublished).toBeNull();
2678 + expect(listedSelectors(calls)).toEqual([]);
2679 +
2680 + const published = yield* manager.branchPullRequest({
2681 + cwd: repoDir,
2682 + branch: "feature/published",
2683 + });
2684 + expect(published?.number).toBe(224);
2685 +
2686 + const pullRequestWorktree = yield* manager.branchPullRequest({
2687 + cwd: repoDir,
2688 + branch: "t3code/pr-300/main",
2689 + });
2690 + expect(pullRequestWorktree?.number).toBe(300);
2691 + }),
2692 + );
2693 +
2694 it.effect("branch PR lookup ignores the PR of a local branch the branch tracks", () =>
2695 Effect.gen(function* () {
2696 const repoDir = yield* makeTempDir("t3code-git-manager-");
apps/server/src/git/GitManager.ts
+11 -1
@@ -272,6 +272,11 @@ function resolveHeadRepositoryNameWithOwner(pullRequest: PullRequestHeadRemoteIn
272 return normalizeOptionalString(pullRequest.headRepositoryNameWithOwner);
273 }
274
275 +// Both names `resolvePullRequestWorktreeLocalBranchName` gives a fork pull request's branch.
276 +function isPullRequestWorktreeLocalBranchName(branch: string): boolean {
277 + return /^t3code[/-]pr-\d+[/-]/u.test(branch);
278 +}
279 +
280 function resolvePullRequestWorktreeLocalBranchName(
281 pullRequest: ResolvedPullRequest & PullRequestHeadRemoteInfo,
282 localBranches: ReadonlySet<string>,
@@ -1848,7 +1853,12 @@ export const make = Effect.gen(function* () {
1853 };
1854 }
1855 }
1851 - if (headContext.headBranch === details.branch || headContext.isCrossRepository) {
1856 + // A fork's default branch can be a PR head. When that fork is origin it is also where new
1857 + // branches start, so only a branch made for a pull request takes it as its head.
1858 + const tracksForkHead =
1859 + headContext.isCrossRepository &&
1860 + (headContext.remoteName !== "origin" || isPullRequestWorktreeLocalBranchName(details.branch));
1861 + if (headContext.headBranch === details.branch || tracksForkHead) {
1862 return { headContext, lookup: true };
1863 }
1864 const upstreamHeadIsBase =