Skip to content

Commit 4d4d598

Browse files
committed
fix(repo): surface unrelated histories on Sync Fork
Sync Fork mapped merge conflicts to a JSON error but left unrelated-histories as ServerError, so the UI showed a 500 HTML snippet. PR merge already maps this. Do the same on the web handler and return 409 from the API. Fixes #36772 Assisted-by: Grok:grok-4 Signed-off-by: Zhaoqi Xu <lzy00419@outlook.com>
1 parent 1770470 commit 4d4d598

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

routers/api/v1/repo/branch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,8 @@ func MergeUpstream(ctx *context.APIContext) {
13311331
// "$ref": "#/responses/error"
13321332
// "404":
13331333
// "$ref": "#/responses/notFound"
1334+
// "409":
1335+
// "$ref": "#/responses/error"
13341336
form := web.GetForm[*api.MergeUpstreamRequest](ctx)
13351337
mergeStyle, err := repo_service.MergeUpstream(ctx, ctx.Doer, ctx.Repo.Repository, form.Branch, form.FfOnly)
13361338
if err != nil {
@@ -1343,6 +1345,9 @@ func MergeUpstream(ctx *context.APIContext) {
13431345
} else if errors.Is(err, util.ErrPermissionDenied) {
13441346
ctx.APIError(http.StatusForbidden, err.Error())
13451347
return
1348+
} else if pull_service.IsErrMergeConflicts(err) || pull_service.IsErrMergeUnrelatedHistories(err) {
1349+
ctx.APIError(http.StatusConflict, err.Error())
1350+
return
13461351
}
13471352
ctx.APIErrorInternal(err)
13481353
return

routers/web/repo/branch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ func MergeUpstream(ctx *context.Context) {
240240
} else if pull_service.IsErrMergeConflicts(err) {
241241
ctx.JSONError(ctx.Tr("repo.pulls.merge_conflict"))
242242
return
243+
} else if pull_service.IsErrMergeUnrelatedHistories(err) {
244+
ctx.JSONError(ctx.Tr("repo.pulls.unrelated_histories"))
245+
return
243246
}
244247
ctx.ServerError("MergeUpstream", err)
245248
return

0 commit comments

Comments
 (0)