@devries-cameron20 / t3code-1 / commits / 414d938513
Fork 0

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

fix(server): publish Create PR branches to split push URLs (#36695)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 13:19 UTC 414d938513250edb2df7178ba737e1e630656ab7
2 files changed +132 -40
apps/server/src/vcs/GitVcsDriverCore.test.ts
+69 -15
@@ -7805,6 +7805,16 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7805 yield* git(originRemote, ["--git-dir=.", "rev-parse", "refs/heads/feature/push"]),
7806 publishedHead,
7807 );
7808 +
7809 + const pushOnlyRemote = yield* makeTmpDir("git-push-only-remote-");
7810 + yield* git(pushOnlyRemote, ["init", "--bare"]);
7811 + yield* git(cwd, ["remote", "set-url", "--push", "origin", pushOnlyRemote]);
7812 + const pushedToPushUrl = yield* driver.pushCurrentBranch(cwd, null);
7813 + assert.deepInclude(pushedToPushUrl, { status: "pushed", branch });
7814 + assert.equal(
7815 + yield* git(pushOnlyRemote, ["--git-dir=.", "rev-parse", "refs/heads/feature/push"]),
7816 + head,
7817 + );
7818 }),
7819 );
7820
@@ -8206,29 +8216,73 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
8216 }),
8217 );
8218
8209 - it.effect("skips an up-to-date tracked branch the push remote already has", () =>
8219 + it.effect.each([
8220 + { pushUrls: [], status: "skipped_up_to_date" },
8221 + { pushUrls: ["mirror"], status: "pushed" },
8222 + { pushUrls: ["fork", "mirror"], status: "pushed" },
8223 + ] as const)(
8224 + "skips an up-to-date tracked branch only when every push URL has it (pushurl $pushUrls)",
8225 + ({ pushUrls, status }) =>
8226 + Effect.gen(function* () {
8227 + const cwd = yield* makeTmpDir();
8228 + const upstreamRemote = yield* makeTmpDir("git-upstream-remote-");
8229 + const remotes = {
8230 + fork: yield* makeTmpDir("git-fork-remote-"),
8231 + mirror: yield* makeTmpDir("git-mirror-remote-"),
8232 + };
8233 + yield* initRepoWithCommit(cwd);
8234 + const driver = yield* GitVcsDriver.GitVcsDriver;
8235 + yield* git(upstreamRemote, ["init", "--bare"]);
8236 + yield* git(remotes.fork, ["init", "--bare"]);
8237 + yield* git(remotes.mirror, ["init", "--bare"]);
8238 + yield* git(cwd, ["remote", "add", "upstream", upstreamRemote]);
8239 + yield* git(cwd, ["remote", "add", "fork", remotes.fork]);
8240 + yield* git(cwd, ["checkout", "-b", "topic"]);
8241 + yield* git(cwd, ["push", "-u", "upstream", "topic"]);
8242 + yield* git(cwd, ["push", "fork", "topic"]);
8243 + yield* git(cwd, ["config", "remote.pushDefault", "fork"]);
8244 + for (const name of pushUrls) {
8245 + yield* git(cwd, ["remote", "set-url", "--add", "--push", "fork", remotes[name]]);
8246 + }
8247 +
8248 + const pushed = yield* driver.pushCurrentBranch(cwd, null);
8249 +
8250 + assert.deepInclude(pushed, { status, upstreamBranch: "fork/topic", pushRemote: "fork" });
8251 + const head = yield* git(cwd, ["rev-parse", "HEAD"]);
8252 + for (const name of pushUrls) {
8253 + assert.equal(
8254 + yield* git(remotes[name], ["--git-dir=.", "rev-parse", "refs/heads/topic"]),
8255 + head,
8256 + );
8257 + }
8258 + assert.equal(
8259 + yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]),
8260 + "upstream/topic",
8261 + );
8262 + }),
8263 + );
8264 +
8265 + it.effect("pushes an up-to-date branch whose tracked remote has a separate push URL", () =>
8266 Effect.gen(function* () {
8267 const cwd = yield* makeTmpDir();
8212 - const upstreamRemote = yield* makeTmpDir("git-upstream-remote-");
8213 - const forkRemote = yield* makeTmpDir("git-fork-remote-");
8268 + const fetchRemote = yield* makeTmpDir("git-fetch-remote-");
8269 + const pushRemote = yield* makeTmpDir("git-push-remote-");
8270 yield* initRepoWithCommit(cwd);
8271 const driver = yield* GitVcsDriver.GitVcsDriver;
8216 - yield* git(upstreamRemote, ["init", "--bare"]);
8217 - yield* git(forkRemote, ["init", "--bare"]);
8218 - yield* git(cwd, ["remote", "add", "upstream", upstreamRemote]);
8219 - yield* git(cwd, ["remote", "add", "fork", forkRemote]);
8272 + yield* git(fetchRemote, ["init", "--bare"]);
8273 + yield* git(pushRemote, ["init", "--bare"]);
8274 + yield* git(cwd, ["remote", "add", "origin", fetchRemote]);
8275 yield* git(cwd, ["checkout", "-b", "topic"]);
8221 - yield* git(cwd, ["push", "-u", "upstream", "topic"]);
8222 - yield* git(cwd, ["push", "fork", "topic"]);
8223 - yield* git(cwd, ["config", "remote.pushDefault", "fork"]);
8276 + yield* git(cwd, ["push", "-u", "origin", "topic"]);
8277 + yield* git(cwd, ["remote", "set-url", "--push", "origin", pushRemote]);
8278
8279 const pushed = yield* driver.pushCurrentBranch(cwd, null);
8280
8227 - assert.deepInclude(pushed, {
8228 - status: "skipped_up_to_date",
8229 - upstreamBranch: "fork/topic",
8230 - pushRemote: "fork",
8231 - });
8281 + assert.deepInclude(pushed, { status: "pushed", upstreamBranch: "origin/topic" });
8282 + assert.equal(
8283 + yield* git(pushRemote, ["--git-dir=.", "rev-parse", "refs/heads/topic"]),
8284 + yield* git(cwd, ["rev-parse", "HEAD"]),
8285 + );
8286 }),
8287 );
8288
apps/server/src/vcs/GitVcsDriverCore.ts
+63 -25
@@ -1866,6 +1866,34 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1866 Effect.orElseSucceed(() => false),
1867 );
1868
1869 + // A fetch reads only the remote's first url, while a push writes every push URL (pushurl, else
1870 + // each url). A fetched ref is evidence of the push destination only when those are the same one.
1871 + const pushesOnlyToFetchUrl = Effect.fn("GitVcsDriver.pushesOnlyToFetchUrl")(
1872 + function* (cwd: string, remoteName: string) {
1873 + const [fetchUrl, pushUrls] = yield* Effect.all([
1874 + runGitStdout("GitVcsDriver.pushesOnlyToFetchUrl.fetchUrl", cwd, [
1875 + "remote",
1876 + "get-url",
1877 + "--",
1878 + remoteName,
1879 + ]),
1880 + runGitStdout("GitVcsDriver.pushesOnlyToFetchUrl.pushUrls", cwd, [
1881 + "remote",
1882 + "get-url",
1883 + "--push",
1884 + "--all",
1885 + "--",
1886 + remoteName,
1887 + ]),
1888 + ]);
1889 + // Preserve whitespace in URLs and reject ambiguous multiline fetch URLs.
1890 + return (
1891 + fetchUrl.endsWith("\n") && !fetchUrl.slice(0, -1).includes("\n") && pushUrls === fetchUrl
1892 + );
1893 + },
1894 + Effect.orElseSucceed(() => false),
1895 + );
1896 +
1897 const ensureRemote: GitVcsDriver.GitVcsDriver["Service"]["ensureRemote"] = Effect.fn(
1898 "ensureRemote",
1899 )(function* (input) {
@@ -2974,30 +3002,36 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3002 const destination = yield* resolvePushDestination(cwd, branch, details.hasUpstream);
3003 if (hasNoLocalDelta && details.hasUpstream) {
3004 if (!destination?.pushRemote) {
2977 - return {
2978 - status: "skipped_up_to_date" as const,
2979 - branch,
2980 - ...(details.upstreamRef ? { upstreamBranch: details.upstreamRef } : {}),
2981 - };
2982 - }
2983 - const { pushRemote, branchName } = destination;
2984 - const pushRemoteRef = `${pushRemote}/${branchName}`;
2985 - // The local ref can be stale when the branch was deleted or rewound elsewhere.
2986 - const pushRemoteHasHead = yield* fetchRemoteTrackingBranch({
2987 - cwd,
2988 - remoteName: pushRemote,
2989 - remoteBranch: branchName,
2990 - }).pipe(
2991 - Effect.andThen(remoteRefContainsHead(cwd, pushRemoteRef)),
2992 - Effect.orElseSucceed(() => false),
2993 - );
2994 - if (pushRemoteHasHead) {
2995 - return {
2996 - status: "skipped_up_to_date" as const,
2997 - branch,
2998 - upstreamBranch: pushRemoteRef,
2999 - pushRemote,
3000 - };
3005 + // The tracking ref reflects the fetch URL, so it says nothing about a separate push URL.
3006 + if (!destination || (yield* pushesOnlyToFetchUrl(cwd, destination.remoteName))) {
3007 + return {
3008 + status: "skipped_up_to_date" as const,
3009 + branch,
3010 + ...(details.upstreamRef ? { upstreamBranch: details.upstreamRef } : {}),
3011 + };
3012 + }
3013 + } else {
3014 + const { pushRemote, branchName } = destination;
3015 + const pushRemoteRef = `${pushRemote}/${branchName}`;
3016 + // The local ref can be stale when the branch was deleted or rewound elsewhere.
3017 + const pushRemoteHasHead =
3018 + (yield* pushesOnlyToFetchUrl(cwd, pushRemote)) &&
3019 + (yield* fetchRemoteTrackingBranch({
3020 + cwd,
3021 + remoteName: pushRemote,
3022 + remoteBranch: branchName,
3023 + }).pipe(
3024 + Effect.andThen(remoteRefContainsHead(cwd, pushRemoteRef)),
3025 + Effect.orElseSucceed(() => false),
3026 + ));
3027 + if (pushRemoteHasHead) {
3028 + return {
3029 + status: "skipped_up_to_date" as const,
3030 + branch,
3031 + upstreamBranch: pushRemoteRef,
3032 + pushRemote,
3033 + };
3034 + }
3035 }
3036 } else if (hasNoLocalDelta) {
3037 const comparableBaseBranch = yield* resolveBaseBranchForNoUpstream(cwd, branch).pipe(
@@ -3013,7 +3047,11 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3047
3048 // The configured diff base can contain HEAD while the publish branch is still behind.
3049 if (
3016 - yield* remoteRefContainsHead(cwd, `${destination.remoteName}/${destination.branchName}`)
3050 + (yield* remoteRefContainsHead(
3051 + cwd,
3052 + `${destination.remoteName}/${destination.branchName}`,
3053 + )) &&
3054 + (yield* pushesOnlyToFetchUrl(cwd, destination.remoteName))
3055 ) {
3056 return {
3057 status: "skipped_up_to_date" as const,