Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(server): push no longer writes a feature branch's commits to its base branch (#8228)
Theo Browne994372ba4381
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.tsindex cff5d6d47..8a820aa81 100644--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts@@ -1837,6 +1837,111 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {}),);+ it.effect("publishes a branch tracking its base under its own name, not the base", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTmpDir();+ const remote = yield* makeTmpDir("git-remote-");+ yield* initRepoWithCommit(cwd);+ const driver = yield* GitVcsDriver.GitVcsDriver;+ yield* git(cwd, ["branch", "-M", "main"]);+ yield* git(remote, ["init", "--bare"]);+ yield* git(cwd, ["remote", "add", "origin", remote]);+ yield* git(cwd, ["push", "-u", "origin", "main"]);+ yield* git(cwd, ["checkout", "-b", "dev"]);+ yield* git(cwd, ["push", "-u", "origin", "dev"]);+ const devSha = yield* git(cwd, ["rev-parse", "HEAD"]);+ yield* git(cwd, ["checkout", "-b", "feature/x", "origin/dev"]);+ yield* writeTextFile(cwd, "feature.txt", "feature\n");+ yield* driver.prepareCommitContext(cwd);+ yield* driver.commit(cwd, "Add feature", "");++ const pushed = yield* driver.pushCurrentBranch(cwd, null);++ assert.deepInclude(pushed, {+ status: "pushed",+ branch: "feature/x",+ upstreamBranch: "origin/feature/x",+ setUpstream: true,+ });+ assert.equal(yield* git(remote, ["log", "-1", "--pretty=%s", "feature/x"]), "Add feature");+ assert.equal(yield* git(remote, ["rev-parse", "dev"]), devSha);+ assert.equal(+ yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]),+ "origin/feature/x",+ );+ assert.equal(yield* driver.readConfigValue(cwd, "branch.feature/x.gh-merge-base"), "dev");+ }),+ );++ it.effect("keeps a recorded merge base when publishing a tracked branch", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTmpDir();+ const remote = yield* makeTmpDir("git-remote-");+ yield* initRepoWithCommit(cwd);+ const driver = yield* GitVcsDriver.GitVcsDriver;+ yield* git(cwd, ["branch", "-M", "main"]);+ yield* git(remote, ["init", "--bare"]);+ yield* git(cwd, ["remote", "add", "origin", remote]);+ yield* git(cwd, ["push", "-u", "origin", "main"]);+ yield* git(cwd, ["checkout", "-b", "feature/y", "origin/main"]);+ yield* git(cwd, ["config", "branch.feature/y.gh-merge-base", "release/v2"]);+ yield* writeTextFile(cwd, "feature.txt", "feature\n");+ yield* driver.prepareCommitContext(cwd);+ yield* driver.commit(cwd, "Add feature", "");++ const pushed = yield* driver.pushCurrentBranch(cwd, null);++ assert.deepInclude(pushed, {+ status: "pushed",+ branch: "feature/y",+ upstreamBranch: "origin/feature/y",+ setUpstream: true,+ });+ assert.equal(+ yield* driver.readConfigValue(cwd, "branch.feature/y.gh-merge-base"),+ "release/v2",+ );+ }),+ );++ it.effect("still pushes a git-mangled tracking alias to its upstream head", () =>+ Effect.gen(function* () {+ const cwd = yield* makeTmpDir();+ const remote = yield* makeTmpDir("git-remote-");+ yield* initRepoWithCommit(cwd);+ const driver = yield* GitVcsDriver.GitVcsDriver;+ yield* git(cwd, ["branch", "-M", "main"]);+ yield* git(remote, ["init", "--bare"]);+ yield* git(cwd, ["remote", "add", "my-org/upstream", remote]);+ yield* git(cwd, ["push", "my-org/upstream", "main:effect-atom"]);+ yield* git(cwd, ["fetch", "my-org/upstream"]);+ // `checkout --track my-org/upstream/effect-atom` cannot name the local+ // branch `effect-atom`, so git keeps `upstream/effect-atom`. Its+ // upstream is still its published head.+ yield* git(cwd, ["checkout", "--track", "my-org/upstream/effect-atom"]);+ assert.equal(+ yield* git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"]),+ "upstream/effect-atom",+ );+ yield* writeTextFile(cwd, "alias.txt", "alias\n");+ yield* driver.prepareCommitContext(cwd);+ yield* driver.commit(cwd, "Add alias update", "");++ const pushed = yield* driver.pushCurrentBranch(cwd, null);++ assert.deepInclude(pushed, {+ status: "pushed",+ branch: "upstream/effect-atom",+ upstreamBranch: "my-org/upstream/effect-atom",+ setUpstream: false,+ });+ assert.equal(+ yield* git(remote, ["log", "-1", "--pretty=%s", "effect-atom"]),+ "Add alias update",+ );+ }),+ );+it.effect("pushes to the requested remote instead of the primary remote", () =>Effect.gen(function* () {const cwd = yield* makeTmpDir();diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.tsindex 19e58fea6..71e478cba 100644--- a/apps/server/src/vcs/GitVcsDriverCore.ts+++ b/apps/server/src/vcs/GitVcsDriverCore.ts@@ -2007,6 +2007,55 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*Effect.orElseSucceed(() => null),);if (currentUpstream) {+ // A branch tracking a differently named ref was cut from it, the way+ // `git checkout -b feature origin/dev` and our own worktree flow leave+ // it. That upstream is the branch's base, not its publish target, and+ // pushing HEAD onto it would write feature commits to a shared branch+ // (bare `git push` refuses this under push.default=simple). The one+ // same-repo tracking setup that legitimately differs is a git-mangled+ // alias such as local `upstream/effect-atom` for my-org/upstream's+ // `effect-atom`: the branch name ends in the upstream head while the+ // upstream ref ends in the branch name.+ const isAliasOfUpstreamHead =+ branch === currentUpstream.branchName ||+ (branch.endsWith(`/${currentUpstream.branchName}`) &&+ currentUpstream.upstreamRef.endsWith(`/${branch}`));+ if (!isAliasOfUpstreamHead) {+ const publishRemoteName = yield* resolvePushRemoteName(cwd, branch).pipe(+ Effect.orElseSucceed(() => null),+ );+ const remoteName = publishRemoteName ?? currentUpstream.remoteName;+ const publishBranch = yield* resolvePublishBranchName(cwd, branch);+ // `-u` retargets the upstream to the published branch, so keep the+ // base recorded first; base resolution reads gh-merge-base before the+ // upstream ref.+ const configuredMergeBase = yield* runGitStdout(+ "GitVcsDriver.pushCurrentBranch.readMergeBase",+ cwd,+ ["config", "--get", `branch.${branch}.gh-merge-base`],+ true,+ ).pipe(Effect.map((stdout) => stdout.trim()));+ if (configuredMergeBase.length === 0) {+ yield* runGit("GitVcsDriver.pushCurrentBranch.recordMergeBase", cwd, [+ "config",+ `branch.${branch}.gh-merge-base`,+ currentUpstream.branchName,+ ]);+ }+ yield* runGit(+ "GitVcsDriver.pushCurrentBranch.pushOwnBranch",+ cwd,+ ["push", "-u", remoteName, `HEAD:refs/heads/${publishBranch}`],+ { timeoutMs: null },+ );+ return {+ status: "pushed" as const,+ branch,+ upstreamBranch: `${remoteName}/${publishBranch}`,+ setUpstream: true,+ };+ }+yield* runGit("GitVcsDriver.pushCurrentBranch.pushUpstream",cwd,