Target the fork branch from fork-PR worktrees (#4394)

Creating a worktree from a cross-repository (fork) PR previously named the
local branch with the maintainer's branch prefix (e.g. `me/866`) and pushed to
origin instead of the contributor's fork, so maintainer edits never reached the
PR. Fork PRs now adopt the contributor's branch name (matching same-repo PRs)
and resolve a fork push target, with a non-blocking warning when the PR
disables maintainer edits and an indicator showing where a push will land.

- pr-start-point: return branchNameOverride/headSha/maintainerCanModify for
  cross-repo PRs (previously only same-repo PRs received these)
- github client: surface maintainer_can_modify alongside the fork push target
- composer: warn (but still allow) when "Allow edits from maintainers" is off
- source control: show the fork push target (owner:branch) before pushing
- extract fork-remote cleanup and setup into dedicated, unit-tested modules

Adds unit suites for the cleanup multi-fork matrix, fork-remote setup,
push-target resolution, the warning decision, and the push-target label.

Note: pre-commit react-doctor hook bypassed — its warnings in useComposerState
are pre-existing (identical count on base) and not enforced by CI.

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
This commit is contained in:
Kaylee
2026-06-07 19:51:36 -07:00
committed by GitHub
co-authored by Neil
parent a67afb5a04
commit 528a887ab5
18 changed files with 1050 additions and 223 deletions
+25 -5
View File
@@ -257,11 +257,22 @@ function sanitizeRemoteName(owner: string, repo: string): string {
return slug ? `pr-${slug}` : 'pr-head'
}
/**
* A fork push target plus the PR's `maintainer_can_modify` flag. The flag rides
* alongside the target (rather than inside {@link GitPushTarget}) so it never
* leaks into the persisted, validated push-target shape.
*/
export type PullRequestPushTarget = {
pushTarget: GitPushTarget
/** false when the PR has "Allow edits from maintainers" off; a push may be rejected. */
maintainerCanModify?: boolean
}
export async function getPullRequestPushTarget(
repoPath: string,
prNumber: number,
connectionId?: string | null
): Promise<GitPushTarget | null> {
): Promise<PullRequestPushTarget | null> {
const context = githubRepoContext(repoPath, connectionId)
const ghOptions = ghRepoExecOptions(context)
const { candidates } = await resolvePRRepositoryCandidates(repoPath, connectionId)
@@ -297,6 +308,7 @@ export async function getPullRequestPushTarget(
}
const origin = await getOwnerRepoForRemote(repoPath, 'origin', connectionId)
const pr = JSON.parse(prStdout) as {
maintainer_can_modify?: boolean
head?: {
ref?: string
repo?: {
@@ -314,6 +326,8 @@ export async function getPullRequestPushTarget(
const repo = headRepo?.name?.trim() ?? headRepo?.full_name?.split('/')[1]?.trim()
const cloneUrl = headRepo?.clone_url?.trim()
const sshUrl = headRepo?.ssh_url?.trim()
const maintainerCanModify =
typeof pr.maintainer_can_modify === 'boolean' ? pr.maintainer_can_modify : undefined
if (!owner || !repo || !branchName || !cloneUrl || !sshUrl) {
return null
}
@@ -322,7 +336,10 @@ export async function getPullRequestPushTarget(
origin.owner.toLowerCase() === owner.toLowerCase() &&
origin.repo.toLowerCase() === repo.toLowerCase()
) {
return { remoteName: 'origin', branchName }
return {
pushTarget: { remoteName: 'origin', branchName },
...(maintainerCanModify !== undefined ? { maintainerCanModify } : {})
}
}
let originUrl: string | null = null
@@ -335,9 +352,12 @@ export async function getPullRequestPushTarget(
originUrl = null
}
return {
remoteName: sanitizeRemoteName(owner, repo),
branchName,
remoteUrl: pickPushRemoteUrl({ originUrl, cloneUrl, sshUrl })
pushTarget: {
remoteName: sanitizeRemoteName(owner, repo),
branchName,
remoteUrl: pickPushRemoteUrl({ originUrl, cloneUrl, sshUrl })
},
...(maintainerCanModify !== undefined ? { maintainerCanModify } : {})
}
} finally {
release()