@devries-cameron20 / t3code-1 / commits / 517c9fcd09
Fork 0

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

fix(git): push publishes a branch that tracks a local branch (#33581)

Co-authored-by: maria-rcks <maria@kuuro.net>

Ibrahim Elkamali committed Nov 12, 2026 at 02:12 UTC 517c9fcd096d1f0fdb4e2480b73dd592253d381e
2 files changed +251 -94
apps/server/src/vcs/GitVcsDriverCore.test.ts
+225 -92
@@ -6654,42 +6654,67 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6654 }),
6655 );
6656
6657 - it.effect("pushes with upstream setup and skips when already up to date", () =>
6658 - Effect.gen(function* () {
6659 - const cwd = yield* makeTmpDir();
6660 - const remote = yield* makeTmpDir("git-remote-");
6661 - yield* initRepoWithCommit(cwd);
6662 - yield* git(remote, ["init", "--bare"]);
6663 - yield* git(cwd, ["remote", "add", "origin", remote]);
6664 - yield* (yield* GitVcsDriver.GitVcsDriver).createRef({
6665 - cwd,
6666 - refName: "feature/push",
6667 - });
6668 - yield* (yield* GitVcsDriver.GitVcsDriver).switchRef({
6669 - cwd,
6670 - refName: "feature/push",
6671 - });
6672 - yield* writeTextFile(cwd, "feature.txt", "feature\n");
6673 - yield* git(cwd, ["add", "-A"]);
6674 - yield* (yield* GitVcsDriver.GitVcsDriver).commit(cwd, "Add feature", "");
6657 + it.effect.each([false, true])(
6658 + "pushes with upstream setup and skips when already up to date (autoSetupMerge=%s)",
6659 + (autoSetupMerge) =>
6660 + Effect.gen(function* () {
6661 + const cwd = yield* makeTmpDir();
6662 + const remote = yield* makeTmpDir("git-remote-");
6663 + const { initialBranch } = yield* initRepoWithCommit(cwd);
6664 + if (autoSetupMerge) {
6665 + yield* git(cwd, ["config", "branch.autoSetupMerge", "always"]);
6666 + }
6667 + yield* git(remote, ["init", "--bare"]);
6668 + yield* git(cwd, ["remote", "add", "origin", remote]);
6669 + yield* (yield* GitVcsDriver.GitVcsDriver).createRef({
6670 + cwd,
6671 + refName: "feature/push",
6672 + });
6673 + yield* (yield* GitVcsDriver.GitVcsDriver).switchRef({
6674 + cwd,
6675 + refName: "feature/push",
6676 + });
6677 + yield* writeTextFile(cwd, "feature.txt", "feature\n");
6678 + yield* git(cwd, ["add", "-A"]);
6679 + yield* (yield* GitVcsDriver.GitVcsDriver).commit(cwd, "Add feature", "");
6680
6676 - const pushed = yield* (yield* GitVcsDriver.GitVcsDriver).pushCurrentBranch(cwd, null);
6677 - assert.deepInclude(pushed, {
6678 - status: "pushed",
6679 - branch: "feature/push",
6680 - setUpstream: true,
6681 - });
6682 - assert.equal(
6683 - yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]),
6684 - "origin/feature/push",
6685 - );
6681 + const driver = yield* GitVcsDriver.GitVcsDriver;
6682 + if (autoSetupMerge) {
6683 + assert.equal(yield* driver.readConfigValue(cwd, "branch.feature/push.remote"), ".");
6684 + assert.equal(
6685 + yield* driver.readConfigValue(cwd, "branch.feature/push.merge"),
6686 + `refs/heads/${initialBranch}`,
6687 + );
6688 + }
6689
6687 - const skipped = yield* (yield* GitVcsDriver.GitVcsDriver).pushCurrentBranch(cwd, null);
6688 - assert.deepInclude(skipped, {
6689 - status: "skipped_up_to_date",
6690 - branch: "feature/push",
6691 - });
6692 - }),
6690 + const pushed = yield* (yield* GitVcsDriver.GitVcsDriver).pushCurrentBranch(cwd, null);
6691 + assert.deepInclude(pushed, {
6692 + status: "pushed",
6693 + branch: "feature/push",
6694 + setUpstream: true,
6695 + });
6696 + assert.equal(
6697 + yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]),
6698 + "origin/feature/push",
6699 + );
6700 +
6701 + if (autoSetupMerge) {
6702 + assert.equal(
6703 + yield* driver.readConfigValue(cwd, "branch.feature/push.t3-merge-base"),
6704 + initialBranch,
6705 + );
6706 + assert.equal(
6707 + yield* driver.readConfigValue(cwd, "branch.feature/push.t3-merge-base-ref"),
6708 + `refs/heads/${initialBranch}`,
6709 + );
6710 + }
6711 +
6712 + const skipped = yield* (yield* GitVcsDriver.GitVcsDriver).pushCurrentBranch(cwd, null);
6713 + assert.deepInclude(skipped, {
6714 + status: "skipped_up_to_date",
6715 + branch: "feature/push",
6716 + });
6717 + }),
6718 );
6719
6720 it.effect("rebases a pushed branch's pulls when branch.autoSetupRebase asks for it", () =>
@@ -6837,62 +6862,170 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6862 }),
6863 );
6864
6840 - it.effect("publishes a branch tracking its base under its own name, not the base", () =>
6841 - Effect.gen(function* () {
6842 - const cwd = yield* makeTmpDir();
6843 - const remote = yield* makeTmpDir("git-remote-");
6844 - const upstream = yield* makeTmpDir("git-upstream-");
6845 - yield* initRepoWithCommit(cwd);
6846 - const driver = yield* GitVcsDriver.GitVcsDriver;
6847 - yield* git(cwd, ["branch", "-M", "main"]);
6848 - yield* git(remote, ["init", "--bare"]);
6849 - yield* git(cwd, ["remote", "add", "origin", remote]);
6850 - yield* git(cwd, ["push", "-u", "origin", "main"]);
6851 - yield* git(cwd, ["checkout", "-b", "dev"]);
6852 - yield* git(cwd, ["push", "-u", "origin", "dev"]);
6853 - const devSha = yield* git(cwd, ["rev-parse", "HEAD"]);
6854 - yield* git(upstream, ["init", "--bare"]);
6855 - yield* git(cwd, ["remote", "add", "upstream", upstream]);
6856 - yield* writeTextFile(cwd, "upstream.txt", "upstream work\n");
6857 - yield* git(cwd, ["add", "-A"]);
6858 - yield* driver.commit(cwd, "Add upstream update", "");
6859 - yield* git(cwd, ["push", "upstream", "dev"]);
6860 - const upstreamDevSha = yield* git(cwd, ["rev-parse", "HEAD"]);
6861 - yield* git(cwd, ["checkout", "-b", "feature/x", "upstream/dev"]);
6862 - yield* writeTextFile(cwd, "feature.txt", "feature\n");
6863 - yield* git(cwd, ["add", "-A"]);
6864 - yield* driver.commit(cwd, "Add feature", "");
6865 + it.effect.each([
6866 + { baseBranch: "dev", local: false },
6867 + { baseBranch: "dev", local: true },
6868 + { baseBranch: "feature/base", local: true },
6869 + { baseBranch: "upstream", local: true },
6870 + { baseBranch: "upstream/feature/x", local: true },
6871 + ])(
6872 + "publishes a branch tracking $baseBranch (local=$local) under its own name, not the base",
6873 + ({ baseBranch, local }) =>
6874 + Effect.gen(function* () {
6875 + const cwd = yield* makeTmpDir();
6876 + const remote = yield* makeTmpDir("git-remote-");
6877 + const upstream = yield* makeTmpDir("git-upstream-");
6878 + yield* initRepoWithCommit(cwd);
6879 + const driver = yield* GitVcsDriver.GitVcsDriver;
6880 + yield* git(cwd, ["branch", "-M", "main"]);
6881 + yield* git(remote, ["init", "--bare"]);
6882 + yield* git(cwd, ["remote", "add", "origin", remote]);
6883 + yield* git(cwd, ["push", "-u", "origin", "main"]);
6884 + yield* git(cwd, ["checkout", "--no-track", "-b", baseBranch]);
6885 + yield* git(cwd, ["push", "-u", "origin", baseBranch]);
6886 + const devSha = yield* git(cwd, ["rev-parse", "HEAD"]);
6887 + yield* git(upstream, ["init", "--bare"]);
6888 + yield* git(cwd, ["remote", "add", "upstream", upstream]);
6889 + yield* writeTextFile(cwd, "upstream.txt", "upstream work\n");
6890 + yield* git(cwd, ["add", "-A"]);
6891 + yield* driver.commit(cwd, "Add upstream update", "");
6892 + yield* git(cwd, ["push", "upstream", baseBranch]);
6893 + const upstreamDevSha = yield* git(cwd, ["rev-parse", "HEAD"]);
6894 + yield* git(cwd, [
6895 + "checkout",
6896 + "--track",
6897 + "-b",
6898 + "feature/x",
6899 + local ? `refs/heads/${baseBranch}` : `refs/remotes/upstream/${baseBranch}`,
6900 + ]);
6901 + assert.equal(
6902 + yield* driver.readConfigValue(cwd, "branch.feature/x.remote"),
6903 + local ? "." : "upstream",
6904 + );
6905 + yield* writeTextFile(cwd, "feature.txt", "feature\n");
6906 + yield* git(cwd, ["add", "-A"]);
6907 + yield* driver.commit(cwd, "Add feature", "");
6908
6866 - const pushed = yield* driver.pushCurrentBranch(cwd, null);
6909 + const pushed = yield* driver.pushCurrentBranch(cwd, null);
6910
6868 - assert.deepInclude(pushed, {
6869 - status: "pushed",
6870 - branch: "feature/x",
6871 - upstreamBranch: "origin/feature/x",
6872 - setUpstream: true,
6873 - });
6874 - assert.equal(
6875 - yield* git(remote, ["--git-dir=.", "log", "-1", "--pretty=%s", "feature/x"]),
6876 - "Add feature",
6877 - );
6878 - assert.equal(yield* git(remote, ["--git-dir=.", "rev-parse", "dev"]), devSha);
6879 - assert.equal(yield* git(upstream, ["--git-dir=.", "rev-parse", "dev"]), upstreamDevSha);
6880 - assert.equal(
6881 - yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]),
6882 - "origin/feature/x",
6883 - );
6884 - assert.equal(yield* driver.readConfigValue(cwd, "branch.feature/x.t3-merge-base"), "dev");
6911 + assert.deepInclude(pushed, {
6912 + status: "pushed",
6913 + branch: "feature/x",
6914 + upstreamBranch: "origin/feature/x",
6915 + setUpstream: true,
6916 + });
6917 + assert.equal(
6918 + yield* git(remote, ["--git-dir=.", "log", "-1", "--pretty=%s", "feature/x"]),
6919 + "Add feature",
6920 + );
6921 + assert.equal(
6922 + yield* git(remote, ["--git-dir=.", "rev-parse", `refs/heads/${baseBranch}`]),
6923 + devSha,
6924 + );
6925 + assert.equal(
6926 + yield* git(upstream, ["--git-dir=.", "rev-parse", `refs/heads/${baseBranch}`]),
6927 + upstreamDevSha,
6928 + );
6929 + assert.equal(
6930 + yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]),
6931 + "origin/feature/x",
6932 + );
6933 + assert.equal(
6934 + yield* driver.readConfigValue(cwd, "branch.feature/x.t3-merge-base"),
6935 + baseBranch,
6936 + );
6937 + assert.equal(
6938 + yield* driver.readConfigValue(cwd, "branch.feature/x.t3-merge-base-ref"),
6939 + local ? `refs/heads/${baseBranch}` : `refs/remotes/upstream/${baseBranch}`,
6940 + );
6941 + assert.equal(yield* git(cwd, ["rev-parse", `refs/heads/${baseBranch}`]), upstreamDevSha);
6942
6886 - const preview = yield* driver.getReviewDiffPreview({ cwd });
6887 - const changes = preview.sources.find((source) => source.kind === "branch-range")!;
6888 - assert.deepStrictEqual(changes.files, [
6889 - { path: "feature.txt", previousPath: null, additions: 1, deletions: 0 },
6890 - ]);
6891 - assert.equal(changes.baseRef, "upstream/dev");
6892 - }),
6943 + const preview = yield* driver.getReviewDiffPreview({ cwd });
6944 + const changes = preview.sources.find((source) => source.kind === "branch-range")!;
6945 + assert.deepStrictEqual(changes.files, [
6946 + { path: "feature.txt", previousPath: null, additions: 1, deletions: 0 },
6947 + ]);
6948 + assert.equal(
6949 + changes.baseRef,
6950 + local ? `refs/heads/${baseBranch}` : `upstream/${baseBranch}`,
6951 + );
6952 + }),
6953 + );
6954 +
6955 + it.effect.each([
6956 + { upstreamRef: "refs/remotes/origin/main", baseKey: "gh-merge-base" },
6957 + { upstreamRef: "refs/heads/main", baseKey: "gh-merge-base" },
6958 + { upstreamRef: "refs/heads/main", baseKey: "t3-merge-base" },
6959 + ])(
6960 + "keeps a recorded $baseKey when publishing a branch tracking $upstreamRef",
6961 + ({ upstreamRef, baseKey }) =>
6962 + Effect.gen(function* () {
6963 + const cwd = yield* makeTmpDir();
6964 + const remote = yield* makeTmpDir("git-remote-");
6965 + yield* initRepoWithCommit(cwd);
6966 + const driver = yield* GitVcsDriver.GitVcsDriver;
6967 + yield* git(cwd, ["branch", "-M", "main"]);
6968 + yield* git(remote, ["init", "--bare"]);
6969 + yield* git(cwd, ["remote", "add", "origin", remote]);
6970 + yield* git(cwd, ["push", "-u", "origin", "main"]);
6971 + yield* git(cwd, ["checkout", "--track", "-b", "feature/y", upstreamRef]);
6972 + yield* git(cwd, ["config", `branch.feature/y.${baseKey}`, "release/v2"]);
6973 + yield* git(cwd, [
6974 + "config",
6975 + "branch.feature/y.t3-merge-base-ref",
6976 + "refs/heads/release/v2",
6977 + ]);
6978 + yield* writeTextFile(cwd, "feature.txt", "feature\n");
6979 + yield* git(cwd, ["add", "-A"]);
6980 + yield* driver.commit(cwd, "Add feature", "");
6981 +
6982 + const pushed = yield* driver.pushCurrentBranch(cwd, null);
6983 +
6984 + assert.deepInclude(pushed, {
6985 + status: "pushed",
6986 + branch: "feature/y",
6987 + upstreamBranch: "origin/feature/y",
6988 + setUpstream: true,
6989 + });
6990 + assert.equal(
6991 + yield* driver.readConfigValue(cwd, `branch.feature/y.${baseKey}`),
6992 + "release/v2",
6993 + );
6994 + assert.equal(yield* driver.readBranchBase(cwd, "feature/y"), "release/v2");
6995 + assert.equal(
6996 + yield* driver.readConfigValue(cwd, "branch.feature/y.t3-merge-base-ref"),
6997 + "refs/heads/release/v2",
6998 + );
6999 + }),
7000 + );
7001 +
7002 + it.effect.each(["main", "feature/base"])(
7003 + "rejects publishing a branch tracking local %s without a git remote",
7004 + (parent) =>
7005 + Effect.gen(function* () {
7006 + const cwd = yield* makeTmpDir();
7007 + yield* initRepoWithCommit(cwd);
7008 + const driver = yield* GitVcsDriver.GitVcsDriver;
7009 + yield* git(cwd, ["branch", "-M", parent]);
7010 + yield* git(cwd, ["checkout", "--track", "-b", "child", `refs/heads/${parent}`]);
7011 + yield* writeTextFile(cwd, "feature.txt", "feature\n");
7012 + yield* git(cwd, ["add", "-A"]);
7013 + yield* driver.commit(cwd, "Add feature", "");
7014 + const parentSha = yield* git(cwd, ["rev-parse", `refs/heads/${parent}`]);
7015 +
7016 + const error = yield* driver.pushCurrentBranch(cwd, null).pipe(Effect.flip);
7017 +
7018 + assert.equal(error._tag, "GitCommandError");
7019 + assert.equal(error.operation, "GitVcsDriver.pushCurrentBranch");
7020 + assert.equal(
7021 + error.detail,
7022 + "Cannot push because no git remote is configured for this repository.",
7023 + );
7024 + assert.equal(yield* git(cwd, ["rev-parse", `refs/heads/${parent}`]), parentSha);
7025 + }),
7026 );
7027
6895 - it.effect("keeps a recorded merge base when publishing a tracked branch", () =>
7028 + it.effect("publishes a local-tracking branch named like a remote ref under its full name", () =>
7029 Effect.gen(function* () {
7030 const cwd = yield* makeTmpDir();
7031 const remote = yield* makeTmpDir("git-remote-");
@@ -6902,8 +7035,8 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7035 yield* git(remote, ["init", "--bare"]);
7036 yield* git(cwd, ["remote", "add", "origin", remote]);
7037 yield* git(cwd, ["push", "-u", "origin", "main"]);
6905 - yield* git(cwd, ["checkout", "-b", "feature/y", "origin/main"]);
6906 - yield* git(cwd, ["config", "branch.feature/y.gh-merge-base", "release/v2"]);
7038 + const mainSha = yield* git(cwd, ["rev-parse", "refs/heads/main"]);
7039 + yield* git(cwd, ["checkout", "--track", "-b", "origin/main", "refs/heads/main"]);
7040 yield* writeTextFile(cwd, "feature.txt", "feature\n");
7041 yield* git(cwd, ["add", "-A"]);
7042 yield* driver.commit(cwd, "Add feature", "");
@@ -6912,13 +7045,13 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7045
7046 assert.deepInclude(pushed, {
7047 status: "pushed",
6915 - branch: "feature/y",
6916 - upstreamBranch: "origin/feature/y",
6917 - setUpstream: true,
7048 + branch: "origin/main",
7049 + upstreamBranch: "origin/origin/main",
7050 });
7051 + assert.equal(yield* git(remote, ["--git-dir=.", "rev-parse", "refs/heads/main"]), mainSha);
7052 assert.equal(
6920 - yield* driver.readConfigValue(cwd, "branch.feature/y.gh-merge-base"),
6921 - "release/v2",
7053 + yield* git(remote, ["--git-dir=.", "log", "-1", "--pretty=%s", "refs/heads/origin/main"]),
7054 + "Add feature",
7055 );
7056 }),
7057 );
apps/server/src/vcs/GitVcsDriverCore.ts
+26 -2
@@ -2731,6 +2731,24 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2731 return { remoteName, branchName, publishes: true, upstream: null };
2732 }
2733
2734 + if ((yield* readConfigValue(cwd, `branch.${branch}.remote`)) === ".") {
2735 + const localUpstream = yield* readCurrentUpstreamRef(cwd).pipe(
2736 + Effect.orElseSucceed(() => null),
2737 + );
2738 + if (localUpstream === null) return null;
2739 + // A local upstream is a base; publish under the full local name so `origin/main` never lands on remote `main`.
2740 + const remoteName = yield* resolvePushRemoteName(cwd, branch).pipe(
2741 + Effect.orElseSucceed(() => null),
2742 + );
2743 + if (!remoteName) return null;
2744 + return {
2745 + remoteName,
2746 + branchName: branch,
2747 + publishes: true,
2748 + upstream: { remoteName: ".", branchName: localUpstream, upstreamRef: localUpstream },
2749 + };
2750 + }
2751 +
2752 const upstream = yield* resolveCurrentUpstream(cwd).pipe(Effect.orElseSucceed(() => null));
2753 if (!upstream) return null;
2754 // Differently named upstreams are bases, not publish targets; pushing HEAD there would write features to shared branches.
@@ -2845,7 +2863,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2863 }
2864 }
2865
2848 - if (!details.hasUpstream && !destination) {
2866 + if (
2867 + !destination &&
2868 + (!details.hasUpstream || (yield* readConfigValue(cwd, `branch.${branch}.remote`)) === ".")
2869 + ) {
2870 return yield* new GitCommandError({
2871 ...gitCommandContext({
2872 operation: "GitVcsDriver.pushCurrentBranch",
@@ -2869,7 +2890,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2890 yield* writeConfigValue({
2891 cwd,
2892 key: `branch.${branch}.t3-merge-base-ref`,
2872 - value: `refs/remotes/${upstream.upstreamRef}`,
2893 + value:
2894 + upstream.remoteName === "."
2895 + ? `refs/heads/${upstream.branchName}`
2896 + : `refs/remotes/${upstream.upstreamRef}`,
2897 });
2898 }
2899 }