@devries-cameron20 / t3code Mirror · read-only / commits / 3cc98ba567
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 23, 03:00 UTC

fix(server): preserve unrelated branch upstreams when opening fork PRs (#18413)

Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

Alex Southwell committed Oct 19, 2026 at 07:09 UTC 3cc98ba567bd37a45698b8edb1597875d5fb8fa3
2 files changed +46 -3
apps/server/src/git/GitManager.test.ts
+46 -2
@@ -6865,7 +6865,7 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
6865 }),
6866 );
6867
6868 - it.effect("never moves an unrelated local branch that shares the fork head branch name", () =>
6868 + it.effect("preserves an unrelated local branch and upstream that share the fork head name", () =>
6869 Effect.gen(function* () {
6870 const repoDir = yield* makeTempDir("t3code-git-manager-");
6871 yield* initRepo(repoDir);
@@ -6887,6 +6887,13 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
6887 );
6888 yield* runGit(repoDir, ["worktree", "add", mainWorktreePath, "main"]);
6889 const localMainBefore = (yield* runGit(repoDir, ["rev-parse", "main"])).stdout.trim();
6890 + // Leave the fork tracking ref stale so an unnecessary fetch would change it.
6891 + yield* runGit(repoDir, ["update-ref", "refs/remotes/fork-seed/main", localMainBefore]);
6892 + const trackingRefsBefore = (yield* runGit(repoDir, [
6893 + "for-each-ref",
6894 + "--format=%(refname) %(objectname)",
6895 + "refs/remotes",
6896 + ])).stdout;
6897
6898 const setupCalls: ProjectSetupScriptRunner.ProjectSetupScriptRunnerInput[] = [];
6899 const { manager } = yield* makeManager({
@@ -6930,8 +6937,34 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
6937 localMainBefore,
6938 );
6939 expect(NodeFS.existsSync(NodePath.join(mainWorktreePath, "contributor.txt"))).toBe(false);
6940 + expect(
6941 + (yield* runGit(mainWorktreePath, [
6942 + "rev-parse",
6943 + "--abbrev-ref",
6944 + "@{upstream}",
6945 + ])).stdout.trim(),
6946 + ).toBe("origin/main");
6947 + expect(result.branch).toBe("t3code/pr-94/main");
6948 + expect(result.worktreePath && NodeFS.realpathSync.native(result.worktreePath)).toBe(
6949 + NodeFS.realpathSync.native(mainWorktreePath),
6950 + );
6951 + expect(
6952 + (yield* runGit(repoDir, [
6953 + "for-each-ref",
6954 + "--format=%(refname) %(objectname)",
6955 + "refs/remotes",
6956 + ])).stdout,
6957 + ).toBe(trackingRefsBefore);
6958 + expect((yield* runGit(mainWorktreePath, ["branch", "--show-current"])).stdout.trim()).toBe(
6959 + "main",
6960 + );
6961 expect(result.isOnPullRequestHead).toBe(false);
6962 expect(setupCalls).toHaveLength(0);
6963 +
6964 + yield* (yield* GitVcsDriver.GitVcsDriver).pullCurrentBranch(mainWorktreePath);
6965 + expect((yield* runGit(mainWorktreePath, ["rev-parse", "HEAD"])).stdout.trim()).toBe(
6966 + localMainBefore,
6967 + );
6968 }),
6969 );
6970
@@ -7075,7 +7108,14 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
7108 "..",
7109 `pr-reused-fork-${NodePath.basename(repoDir)}`,
7110 );
7078 - yield* runGit(repoDir, ["worktree", "add", worktreePath, "feature/pr-reused-fork"]);
7111 + yield* runGit(repoDir, [
7112 + "worktree",
7113 + "add",
7114 + "-b",
7115 + "t3code/pr-83/feature/pr-reused-fork",
7116 + worktreePath,
7117 + "feature/pr-reused-fork",
7118 + ]);
7119 yield* runGit(worktreePath, ["branch", "--unset-upstream"], true);
7120
7121 const { manager } = yield* makeManager({
@@ -7109,6 +7149,10 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
7149 expect(result.worktreePath && NodeFS.realpathSync.native(result.worktreePath)).toBe(
7150 NodeFS.realpathSync.native(worktreePath),
7151 );
7152 + expect(result.branch).toBe("t3code/pr-83/feature/pr-reused-fork");
7153 + expect((yield* runGit(worktreePath, ["branch", "--show-current"])).stdout.trim()).toBe(
7154 + result.branch,
7155 + );
7156 expect(
7157 (yield* runGit(worktreePath, ["rev-parse", "--abbrev-ref", "@{upstream}"])).stdout.trim(),
7158 ).toBe("fork-seed/feature/pr-reused-fork");
apps/server/src/git/GitManager.ts
-1
@@ -2729,7 +2729,6 @@ export const make = Effect.gen(function* () {
2729 // findLocalHeadBranch also accepts a branch that merely shares the head's bare name —
2730 // a fork PR opened from "main" matches the user's own local main. That checkout is
2731 // somebody else's work, so it keeps its tracking config and nothing else.
2732 - yield* ensureExistingWorktreeUpstream(worktreePath);
2732 return {
2733 pullRequest,
2734 branch: localPullRequestBranch,