fix(repo): surface unrelated histories on Sync Fork (#39258)

Sync Fork already maps merge conflicts to a JSON error. Unrelated
histories still went through `ServerError`, so the UI showed a 500 HTML
snippet instead of the same user-facing message PR merge already uses
(`repo.pulls.unrelated_histories`).

The API path returned 500 for the same git error; PR merge returns 409.
Match that.

Fixes #36772

AI assistance was used to locate the handler gap and draft the mapping.
I reviewed and take responsibility for the change.

Signed-off-by: Zhaoqi Xu <lzy00419@outlook.com>
This commit is contained in:
Zhaoqi Xu
2026-09-17 12:25:43 +00:00
committed by GitHub
parent afb7edef07
commit be7cde7539
4 changed files with 14 additions and 0 deletions
+5
View File
@@ -1331,6 +1331,8 @@ func MergeUpstream(ctx *context.APIContext) {
// "$ref": "#/responses/error"
// "404":
// "$ref": "#/responses/notFound"
// "409":
// "$ref": "#/responses/error"
form := web.GetForm[*api.MergeUpstreamRequest](ctx)
mergeStyle, err := repo_service.MergeUpstream(ctx, ctx.Doer, ctx.Repo.Repository, form.Branch, form.FfOnly)
if err != nil {
@@ -1343,6 +1345,9 @@ func MergeUpstream(ctx *context.APIContext) {
} else if errors.Is(err, util.ErrPermissionDenied) {
ctx.APIError(http.StatusForbidden, err.Error())
return
} else if pull_service.IsErrMergeConflicts(err) || pull_service.IsErrMergeUnrelatedHistories(err) {
ctx.APIError(http.StatusConflict, err.Error())
return
}
ctx.APIErrorInternal(err)
return