fix(pull): name the head repository in default compare links (#39075)

The "New Pull Request" buttons and the `/pulls/new/{branch}` redirect
build their compare link as `{owner}:{branch}`. If a fork and its parent
share an owner, through ALLOW_FORK_INTO_SAME_OWNER, or after a transfer,
that head resolves back to the base repo, so the link compares the base
against itself and 404s on a branch that only exists in the fork.

Switching to `{owner}/{repo}:{branch}` names the head repo
unambiguously, and it's what the compare page's own links already use.

Also clears the 404 in #37649; the archived-parent half of that report
is separate.
This commit is contained in:
Artem Lytkin
2026-08-24 21:46:40 +03:00
committed by GitHub
parent 32728fc581
commit 6b929ccb15
3 changed files with 32 additions and 3 deletions
+1 -1
View File
@@ -1308,7 +1308,7 @@ func PullsNewRedirect(ctx *context.Context) {
return
}
redirectRepo = repo.BaseRepo
branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch)
branch = context.CompareHeadRef(repo, branch)
}
ctx.Redirect(fmt.Sprintf("%s/compare/%s...%s?expand=1", redirectRepo.Link(), util.PathEscapeSegments(redirectRepo.DefaultBranch), util.PathEscapeSegments(branch)))
}