From a617294b5a554b24e6af08408ff7df0e780b26ce Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Fri, 3 Sep 2021 20:48:11 +0100 Subject: [PATCH 1/2] Ensure that rebase conflicts are handled in updates PR #16125 did not update the error handlers to handle conflict errors relating to rebases. This PR adds them. Fix #16922 Signed-off-by: Andrew Thornton --- routers/api/v1/repo/pull.go | 2 ++ routers/web/repo/pull.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index e493e720fb2e5..0083e5e45d0e8 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1136,6 +1136,8 @@ func UpdatePullRequest(ctx *context.APIContext) { if models.IsErrMergeConflicts(err) { ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict") return + } else if models.IsErrRebaseConflicts(err) { + ctx.Error(http.StatusConflict, "Update", "rebase failed because of conflict") } ctx.Error(http.StatusInternalServerError, "pull_service.Update", err) return diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 885ac3391a7e3..6b369195de356 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -766,6 +766,21 @@ func UpdatePullRequest(ctx *context.Context) { ctx.Flash.Error(flashError) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index)) return + } else if models.IsErrRebaseConflicts(err) { + conflictError := err.(models.ErrRebaseConflicts) + flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{ + "Message": ctx.Tr("repo.pulls.rebase_conflict", utils.SanitizeFlashErrorString(conflictError.CommitSHA)), + "Summary": ctx.Tr("repo.pulls.rebase_conflict_summary"), + "Details": utils.SanitizeFlashErrorString(conflictError.StdErr) + "
" + utils.SanitizeFlashErrorString(conflictError.StdOut), + }) + if err != nil { + ctx.ServerError("UpdatePullRequest.HTMLString", err) + return + } + ctx.Flash.Error(flashError) + ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index)) + return + } ctx.Flash.Error(err.Error()) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + fmt.Sprint(issue.Index)) From 1e72706e989509541fb86f310de6478af8e8dd6d Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 4 Sep 2021 08:33:08 +0100 Subject: [PATCH 2/2] Update routers/api/v1/repo/pull.go --- routers/api/v1/repo/pull.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 0083e5e45d0e8..dee9a94bca6bd 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1138,6 +1138,7 @@ func UpdatePullRequest(ctx *context.APIContext) { return } else if models.IsErrRebaseConflicts(err) { ctx.Error(http.StatusConflict, "Update", "rebase failed because of conflict") + return } ctx.Error(http.StatusInternalServerError, "pull_service.Update", err) return