Compare commits

...
Author SHA1 Message Date
Cursor Agent f3d8594d49 fix: use remote tracking ref for PR range context
When generating PR content, resolve the base branch to its remote
tracking ref (e.g. origin/main) instead of using the potentially
stale local ref. This aligns the PR range calculation with the
status/divergence path which already uses resolveBaseBranchForNoUpstream
to prefer the remote tracking ref.

Falls back to the local ref when the remote-qualified ref is
unavailable (e.g. remote branch not yet pushed).
2026-06-20 06:48:15 +00:00
Julius Marminge 1d107bd84a Fix PR base for origin worktrees 2026-06-19 23:25:11 -07:00
7 changed files with 54 additions and 5 deletions

No files matched your search

+13 -1
View File
@@ -1298,7 +1298,19 @@ export const make = Effect.gen(function* () {
phase: "pr",
label: `Generating ${terms.shortLabel} content...`,
});
const rangeContext = yield* gitCore.readRangeContext(cwd, baseBranch);
const rangeBaseRef = yield* gitCore.resolvePrimaryRemoteName(cwd).pipe(
Effect.map((remote) =>
baseBranch.startsWith(`${remote}/`) ? baseBranch : `${remote}/${baseBranch}`,
),
Effect.orElseSucceed(() => baseBranch),
);
const rangeContext = yield* (
rangeBaseRef === baseBranch
? gitCore.readRangeContext(cwd, rangeBaseRef)
: gitCore.readRangeContext(cwd, rangeBaseRef).pipe(
Effect.catch(() => gitCore.readRangeContext(cwd, baseBranch)),
)
);
const generated = yield* textGeneration.generatePrContent({
cwd,
+1
View File
@@ -6041,6 +6041,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
cwd: "/tmp/project",
refName: fetchedOriginCommit,
newRefName: "t3code/bootstrap-refName",
baseRefName: "main",
path: null,
});
assert.deepEqual(fetchRemote.mock.calls[0]?.[0], {
@@ -568,13 +568,21 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
path: worktreePath,
refName: resolvedBase.commitSha,
newRefName: "t3code/fetched-origin",
baseRefName: resolvedBase.remoteRefName,
});
assert.equal(yield* git(worktreePath, ["rev-parse", "HEAD"]), remoteHead);
assert.equal(
yield* driver.readConfigValue(worktreePath, "branch.t3code/fetched-origin.gh-merge-base"),
initialBranch,
);
assert.equal(
yield* driver.readConfigValue(worktreePath, "branch.t3code/fetched-origin.remote"),
null,
);
const status = yield* driver.statusDetails(worktreePath);
assert.equal(status.aheadCount, 0);
assert.equal(status.aheadOfDefaultCount, 0);
}),
);
+18 -4
View File
@@ -1130,16 +1130,16 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
continue;
}
if (yield* branchExists(cwd, normalizedCandidate)) {
return normalizedCandidate;
}
if (
primaryRemoteName &&
(yield* remoteBranchExists(cwd, primaryRemoteName, normalizedCandidate))
) {
return `${primaryRemoteName}/${normalizedCandidate}`;
}
if (yield* branchExists(cwd, normalizedCandidate)) {
return normalizedCandidate;
}
}
return null;
@@ -2178,6 +2178,20 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
fallbackErrorMessage: "git worktree add failed",
});
if (input.newRefName && input.baseRefName) {
const remoteNames = yield* listRemoteNames(input.cwd).pipe(Effect.orElseSucceed(() => []));
const parsedBaseRef = parseRemoteRefWithRemoteNames(
input.baseRefName,
remoteNames.toSorted((left, right) => right.length - left.length),
);
const baseBranch = parsedBaseRef?.branchName ?? input.baseRefName;
yield* runGit("GitVcsDriver.createWorktree.configureBaseRef", input.cwd, [
"config",
`branch.${input.newRefName}.gh-merge-base`,
baseBranch,
]);
}
return {
worktree: {
path: worktreePath,
+1
View File
@@ -712,6 +712,7 @@ const makeWsRpcLayer = (currentSession: EnvironmentAuth.AuthenticatedSession) =>
cwd: bootstrap.prepareWorktree.projectCwd,
refName: worktreeBaseRef,
newRefName: bootstrap.prepareWorktree.branch,
baseRefName: bootstrap.prepareWorktree.baseBranch,
path: null,
});
targetWorktreePath = worktree.worktree.path;
+12
View File
@@ -28,6 +28,18 @@ describe("VcsCreateWorktreeInput", () => {
expect(parsed.newRefName).toBeUndefined();
expect(parsed.refName).toBe("feature/existing");
});
it("accepts baseRefName metadata for a new worktree ref", () => {
const parsed = decodeCreateWorktreeInput({
cwd: "/repo",
refName: "0123456789abcdef",
newRefName: "feature/new",
baseRefName: "origin/main",
path: "/tmp/worktree",
});
expect(parsed.baseRefName).toBe("origin/main");
});
});
describe("GitPreparePullRequestThreadInput", () => {
+1
View File
@@ -137,6 +137,7 @@ export const VcsCreateWorktreeInput = Schema.Struct({
cwd: TrimmedNonEmptyStringSchema,
refName: TrimmedNonEmptyStringSchema,
newRefName: Schema.optional(TrimmedNonEmptyStringSchema),
baseRefName: Schema.optional(TrimmedNonEmptyStringSchema),
path: Schema.NullOr(TrimmedNonEmptyStringSchema),
});
export type VcsCreateWorktreeInput = typeof VcsCreateWorktreeInput.Type;