Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10325,6 +10325,35 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);

it.effect(
"publishes a new branch prefixed with another remote's name under its full name",
() =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const origin = yield* makeTmpDir("git-remote-");
const fork = yield* makeTmpDir("git-fork-");
yield* initRepoWithCommit(cwd);
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* git(origin, ["init", "--bare"]);
yield* git(fork, ["init", "--bare"]);
yield* git(cwd, ["remote", "add", "origin", origin]);
// e.g. the remote T3 adds when checking out a pull request from alice's fork.
yield* git(cwd, ["remote", "add", "alice", fork]);
yield* git(cwd, ["checkout", "-b", "alice/fix"]);
yield* writeTextFile(cwd, "fix.txt", "fix\n");
yield* git(cwd, ["add", "-A"]);
yield* driver.commit(cwd, "Add fix", "");

const pushed = yield* driver.pushCurrentBranch(cwd, null);

assert.deepInclude(pushed, { status: "pushed", upstreamBranch: "origin/alice/fix" });
assert.equal(
yield* git(origin, ["--git-dir=.", "rev-parse", "refs/heads/alice/fix"]),
yield* git(cwd, ["rev-parse", "HEAD"]),
);
}),
);

it.effect("still pushes a git-mangled tracking alias to its upstream head", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
Expand Down
21 changes: 8 additions & 13 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2147,14 +2147,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
Effect.map(parseRemoteNamesInGitOrder),
);

const resolvePublishBranchName = Effect.fn("resolvePublishBranchName")(function* (
cwd: string,
branchName: string,
) {
const remoteNames = yield* listRemoteNames(cwd).pipe(Effect.orElseSucceed(() => []));
const parsedRemoteRef = parseRemoteRefWithRemoteNames(branchName, remoteNames);
return parsedRemoteRef?.branchName ?? branchName;
});
// Only the destination remote's prefix is dropped; `alice/fix` pushed to origin keeps its full name.
const resolvePublishBranchName = (branchName: string, remoteName: string) =>
parseRemoteRefWithRemoteNames(branchName, [remoteName])?.branchName ?? branchName;

const hasAnyRemote = (cwd: string) =>
resolveRepositoryPaths(cwd).pipe(
Expand Down Expand Up @@ -3680,7 +3675,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
// A gone local upstream still gets the full local name, as below.
const branchName =
goneUpstream?.branchName ??
(configuredRemoteName === "." ? branch : yield* resolvePublishBranchName(cwd, branch));
(configuredRemoteName === "." ? branch : resolvePublishBranchName(branch, remoteName));
return {
remoteName,
branchName,
Expand Down Expand Up @@ -3731,10 +3726,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const publishRemoteName = yield* resolvePushRemoteName(cwd, branch).pipe(
Effect.orElseSucceed(() => null),
);
const branchName = yield* resolvePublishBranchName(cwd, branch);
const remoteName = publishRemoteName ?? upstream.remoteName;
return {
remoteName: publishRemoteName ?? upstream.remoteName,
branchName,
remoteName,
branchName: resolvePublishBranchName(branch, remoteName),
publishes: true,
upstream,
pushRemote: null,
Expand Down Expand Up @@ -3774,7 +3769,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*

const requestedRemoteName = options?.remoteName?.trim() || null;
if (requestedRemoteName) {
const publishBranch = yield* resolvePublishBranchName(cwd, branch);
const publishBranch = resolvePublishBranchName(branch, requestedRemoteName);
yield* executeGitWithStableDiagnostics(
"GitVcsDriver.pushCurrentBranch.pushWithRequestedRemote",
cwd,
Expand Down
Loading